示例#1
0
def test_creative_is_auditable(audit_app, appnexus_api_auditing):
    '''
    Checks if only those creatives which are attached to some strategy
    can be auditable (which means that they could be sent for audit manually from UI).
    '''
    creative = audit_app.models['creative']['creative_image_1']
    strategy = audit_app.models['strategy']['Hello this is Citrus']
    landing_site = Site.objects.get(url='http://www.google.com/',
                                    owner=strategy.campaign.account)

    audit_creative_call = \
        call.audit_creative(creative.appnexus_id, creative.id_random,
                            creative.width, creative.height, AppCreativeTemplate.image,
                            creative.appnexus_media_url, True)

    # Creative is not attached to any strategy
    assert creative.is_auditable is False

    # Sending for audit manually will result in exception
    with pytest.raises(ValueError):
        creative.send_for_audit()

    # Let's attach creative to some strategy by creating an advert
    Advert.objects.create(strategy=strategy,
                          creative=creative,
                          landing_site=landing_site)
    creative = Creative.objects.get(id=creative.id)

    assert creative.is_auditable is True

    creative.send_for_audit()
    assert audit_creative_call in appnexus_api_auditing.mock_calls
示例#2
0
def test_fbx_creatives_is_send_to_audit_when_domain_is_changed(
        cdn_api, audit_app, appnexus_api_auditing, creative_name):
    appnexus_api = appnexus_api_auditing

    creative = audit_app.models['creative'][creative_name]
    strategy = audit_app.models['strategy']['FBX']
    landing = Site.objects.get(url='http://www.google.com/',
                               owner=strategy.campaign.account)

    Advert.objects.create(strategy=strategy,
                          creative=creative,
                          landing_site=landing)
    set_creative_as_audited(creative)
    # reset mock calls set by saving advert
    appnexus_api.mock_calls = []
    cdn_api.mock_calls = []

    creative = Creative.objects.get(pk=creative.pk)
    creative.domain = 'gravity4_1.com'

    creative.save()
    send_for_audit()

    creative_call = call.creative(creative.appnexus_id)
    audit_creative_call = \
        call.audit_creative(creative.appnexus_id, creative.id_random, creative.width, creative.height,
                            AppCreativeTemplate.fb_newsfeed_image, creative.appnexus_media_url,
                            creative.type != 'Video', creative.data_for_facebook_audit)

    # send for audit on landing_site_url change of rejected creative
    assert creative_call in appnexus_api.mock_calls
    assert audit_creative_call in appnexus_api.mock_calls
    # don't upload to cdn
    assert cdn_api.mock_calls == []
示例#3
0
def test_creatives_is_send_to_audit_when_image_is_changed(
        cdn_api, audit_app, appnexus_api_auditing, creative_name,
        strategy_name, creative_template):
    appnexus_api = appnexus_api_auditing

    creative = audit_app.models['creative'][creative_name]
    strategy = audit_app.models['strategy'][strategy_name]
    landing = Site.objects.get(url='http://www.google.com/',
                               owner=strategy.campaign.account)

    Advert.objects.create(strategy=strategy,
                          creative=creative,
                          landing_site=landing)

    # reset mock calls set by saving advert
    appnexus_api.mock_calls = []
    cdn_api.mock_calls = []

    set_creative_as_audited(creative)

    creative_image = 'creatives/test_creative_2.jpg'
    copy_creative_to_media_root(creative_name=creative_image)

    creative = Creative.objects.get(pk=creative.pk)
    creative.image = creative_image

    creative.save()

    upload_call = call.delay(creative.pk, creative.contents)

    assert upload_call in cdn_api.mock_calls

    send_for_audit()

    creative_call = call.creative(
        Creative.objects.filter(name=creative_name)[0].appnexus_id)
    audit_creative_call = \
        call.audit_creative(creative.appnexus_id, creative.id_random, creative.width, creative.height,
                            creative_template, creative.appnexus_media_url,
                            creative.type != 'Video', creative.data_for_facebook_audit)

    assert creative_call in appnexus_api.mock_calls
    assert audit_creative_call in appnexus_api.mock_calls
示例#4
0
def test_audit_fees(audit_app, appnexus_api_auditing):
    appnexus_api = appnexus_api_auditing

    creative = audit_app.models['creative']['creative_image_1']
    strategy = audit_app.models['strategy']['Hello this is Citrus']
    landing = Site.objects.get(url='http://www.google.com/',
                               owner=strategy.campaign.account)
    Advert.objects.create(strategy=strategy,
                          creative=creative,
                          landing_site=landing)

    audit_creative_call = \
        call.audit_creative(creative.appnexus_id, creative.id_random,
                            creative.width, creative.height, AppCreativeTemplate.image,
                            creative.appnexus_media_url, True)

    audit_fees = 0
    account_balance = creative.owner.account_balance()
    assert account_balance > AUDIT_FEE

    # 1. There is enough money to audit. Send creative multiple times for
    # audit and check if fees are calculated correctly.

    while account_balance > 0:
        creative.send_for_audit(force=True)
        creative = Creative.objects.get(pk=creative.pk)

        audit_fees += AUDIT_FEE
        account_balance -= AUDIT_FEE

        assert creative.audit_fees == audit_fees
        assert creative.owner.account_balance() == account_balance
        assert DailySpendings.objects.get(date=date.today(), account=creative.owner) \
                   .audit_fees == audit_fees

        assert audit_creative_call in appnexus_api.mock_calls
        appnexus_api.mock_calls = []

    # 2. Account balance is empty. Check if creative is not sent for audit. No fees should
    # be changed and notification event about low budget should be created.

    creative.send_for_audit(force=True)
    creative = Creative.objects.get(pk=creative.pk)

    assert creative.audit_fees == audit_fees
    assert creative.owner.account_balance() == account_balance
    assert audit_creative_call not in appnexus_api.mock_calls
    assert Event.objects.filter(message_type=Event.Messages.types.keys().index(
        'not_enough_budget_for_audit')).count() == 1

    # 3. Charge account and try to send creative again.

    audit_app.setup_payments(default_payments)
    account_balance = creative.owner.account_balance()

    creative.send_for_audit(force=True)
    creative = Creative.objects.get(pk=creative.pk)

    audit_fees += AUDIT_FEE
    account_balance -= AUDIT_FEE

    assert creative.audit_fees == audit_fees
    assert creative.owner.account_balance() == account_balance
    assert audit_creative_call in appnexus_api.mock_calls
    assert DailySpendings.objects.get(date=date.today(), account=creative.owner) \
               .audit_fees == audit_fees
