Beispiel #1
0
    def test_get_prices_array_changed_precision(self):
        """
    It returns the expected array with custom price precision.
    """

        config = {
            'precision': 3,
            'min': 1,
            'max': 1.1,
            'increment': 0.012,
        }
        self.assertEqual(get_prices_array(config), [
            1000000, 1012000, 1024000, 1036000, 1048000, 1060000, 1072000,
            1084000, 1096000
        ])

        config = {
            'precision': 2,
            'min': 1,
            'max': 1.1,
            'increment': 0.012,
        }
        self.assertEqual(get_prices_array(config), [
            1000000, 1010000, 1020000, 1030000, 1040000, 1050000, 1060000,
            1070000, 1080000, 1090000, 1100000
        ])
Beispiel #2
0
    def test_get_prices_array_normal(self):
        """
    It returns the expected array with normal use.
    """

        config = {
            'precision': 2,
            'min': 0,
            'max': 5,
            'increment': 0.50,
        }
        self.assertEqual(get_prices_array(config), [
            0, 500000, 1000000, 1500000, 2000000, 2500000, 3000000, 3500000,
            4000000, 4500000, 5000000
        ])

        config = {
            'precision': 2,
            'min': 2,
            'max': 3.50,
            'increment': 0.10,
        }
        self.assertEqual(get_prices_array(config), [
            2000000, 2100000, 2200000, 2300000, 2400000, 2500000, 2600000,
            2700000, 2800000, 2900000, 3000000, 3100000, 3200000, 3300000,
            3400000, 3500000
        ])
Beispiel #3
0
    def test_get_prices_array_length(self):
        """
    It returns the expected number of prices.
    """

        config = {
            'precision': 2,
            'min': 0,
            'max': 20,
            'increment': 0.10,
        }
        self.assertEqual(len(get_prices_array(config)), 201)

        config = {
            'precision': 2,
            'min': 0,
            'max': 20,
            'increment': 0.50,
        }
        self.assertEqual(len(get_prices_array(config)), 41)

        config = {
            'precision': 2,
            'min': 0,
            'max': 15,
            'increment': 0.01,
        }
        self.assertEqual(len(get_prices_array(config)), 1501)
