Skip to content

Commit

Permalink
Validate bucket schema without using json multipleOf (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
dshore committed Jan 26, 2022
1 parent 5d63622 commit 54fb029
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 2 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.4'

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

version = __version__
if dev_version:
Expand Down
1 change: 0 additions & 1 deletion line_item_manager/conf.d/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ definitions:
cpmType:
type: "number"
minimum: 0.01
multipleOf: 0.01
granularityType:
type: "object"
additionalProperties: False
Expand Down
7 changes: 7 additions & 0 deletions line_item_manager/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ def template_src(self) -> str:
return fp.read()
return read_package_file('line_item_template.yml')

def validate_bucket(self, bucket: Dict[str, float]) -> None:
for _k in ('min', 'max', 'interval'):
if not (100 * bucket[_k]) % 1 == 0:
raise ValueError(f"Bucket {_k}, {bucket[_k]}, is not a multiple of 0.01")

def pre_create(self) -> None:
li_ = self.user['line_item']
is_standard = li_['item_type'].upper() == "STANDARD"
Expand All @@ -156,6 +161,8 @@ def pre_create(self) -> None:
self.app['prebid']['creative']['video']['max_duration']
)

_ = [self.validate_bucket(bucket) for bucket in self.cpm_buckets()]

if vcpm and not is_standard:
raise ValueError("Specifying 'vcpm' requires using line item type 'standard'")

Expand Down
134 changes: 134 additions & 0 deletions tests/resources/cfg_bad_custom_bucket.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# line_item_manager configuration
###############################################################################
# Templating uses jinja2 rendering (see https://palletsprojects.com/p/jinja/)
# The following key word types are supported:
# Bidder:
# bidder_code = bidder-code
# bidder_name = bidder-name
# hb_<keystr> = hb_<keystr>_<bidder-code> (20 char limit)
# CPM:
# cpm = line item rate as cost-per-thousand impressions
# Media:
# media_type = video or banner based on creative configuration below
# Misc:
# time = current UTC time represented as "%m/%d/%Y %H:%M:%S"
# Order:
# cpm_max = order maximum cpm
# cpm_min = order minimum cpm
#
# See https://docs.prebid.org/dev-docs/bidder-data.csv for referencing bidder
# names and codes.
###############################################################################
# Publisher (optional)
# This can be specified at run-time like this:
# --network-code <code>
# --network-name <name>
#
publisher:
network_code: 1234
network_name: "Video Publisher"
###############################################################################
# Advertiser (required)
# Allowed Templating Key Words: Bidder
###############################################################################
advertiser:
name: "Prebid"
###############################################################################
# Creatives (required)
# Allowed Templating Key Words: Bidder, Media, Misc
###############################################################################
creative: # at least one of the following types is required {video, banner}
name: "Prebid {{ bidder_name }}-{{ media_type }}"
video:
sizes: # list
- height: 480
width: 640
- height: 240
width: 320
vast_xml_url: "https://prebid.adnxs.com/pbc/v1/cache?uuid=%%PATTERN:{{ hb_cache_id }}%%"
banner:
sizes: # list
- height: 480
width: 640
snippet: |
<script src = "https://..."></script>
<script>
...
</script>
# safe_frame: False (optional: defaults to True)
###############################################################################
# Orders (required)
# Allowed Templating Key Words: Bidder, Media, Order, Misc
###############################################################################
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
#
# Supported Types: price_priority, standard, sponsorship
# datetimes use: "%m/%d/%y %H:%M" (ex. 11/17/20 21:28)
# - default timezone is UTC
# timezones: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
###############################################################################
line_item:
name: "Prebid-{{ bidder_name }}-{{ media_type }}-{{ time }} @ {{ cpm }}"
item_type: "price_priority"
# Optional
# goal: # required if sponsorship item_type
# units: 5
# unitType: "VIEWABLE_IMPRESSIONS"
# goalType: "LIFETIME"
# start_datetime: "11/17/20 21:28"
# end_datetime: "12/17/20 21:28"
# timezone: "UTC"
###############################################################################
# Bidder Targeting Key Override Map (optional):
# If provided override the default bidder_targeting_key and use these
# targeting keys specified by bidder_code.
#
# bidder_key_map:
# <bidder_code_1>: <bidder_targeting_key_1>
# <bidder_code_2>: <bidder_targeting_key_2>
###############################################################################
# Targeting (required)
# Allowed Templating Key Words: None
#
# Note: A Key-Value of 'bidder_targeting_key' with all CPM values is created
# by default.
###############################################################################
targeting:
custom: # list (optional)
- name: "country"
values:
- "US"
- "CAN"
# One of the below either placemane_names or ad_unit_names is required
placement_names: # list of names
- "placement name 1"
- "placement name 2"
ad_unit_names: # list of names
- "ad unit name 1"
- "ad unit name 2"
###############################################################################
# Rate (required)
# NOTE: granularity in Prebid.js config must align with this granularity
# Allowed Templating Key Words: None
###############################################################################
rate:
currency: "USD" # required
granularity:
type: "custom"
custom:
- min: 0.105
max: 0.30
interval: 0.10
- min: 0.30
max: 1.30
interval: 0.50
# optional properties
# vcpm: 100000 # viewable impressions will be enabled

2 changes: 2 additions & 0 deletions tests/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ def performOrderAction(self, *args):
'{\'bad_code\'} must be valid bidder codes'),
(f'tests/resources/cfg_bad_bidder_keys.yml -k {KEY_FILE} -b interactiveOffers',
'for \'pubmatic\' must be valid bidder keys'),
(f'tests/resources/cfg_bad_custom_bucket.yml -k {KEY_FILE} -b interactiveOffers',
'Bucket min, 0.105, is not a multiple of 0.01'),
])
def test_cli_create_bad(monkeypatch, command, err_str):
"""Test the CLI."""
Expand Down

0 comments on commit 54fb029

Please sign in to comment.