Esempio n. 1
0
def test_default_commission(app_audited, redisdb_targeting):
    """
    Test default value of commission value.
    """
    trigger_cache_mappings()

    check_commission(redisdb_targeting, constants.COMMISSION)
Esempio n. 2
0
def test_strategy_audience_remove(redisdb_targeting, included):

    strategy = Strategy.objects.first()
    audiences = Audience.objects.all()
    if included:
        strategy.audiences = audiences
    else:
        strategy.audiences_exclude = audiences
    strategy.save()

    trigger_cache_mappings()

    if included:
        strategy.audiences.remove(audiences[0])
    else:
        strategy.audiences_exclude.remove(audiences[0])
    strategy.save()

    trigger_cache_mappings()
    for advert in Advert.objects.all():
        cache_ad = cPickle.loads(
            redisdb_targeting.hget(redis_keys.ads, advert.public_id))
        aud_include = frozenset(advert.strategy.get_audience_ids())
        aud_exclude = frozenset(advert.strategy.get_audience_ids(exclude=True))
        assert cache_ad.audiences_include == aud_include
        assert cache_ad.audiences_exclude == aud_exclude
        if included:
            assert audiences[0] not in aud_include
        else:
            assert audiences[0] not in aud_exclude
Esempio n. 3
0
def test_advert_mapping_landing_sites(redisdb_targeting):
    trigger_cache_mappings()

    for advert in Advert.objects.all():
        target_ad = cPickle.loads(
            redisdb_targeting.hget(redis_keys.ads, advert.public_id))
        assert target_ad.landing_sites == [("http://google.pl", 1)]
Esempio n. 4
0
def test_accountdetail_advert(app_audited, redisdb_profiles, redisdb_targeting,
                              redisdb_optimizer):
    """
    Check if cached_ad has correct information stored on.
    """
    trigger_cache_mappings()
    for advert in Advert.objects.all():
        cached_ad = cPickle.loads(
            redisdb_targeting.hget(redis_keys.ads, advert.public_id))
        assert cached_ad.account_budget == cast_currency_to_CPM(
            advert.creative.owner.total_paid())
        assert cached_ad.account_fees == cast_currency_to_CPM(
            advert.creative.owner.audit_fees)
        assert cached_ad.account_id == advert.creative.owner.public_id

    account = Account.objects.first()
    account.audit_fees = 1
    account.save()
    trigger_cache_mappings()

    for advert in Advert.objects.all():
        cached_ad = cPickle.loads(
            redisdb_targeting.hget(redis_keys.ads, advert.public_id))
        assert cached_ad.account_budget == cast_currency_to_CPM(
            advert.creative.owner.total_paid())
        assert cached_ad.account_fees == cast_currency_to_CPM(1)
        assert cached_ad.account_id == advert.creative.owner.public_id
Esempio n. 5
0
def test_different_commission(app_audited, redisdb_targeting, commission):
    """
    Test different values for commission field.
    """
    for account in Account.objects.all():
        account.commission = commission
        account.save()

    trigger_cache_mappings()

    check_commission(redisdb_targeting, commission)
Esempio n. 6
0
def test_default_bid_cpm_strategy(app_audited, redisdb_targeting,
                                  redisdb_profiles):
    '''Checks if bid values are properly written to cache from strategy'''

    budget_size = 99.

    for strategy in Strategy.objects.all():
        strategy.budget_bid_CPM = budget_size
        strategy.save()
    trigger_cache_mappings()

    check_ads_bid_value(redisdb_targeting, budget_size)
Esempio n. 7
0
def test_campaign_mapping_default_conv_values(campaigns, redisdb_adserver):
    ''' Test saving default conversion values to redis '''
    for index, campaign in enumerate(Campaign.objects.all()):
        conv = campaign.conversion_def
        conv.value = index + 1
        conv.save()

    trigger_cache_mappings()

    for index, campaign in enumerate(Campaign.objects.all()):
        rv = redisdb_adserver.hget(constants.campaign_default_conv_value_key,
                                   campaign.public_id)
        assert cPickle.loads(rv) == float(index + 1)
