Skip to content

Commit

Permalink
Support for appliedTeamIds in Orders (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
dshore committed Sep 26, 2021
1 parent 4a1f18a commit fc20555
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion line_item_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
__version__ = '0.2.3'

# For an official release, use dev_version = ''
dev_version = ''
dev_version = '1'

version = __version__
if dev_version:
Expand Down
3 changes: 3 additions & 0 deletions line_item_manager/conf.d/line_item_manager.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ creative: # at least one of the following types is required {video, banner}
###############################################################################
order:
name: "Prebid-{{ bidder_name }}-{{ media_type }}-{{ time }} {{ cpm_min }}-{{ cpm_max }}"
# appliedTeamIds: # list (optional)
# - 12345678
# - 23456789
###############################################################################
# Line Items (required)
# Allowed Templating Key Words: Bidder, Media, CPM, Misc
Expand Down
5 changes: 5 additions & 0 deletions line_item_manager/conf.d/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ properties:
properties:
name:
type: "string"
appliedTeamIds:
type: "array"
minItems: 1
items:
type: "number"
required:
- "name"
line_item:
Expand Down
8 changes: 6 additions & 2 deletions line_item_manager/gam_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,12 @@ def order(self) -> dict:
cfg = render_cfg('order', self.bidder, media_type=self.media_type,
cpm_min=self.cpms[0], cpm_max=self.cpms[-1])
log('order', obj=cfg)
self._order = Order(name=cfg['name'], advertiserId=self.advertiser['id'],
traffickerId=self.gam.user['id']).fetchone(create=True)
self._order = Order(
name=cfg['name'],
advertiserId=self.advertiser['id'],
traffickerId=self.gam.user['id'],
appliedTeamIds=config.user['order'].get('appliedTeamIds'),
).fetchone(create=True)
return self._order

@property
Expand Down
6 changes: 6 additions & 0 deletions line_item_manager/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ class Order(AppOperations):
service = "OrderService"
method = 'getOrdersByStatement'
create_method = 'createOrders'
query_fields = ('id', 'name', 'advertiserId', 'traffickerId')

def __init__(self, *args, **kwargs):
if 'appliedTeamIds' in kwargs and kwargs['appliedTeamIds'] is None:
del kwargs['appliedTeamIds']
super().__init__(*args, **kwargs)

def archive(self) -> dict:
if self.dry_run:
Expand Down
3 changes: 3 additions & 0 deletions tests/resources/cfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ creative: # at least one of the following types is required {video, banner}
###############################################################################
order:
name: "Prebid-{{ bidder_name }}-{{ media_type }}-{{ time }} {{ cpm_min }}-{{ cpm_max }}"
appliedTeamIds: # list (optional)
- 12345678
- 23456789
###############################################################################
# Line Items (required)
# Allowed Templating Key Words: Bidder, Media, CPM, Misc
Expand Down
3 changes: 3 additions & 0 deletions tests/resources/cfg_video.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ creative: # at least one of the following types is required {video, banner}
###############################################################################
order:
name: "Prebid-{{ bidder_name }}-{{ media_type }}-{{ time }} {{ cpm_min }}-{{ cpm_max }}"
appliedTeamIds: # list (optional)
- 12345678
- 23456789
###############################################################################
# Line Items (required)
# Allowed Templating Key Words: Bidder, Media, CPM, Misc
Expand Down
1 change: 1 addition & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def test_bidders(cli_config):
def test_single_order(cli_config):
assert [PrebidBidder(c_, single_order=config.cli['single_order']).targeting_key \
for c_ in config.bidder_codes()] == ['hb_pb']
assert config.user['order']['appliedTeamIds'] == [12345678, 23456789]

def test_fmt_bidder_key():
assert PrebidBidder('oneVideo').fmt_bidder_key('prefix') == "prefix_oneVideo"
Expand Down

0 comments on commit fc20555

Please sign in to comment.