示例#5
0
def test_creatives_is_send_to_audit_when_landing_page_is_changed(
        cdn_api, audit_app, appnexus_api_auditing, creative_name,
        strategy_name, creative_template):
    appnexus_api = appnexus_api_auditing

    creative = audit_app.models['creative'][creative_name]
    strategy = audit_app.models['strategy'][strategy_name]
    landing = Site.objects.get(url='http://www.google.com/',
                               owner=strategy.campaign.account)

    Advert.objects.create(strategy=strategy,
                          creative=creative,
                          landing_site=landing)

    set_creative_as_audited(creative)

    appnexus_api.mock_calls = []
    cdn_api.mock_calls = []

    creative = Creative.objects.get(pk=creative.pk)
    creative.landing_site_url = 'http://go.com/'
    creative.save()

    send_for_audit()

    creative_call = call.creative(creative.appnexus_id)
    audit_creative_call = \
        call.audit_creative(creative.appnexus_id, creative.id_random, creative.width, creative.height,
                            creative_template, creative.appnexus_media_url,
                            creative.type != 'Video', creative.data_for_facebook_audit)

    # don't upload to cdn if content is not changed
    assert cdn_api.mock_calls == []
    # don't send for audit on landing_site_url change if already audited
    if not creative.destination == u'd':
        assert creative_call in appnexus_api.mock_calls
        assert audit_creative_call in appnexus_api.mock_calls
    else:
        assert appnexus_api.mock_calls == []

    creative = Creative.objects.get(pk=creative.pk)
    creative.appnexus_status = 'r'
    creative.landing_site_url = 'http://gohome.com/'

    creative.save()

    creative_call = call.creative(creative.appnexus_id)
    audit_creative_call = \
        call.audit_creative(creative.appnexus_id, creative.id_random, creative.width, creative.height,
                            creative_template, creative.appnexus_media_url,
                            creative.type != 'Video', creative.data_for_facebook_audit)

    appnexus_api.mock_calls = []

    send_for_audit()

    # send for audit on landing_site_url change of rejected creative
    assert creative_call in appnexus_api.mock_calls
    assert audit_creative_call in appnexus_api.mock_calls
    # don't upload to cdn
    assert cdn_api.mock_calls == []
示例#6
0
def test_audit_tasks_execution(audit_app, appnexus_api_auditing, cdn_api,
                               creative_name, creative_template, duration):
    '''
    Checks if creation of Advert has a side effect in calling cdn
    and AppNexus API.
    '''
    medias = [{
        'duration': duration,
        'width': 400,
        'height': 300,
        'type': 'video/flv',
        'url': 'http://example.com'
    }]
    liverail_list_video_assets = patch(
        'apis.liverail.LiveRailAPI.list_video_assets', return_value=medias)

    appnexus_api = appnexus_api_auditing
    creative = audit_app.models['creative'][creative_name]
    if creative.destination == u'd':
        strategy = audit_app.models['strategy']['Hello this is Citrus']
    else:
        strategy = audit_app.models['strategy']['FBX']
    with liverail_login, liverail_creative_status, liverail_list_video_assets, liverail_logout:
        update_video_creative_media()

    creative = Creative.objects.get(pk=creative.pk)
    advert = Advert.objects.create(strategy=strategy,
                                   creative=creative,
                                   landing_site=Site.objects.get(
                                       url='http://www.google.com/',
                                       owner=strategy.campaign.account))

    send_for_audit()

    creative = Creative.objects.get(pk=creative.pk)

    upload_call = call(creative.pk, creative.contents)

    creative_call = call.creative(creative.appnexus_id)
    audit_creative_call = call.audit_creative(None, creative.id_random,
                                              creative.width, creative.height,
                                              creative_template,
                                              creative.appnexus_media_url,
                                              creative.type != 'Video',
                                              creative.data_for_facebook_audit)

    assert upload_call in cdn_api.mock_calls
    assert appnexus_api.mock_calls == [audit_creative_call, creative_call]

    appnexus_api.mock_calls = []
    cdn_api.mock_calls = []

    advert.is_default = True
    advert.save()

    # changing advert shouldn't send creative for audit
    assert appnexus_api.mock_calls == []

    creative.name += '[updated]'
    creative.save()

    # changing creative name shoudn't send it for audit
    assert appnexus_api.mock_calls == []
    assert cdn_api.mock_calls == []