Esempio n. 8
0
def test_default_bid_cpm_advert(app_audited, redisdb_targeting,
                                redisdb_profiles):
    '''Checks if bid values are properly written to cache from advert'''
    budget_size = 989.

    for advert in Advert.objects.all():
        advert.custom_bid_CPM = budget_size
        advert.save()

    for strategy in Strategy.objects.all():
        strategy.budget_bid_CPM = int(budget_size * 2)
        strategy.save()

    trigger_cache_mappings()

    check_ads_bid_value(redisdb_targeting, budget_size)
def test_creative_audit_dirtify(creative_resource, audit_app, creative_type):
    """Test that Creative audit dirtifies the cache."""
    if creative_type == 'video':
        audit_app.setup_creative_videos()
    creative_name = 'creative_%s_1' % creative_type
    audit_app.setup_adverts(adverts=[
        {
            'name': 'ad_lemon',
            'strategy': 'Hello this is Citrus',
            'creative': creative_name,
            'url': 'http://www.google.com/',
        },
        {
            'name': 'ad_orange',
            'strategy': 'Hello this is Citrus',
            'creative': creative_name,
            'url': 'http://www.wp.pl/',
        },
        {
            'name': 'ad_carrot',
            'strategy': 'han i has a pumpkin?',
            'creative': creative_name,
            'url': 'http://www.google.com/',
        },
        {
            'name': 'ad_celery',
            'strategy': 'han i has a pumpkin?',
            'creative': creative_name,
            'url': 'http://www.wp.pl/',
        },
    ])
    creative = audit_app.models['creative'][creative_name]

    creative.appnexus_status = 'p'
    creative.save()

    trigger_cache_mappings()
    assert len(creative.advert_set.all()) > 0
    for ad in creative.advert_set.all():
        assert not ad.cache_is_dirty

    appnexus_update_status_all()
    assert creative.cache_is_dirty

    for ad in creative.advert_set.all():
        assert ad.cache_is_dirty
Esempio n. 10
0
def test_content_categories(app_audited, redisdb_targeting, redisdb_profiles):
    """
    Checks redis targeting (content categories - include and exclude).
    """
    content_categories = ContentCategory.objects.all()

    for strategy in Strategy.objects.all():
        strategy.content_category_values = content_categories
    trigger_cache_mappings()

    check_target_values(redisdb_targeting, content_categories)

    for strategy in Strategy.objects.all():
        strategy.content_category_values.clear()
        strategy.content_category_values_exclude = content_categories
    trigger_cache_mappings()

    check_target_values(redisdb_targeting, content_categories, include=False)
Esempio n. 11
0
def test_strategy_audience_is_ip(redisdb_targeting):

    strategy = Strategy.objects.first()
    audiences = Audience.objects.all()
    strategy.audiences = audiences
    strategy.save()

    trigger_cache_mappings()
    advert = strategy.advert_set.first()
    cache_ad = cPickle.loads(
        redisdb_targeting.hget(redis_keys.ads, advert.public_id))
    assert cache_ad.has_ip_audiences is False

    ip_audience = Audience.objects.first()
    ip_audience.is_ip = True
    ip_audience.save()

    trigger_cache_mappings()
    cache_ad = cPickle.loads(
        redisdb_targeting.hget(redis_keys.ads, advert.public_id))
    assert cache_ad.has_ip_audiences is True
Esempio n. 12
0
def test_advert_capping(app_audited, redisdb_targeting, redisdb_profiles,
                        capping):
    if capping:
        for campaign in Campaign.objects.all():
            for cap_obj, (cap_limit, cap_period) in capping.items():
                if cap_obj == 'campaign':
                    campaign.cap_campaign_selected = True
                    campaign.cap_total = cap_limit
                    campaign.cap_total_period = cap_period
                elif cap_obj == 'strategy':
                    campaign.cap_strategy_selected = True
                    campaign.cap_strategy = cap_limit
                    campaign.cap_strategy_period = cap_period
                elif cap_obj == 'ad':
                    campaign.cap_creative_selected = True
                    campaign.cap_creative = cap_limit
                    campaign.cap_creative_period = cap_period
            campaign.save()

    trigger_cache_mappings()

    check_ads_capping(redisdb_targeting, capping)