Beispiel #4
0
def main():
    """
  Validate the settings and ask for confirmation from the user. Then,
  start all necessary DFP tasks.
  """

    user_email = getattr(settings, 'DFP_USER_EMAIL_ADDRESS', None)
    if user_email is None:
        raise MissingSettingException('DFP_USER_EMAIL_ADDRESS')

    advertiser_name = getattr(settings, 'DFP_ADVERTISER_NAME', None)
    if advertiser_name is None:
        raise MissingSettingException('DFP_ADVERTISER_NAME')

    order_name = getattr(settings, 'DFP_ORDER_NAME', None)
    if order_name is None:
        raise MissingSettingException('DFP_ORDER_NAME')

    placements = getattr(settings, 'DFP_TARGETED_PLACEMENT_NAMES', None)
    ad_units = getattr(settings, 'DFP_TARGETED_AD_UNIT_NAMES', None)

    video_ad_type = getattr(settings, 'DFP_VIDEO_AD_TYPE', False)
    vast_redirect_url = getattr(settings, 'DFP_VAST_REDIRECT_URL', '')

    if video_ad_type is True and len(vast_redirect_url) < 1:
        raise BadSettingException(
            'When setting "DFP_VIDEO_AD_TYPE" to "True", please also set "DFP_VAST_REDIRECT_URL".'
        )

    if ad_units is None and placements is None:
        raise MissingSettingException(
            'DFP_TARGETED_PLACEMENT_NAMES or DFP_TARGETED_AD_UNIT_NAMES')
    elif (placements is None
          or len(placements) < 1) and (ad_units is None or len(ad_units) < 1):
        raise BadSettingException(
            'The setting "DFP_TARGETED_PLACEMENT_NAMES" or "DFP_TARGETED_AD_UNIT_NAMES" '
            'must contain at least one DFP placement or ad unit.')

    sizes = getattr(settings, 'DFP_PLACEMENT_SIZES', None)
    if sizes is None:
        raise MissingSettingException('DFP_PLACEMENT_SIZES')
    elif len(sizes) < 1:
        raise BadSettingException('The setting "DFP_PLACEMENT_SIZES" '
                                  'must contain at least one size object.')

    currency_code = getattr(settings, 'DFP_CURRENCY_CODE', 'USD')

    line_item_format = getattr(settings, 'DFP_LINE_ITEM_FORMAT',
                               u'{bidder_code}: HB ${price}')

    # How many creatives to attach to each line item. We need at least one
    # creative per ad unit on a page. See:
    # https://github.com/kmjennison/dfp-prebid-setup/issues/13
    num_creatives = (getattr(settings, 'DFP_NUM_CREATIVES_PER_LINE_ITEM', None)
                     or len(placements) + len(ad_units))

    bidder_code = getattr(settings, 'PREBID_BIDDER_CODE', None)
    if bidder_code is None:
        raise MissingSettingException('PREBID_BIDDER_CODE')

    price_buckets = getattr(settings, 'PREBID_PRICE_BUCKETS', None)
    if price_buckets is None:
        raise MissingSettingException('PREBID_PRICE_BUCKETS')

    check_price_buckets_validity(price_buckets)

    prices = get_prices_array(price_buckets)
    prices_summary = get_prices_summary_string(prices)

    logger.info(u"""

    Going to create {name_start_format}{num_line_items}{format_end} new line items.
      {name_start_format}Order{format_end}: {value_start_format}{order_name}{format_end}
      {name_start_format}Advertiser{format_end}: {value_start_format}{advertiser}{format_end}

    Line items will have targeting:
      {name_start_format}hb_pb{format_end} = {value_start_format}{prices_summary}{format_end}
      {name_start_format}hb_bidder{format_end} = {value_start_format}{bidder_code}{format_end}
      {name_start_format}placements{format_end} = {value_start_format}{placements}{format_end}
      {name_start_format}ad units{format_end} = {value_start_format}{ad_units}{format_end}
    """.format(
        num_line_items=len(prices),
        order_name=order_name,
        advertiser=advertiser_name,
        user_email=user_email,
        prices_summary=prices_summary,
        bidder_code=bidder_code,
        placements=placements,
        ad_units=ad_units,
        sizes=sizes,
        name_start_format=color.BOLD,
        format_end=color.END,
        value_start_format=color.BLUE,
    ))

    if video_ad_type:
        logger.info(
            u"""    Line items will have VAST redirect creatives with redirect URL:
      {value_start_format}{redirect_url}{format_end}

    """.format(
                redirect_url=vast_redirect_url,
                value_start_format=color.BLUE,
                format_end=color.END,
            ))
    else:
        logger.info(
            u"""    Line items will have third party creatives based on snippet.html content.

    """)

    ok = input('Is this correct? (y/n)\n')

    if ok != 'y':
        logger.info('Exiting.')
        return

    setup_partner(user_email, advertiser_name, order_name, placements,
                  ad_units, sizes, bidder_code, prices, num_creatives,
                  currency_code, line_item_format, video_ad_type,
                  vast_redirect_url)
Beispiel #5
0
        'width': '300',
        'height': '250'
    },
    {
        'width': '728',
        'height': '90'
    },
]
bidder_code = 'mypartner'
price_buckets = {
    'precision': 2,
    'min': 0,
    'max': 20,
    'increment': 0.10,
}
prices = get_prices_array(price_buckets)


@patch.multiple('settings',
                DFP_USER_EMAIL_ADDRESS=email,
                DFP_ADVERTISER_NAME=advertiser,
                DFP_ORDER_NAME=order,
                DFP_TARGETED_PLACEMENT_NAMES=placements,
                DFP_TARGETED_AD_UNIT_NAMES=ad_units,
                DFP_PLACEMENT_SIZES=sizes,
                PREBID_BIDDER_CODE=bidder_code,
                PREBID_PRICE_BUCKETS=price_buckets,
                DFP_CREATE_ADVERTISER_IF_DOES_NOT_EXIST=False)
@patch('googleads.ad_manager.AdManagerClient.LoadFromStorage')
class AddNewPrebidPartnerTests(TestCase):
    def test_missing_email_setting(self, mock_dfp_client):
