예제 #1
0
def test_audit_not_enough_budget(audit_low_budget, appnexus_api_auditing):
    '''
    Test creative 'audit blocked because of not enough budget'
    '''
    creative = Creative.objects.first()
    assert creative.state.pending
    assert not creative.state.blocked

    # Try to audit creative with too low account balance
    send_for_audit()

    # Check if event was created and creative status was set to blocked
    latest_event = Event.objects.all()[0]
    assert latest_event.message_name == 'not_enough_budget_for_audit'

    creative = Creative.objects.first()
    assert creative.state.pending
    assert creative.state.blocked

    # Add funds to account
    Payment.objects.create(account=creative.owner,
                           datetime=datetime.utcnow(),
                           amount=AUDIT_FEE)

    # Try to audit, status should not be not blocked
    send_for_audit()

    creative = Creative.objects.first()
    assert not creative.state.pending
    assert not creative.state.blocked
예제 #2
0
def test_audit_disabling(audit_app, appnexus_api_auditing):
    """checks if audit is disabled when creative is deleted."""
    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 = Advert.objects.create(strategy=strategy,
                                   creative=creative,
                                   landing_site=landing)

    creative.appnexus_id = 1234
    # creative.save()

    send_for_audit()

    advert.delete()
    creative.delete()

    disable_creative_audit_call = call.disable_creative_audit(
        creative.appnexus_id)

    assert disable_creative_audit_call in appnexus_api.mock_calls
def test_conformity_between_campaign_strategy_statuses_and_creative_appnexus_status(
        state_app, appnexus_api_rejecting, status, valid, invalid):

    creative = Creative.objects.get(name='creative_image_1')

    if valid == 'creatives_rejected' and status == 'r':
        send_for_audit()
    else:
        creative.appnexus_status = status
        creative.save()

    campaign = Campaign.objects.filter(name='I\'m a fruit')[0]
    strategy = Strategy.objects.filter(name='Hello this is Citrus')[0]

    assert creative in getattr(campaign.state, valid)
    assert creative not in getattr(campaign.state, invalid[0])
    assert creative not in getattr(campaign.state, invalid[1])

    assert creative in getattr(strategy.state, valid)
    assert creative not in getattr(strategy.state, invalid[0])
    assert creative not in getattr(strategy.state, invalid[1])

    # assure that distinct list of creatives is returned
    # no matter how much adverts with the same creative are bound to strategy
    assert len(getattr(campaign.state, valid)) == 1
    assert len(getattr(campaign.state, invalid[0])) == 0
    assert len(getattr(campaign.state, invalid[1])) == 0

    assert len(getattr(strategy.state, valid)) == 1
    assert len(getattr(strategy.state, invalid[0])) == 0
    assert len(getattr(strategy.state, invalid[1])) == 0
예제 #4
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 == []
예제 #5
0
def test_creative_rejected_email_sending(audit_app, appnexus_api_rejecting):
    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)
    send_for_audit()
    import ipdb
    ipdb.set_trace()
    assert is_email_sent('Your ad has been rejected')
예제 #6
0
def test_creatives_is_not_sent_to_audit_when_name_is_changed(
        cdn_api, audit_app, appnexus_api_auditing, creative_name,
        strategy_name, creative_template, duration):
    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()

    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 = Creative.objects.get(pk=creative.pk)
    creative.name = 'New name'
    creative.save()

    send_for_audit()

    assert appnexus_api.mock_calls == []
    assert appnexus_api.mock_calls == []
예제 #7
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
def test_conformity_between_creative_appnexus_status_and_creative_state(
        state_app, appnexus_api_rejecting, status, correct, incorrect):

    creative = Creative.objects.get(name='creative_image_1')

    if correct == 'rejected' and status == 'r':
        send_for_audit()
    else:
        creative.appnexus_status = status
        creative.save()

    creative = Creative.objects.get(name='creative_image_1')
    advert_1 = Advert.objects.filter(creative__name='creative_image_1')[0]
    advert_2 = Advert.objects.filter(creative__name='creative_image_1')[1]
    assert getattr(creative.state, correct) is True
    assert getattr(creative.state, incorrect[0]) is False
    assert getattr(creative.state, incorrect[1]) is False

    assert getattr(advert_1.state, correct) is True
    assert getattr(advert_2.state, correct) is True
예제 #9
0
def test_audit_email_sending(audit_app, 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)

    # clear outbox
    mail.outbox = []

    send_for_audit()
    assert is_email_sent('Your ad has been sent for audit')

    # charge account to have enough money for next audits
    audit_app.setup_payments(default_payments)

    # create 3 new creatives and make sure that only 1 email is sent
    for index in ['A', 'B', 'C']:
        creative = CreativeImage.objects.create(
            name='creative_{0}'.format(index),
            owner=strategy.campaign.account,
            width=300,
            height=250,
            image='creatives/test_creative.jpg')
        Advert.objects.create(strategy=strategy,
                              creative=creative,
                              landing_site=landing)

    # clear outbox
    mail.outbox = []

    send_for_audit()
    assert len(mail.outbox) == 1
    assert mail.outbox[0].subject == 'Your ads have been sent for audit'
예제 #10
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 == []
예제 #11
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 == []