Esempio n. 13
0
 def handle(self, *args, **options):
     trigger_cache_mappings(force=True)
Esempio n. 14
0
def test_appnexus_profile_update(clean_strategy):
    '''
    1. Checking if celery task is setting the correct data through API.
    2. Checking if celery task is fired (by cache mapper) after changing targeting in strategy
    '''

    # undeleting one strategy
    strategy = Strategy.objects.all()[0]
    strategy.is_paused = False
    strategy.save()

    expected_response = nothing_set_profile.copy()
    expected_response['description'] = 'Automatic profile (on)'
    expected_response[
        'passthrough_percent'] = settings.appnexus_profile_passthrough
    expected_response['supply_type_targets'] = list(
        SUPPLY_TYPES[strategy.type])

    # checking ads sizes
    expected_response['size_targets'] = [{'height': 90, 'width': 728}]
    check_update_response(expected_response)

    # setting targeting on USA
    usa_appnexus = TargetValue.objects.create(
        exchange=EXCHANGES.appnexus,
        category=dimensions.g_location,
        value=TargetMap.pack(['USA', None, None]),
    )
    strategy.targeting_values.add(usa_appnexus)

    # setting targeting on Germany in Nexage
    germany_nexage = TargetValue.objects.create(
        exchange=EXCHANGES.nexage,
        category=dimensions.g_location,
        value=TargetMap.pack(['Germany', None, None]),
    )

    # setting AppNexus representant for Nexage country
    germany_appnexus = TargetValue.objects.create(
        exchange=EXCHANGES.appnexus,
        category=dimensions.g_location,
        value=TargetMap.pack(['GER', None, None]),
        representant=germany_nexage)

    # setting targeting on Germany from Nexage
    strategy.targeting_values.add(germany_nexage)

    # checking countries targeting
    expected_response['country_action'] = 'include'
    expected_response['country_targets'] = [{
        'country': 'GER'
    }, {
        'country': 'USA'
    }]
    check_update_response(expected_response)

    # changing country to region
    germany_nexage.value = TargetMap.pack(['Germany', 'LT', None])
    germany_nexage.save()
    germany_appnexus.value = TargetMap.pack(['GER', 'LT', None])
    germany_appnexus.save()

    # setting AppNexus representant for Nexage region in USA
    # (chenging country to region)
    usa_appnexus.value = TargetMap.pack(['USA', 'FL', None])
    usa_appnexus.save()

    expected_response['region_action'] = 'include'
    expected_response['region_targets'] = [{
        'region': 'USA:FL'
    }, {
        'region': 'GER:LT'
    }]
    check_update_response(expected_response)

    # setting targeting on Proximic Safety Level segment
    FAKE_APPNEXUS_ID = 330728
    strategy.segment_proximic_safety_level.add(
        SegmentProximicSafetyLevel.objects.create(appnexus_id=FAKE_APPNEXUS_ID,
                                                  name='Safe from Adult'))

    # checking segments targeting
    expected_response['segment_boolean_operator'] = 'or'
    expected_response['segment_targets'] = [{
        'id': FAKE_APPNEXUS_ID,
        'action': 'include'
    }]
    check_update_response(expected_response)

    # checking if celery task is triggered (inside cache mapper)
    # after changes in strategy
    with patch('ui.campaign.tasks.appnexus_update_profile.delay') as mock_task:
        assert mock_task.call_count == 0
        # strategy changes, we should update AppNexus profile
        trigger_cache_mappings()
        assert mock_task.call_count == 1
        # no changes - no task
        trigger_cache_mappings()
        assert mock_task.call_count == 1

    # Remove all adverts from strategies and check if profile is empty
    for strategy in Strategy.objects.all():
        for advert in strategy.advert_set.all():
            advert.delete()

    check_update_response(nothing_set_profile)