Beispiel #6
0
def main():
    """
  Validate the settings and ask for confirmation from the user. Then,
  start all necessary DFP tasks.
  """

    user_email = getattr(settings, 'DFP_USER_EMAIL_ADDRESS', None)
    if user_email is None:
        raise MissingSettingException('DFP_USER_EMAIL_ADDRESS')

    advertiser_name = getattr(settings, 'DFP_ADVERTISER_NAME', None)
    if advertiser_name is None:
        raise MissingSettingException('DFP_ADVERTISER_NAME')

    order_name = getattr(settings, 'DFP_ORDER_NAME', None)
    if order_name is None:
        raise MissingSettingException('DFP_ORDER_NAME')

    placements = getattr(settings, 'DFP_TARGETED_PLACEMENT_NAMES', None)
    if placements is None:
        raise MissingSettingException('DFP_TARGETED_PLACEMENT_NAMES')
    elif len(placements) < 1:
        raise BadSettingException(
            'The setting "DFP_TARGETED_PLACEMENT_NAMES" '
            'must contain at least one DFP placement ID.')

    sizes = getattr(settings, 'DFP_PLACEMENT_SIZES', None)
    if sizes is None:
        raise MissingSettingException('DFP_PLACEMENT_SIZES')
    elif len(sizes) < 1:
        raise BadSettingException('The setting "DFP_PLACEMENT_SIZES" '
                                  'must contain at least one size object.')

    currency_code = getattr(settings, 'DFP_CURRENCY_CODE', 'USD')

    # How many creatives to attach to each line item. We need at least one
    # creative per ad unit on a page. See:
    # https://github.com/kmjennison/dfp-prebid-setup/issues/13
    num_creatives = (getattr(settings, 'DFP_NUM_CREATIVES_PER_LINE_ITEM', None)
                     or len(placements))

    bidder_code = getattr(settings, 'PREBID_BIDDER_CODE', None)
    if bidder_code is None:
        raise MissingSettingException('PREBID_BIDDER_CODE')

    price_buckets = getattr(settings, 'PREBID_PRICE_BUCKETS', None)
    if price_buckets is None:
        raise MissingSettingException('PREBID_PRICE_BUCKETS')

    check_price_buckets_validity(price_buckets)

    prices = get_prices_array(price_buckets)
    prices_summary = get_prices_summary_string(prices,
                                               price_buckets['precision'])

    logger.info(u"""

    Going to create {name_start_format}{num_line_items}{format_end} new line items.
      {name_start_format}Order{format_end}: {value_start_format}{order_name}{format_end}
      {name_start_format}Advertiser{format_end}: {value_start_format}{advertiser}{format_end}

    Line items will have targeting:
      {name_start_format}hb_pb{format_end} = {value_start_format}{prices_summary}{format_end}
      {name_start_format}hb_bidder{format_end} = {value_start_format}{bidder_code}{format_end}
      {name_start_format}placements{format_end} = {value_start_format}{placements}{format_end}

    """.format(
        num_line_items=len(prices),
        order_name=order_name,
        advertiser=advertiser_name,
        user_email=user_email,
        prices_summary=prices_summary,
        bidder_code=bidder_code,
        placements=placements,
        sizes=sizes,
        name_start_format=color.BOLD,
        format_end=color.END,
        value_start_format=color.BLUE,
    ))

    ok = input('Is this correct? (y/n)\n')

    if ok != 'y':
        logger.info('Exiting.')
        return

    setup_partner(
        user_email,
        advertiser_name,
        order_name,
        placements,
        sizes,
        bidder_code,
        prices,
        num_creatives,
        currency_code,
    )
