Esempio n. 1
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 == []
Esempio n. 2
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
Esempio n. 3
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 == []
Esempio n. 4
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 == []