Beispiel #7
0
def main():
    """
  Validate the settings and ask for confirmation from the user. Then,
  start all necessary DFP tasks.
  """

    user_email = getattr(settings, 'DFP_USER_EMAIL_ADDRESS', None)
    if user_email is None:
        raise MissingSettingException('DFP_USER_EMAIL_ADDRESS')

    advertiser_name = getattr(settings, 'DFP_ADVERTISER_NAME', None)
    if advertiser_name is None:
        raise MissingSettingException('DFP_ADVERTISER_NAME')

    order_name = getattr(settings, 'DFP_ORDER_NAME', None)
    if order_name is None:
        raise MissingSettingException('DFP_ORDER_NAME')

    placements = getattr(settings, 'DFP_TARGETED_PLACEMENT_NAMES', None)
    no_inventory = getattr(settings, 'DFP_ALLOW_NO_INVENTORY_TARGETING', None)
    if placements is None:
        raise MissingSettingException('DFP_TARGETED_PLACEMENT_NAMES')
    elif len(placements) < 1 and no_inventory is not True:
        raise BadSettingException(
            'The setting "DFP_TARGETED_PLACEMENT_NAMES" '
            'must contain at least one DFP placement ID.')

    sizes = getattr(settings, 'DFP_PLACEMENT_SIZES', None)
    if sizes is None:
        raise MissingSettingException('DFP_PLACEMENT_SIZES')
    elif len(sizes) < 1:
        raise BadSettingException('The setting "DFP_PLACEMENT_SIZES" '
                                  'must contain at least one size object.')

    currency_code = getattr(settings, 'DFP_CURRENCY_CODE', 'USD')

    # How many creatives to attach to each line item. We need at least one
    # creative per ad unit on a page. See:
    # https://github.com/kmjennison/dfp-prebid-setup/issues/13
    num_creatives = (getattr(settings, 'DFP_NUM_CREATIVES_PER_LINE_ITEM', None)
                     or len(placements))

    # In the case where no inventory is being used, make sure at least one
    # creative is created
    if not num_creatives > 0:
        num_creatives = 1

    bidder_code = getattr(settings, 'PREBID_BIDDER_CODE', None)
    if bidder_code is None:
        raise MissingSettingException('PREBID_BIDDER_CODE')

    bidder_params = getattr(settings, 'PREBID_BIDDER_PARAMS', None)
    hb_pb_key = 'hb_pb'
    additional_keys = ''

    if bidder_params is True:
        hb_pb_key += '_' + bidder_code
        hb_adid_key = 'hb_adid_' + bidder_code
        hb_size_key = 'hb_size_' + bidder_code

        if len(hb_pb_key) > 20:
            hb_pb_key = hb_pb_key[:20]

        if len(hb_adid_key) > 20:
            hb_adid_key = hb_adid_key[:20]

        if len(hb_size_key) > 20:
            hb_size_key = hb_size_key[:20]

        additional_keys = u"""

    Additionally, keys {name_start_format}{hb_adid_key}{format_end} and {name_start_format}{hb_size_key}{format_end} will be created.""".format(
            hb_adid_key=hb_adid_key,
            hb_size_key=hb_size_key,
            name_start_format=color.BOLD,
            format_end=color.END,
        )

    price_buckets = getattr(settings, 'PREBID_PRICE_BUCKETS', None)
    if price_buckets is None:
        raise MissingSettingException('PREBID_PRICE_BUCKETS')

    check_price_buckets_validity(price_buckets)

    prices = get_prices_array(price_buckets)
    prices_summary = get_prices_summary_string(prices,
                                               price_buckets['precision'])

    logger.info(u"""

    Going to create {name_start_format}{num_line_items}{format_end} new line items.
      {name_start_format}Order{format_end}: {value_start_format}{order_name}{format_end}
      {name_start_format}Advertiser{format_end}: {value_start_format}{advertiser}{format_end}
      {name_start_format}Owner{format_end}: {value_start_format}{user_email}{format_end}

    Line items will have targeting:
      {name_start_format}{hb_pb_key}{format_end} = {value_start_format}{prices_summary}{format_end}
      {name_start_format}hb_bidder{format_end} = {value_start_format}{bidder_code}{format_end}
      {name_start_format}placements{format_end} = {value_start_format}{placements}{format_end}{additional_keys}

    """.format(num_line_items=len(prices),
               order_name=order_name,
               advertiser=advertiser_name,
               user_email=user_email,
               hb_pb_key=hb_pb_key,
               prices_summary=prices_summary,
               bidder_code=bidder_code,
               placements=placements,
               sizes=sizes,
               name_start_format=color.BOLD,
               format_end=color.END,
               value_start_format=color.BLUE,
               additional_keys=additional_keys))

    ok = input('Is this correct? (y/n)\n')

    if ok != 'y':
        logger.info('Exiting.')
        return

    setup_partner(
        user_email,
        advertiser_name,
        order_name,
        placements,
        sizes,
        bidder_code,
        prices,
        num_creatives,
        currency_code,
    )