Ejemplo n.º 1
0
def test_user_age_gender():
    data = api.public_get(VOD_ID,
                          context['partner'],
                          user_token=context['user_token']).json()
    # http://client-api.tvoli.com/api/ads/v1/vast-tracking/my-app/DQQ1O0YK89N9J99K302FRZUIGUSR/unknown?vastUrl=http%3A%2F%2Fpreroll.mobile%3Fuser%5Bgender%5D%3Dm%26user%5Byob%5D%3D1974', 'intervalroll': {'url': 'http://client-api.tvoli.com/api/ads/v1/vast-tracking/my-app/DQQ1O0YK89N9J99K302FRZUIGUSR/unknown?vastUrl=http%3A%2F%2Fintervalroll.mobile%3Fuser%5Bgender%5D%3Dm%26user%5Byob%5D%3D1974
    api_url = urlparse(deep_get(data, 'preroll'))
    assert_equal(api_url.hostname,
                 urlparse(config.api_global_url()).hostname,
                 'api url hostname')
    assert_equal(
        api_url.path,
        f'/api/ads/v1/vast-wrapper/{context["partner"]["id"]}/{context["user_id"]}/unknown',
        'api url path')
    url_string = parse_qs(api_url.query)['vastUrl'][0]
    url = urlparse(url_string)
    preroll_url = VOD_SETTINGS['preroll']['mobile']
    yob = str(context['user_info']['yearOfBirth'])
    gender = str(context['user_info']['gender'])
    url_string_expect = f'{preroll_url}&user[gender]={gender}&user[yob]={yob}'
    assert_equal(url_string, url_string_expect,
                 'vastUrl query param should be correct')
    query = parse_qs(url.query)
    expected_url = urlparse(deep_get(VOD_SETTINGS, 'preroll.mobile'))
    assert_equal(url.scheme, expected_url.scheme, 'url scheme')
    assert_equal(url.hostname, expected_url.hostname, 'url hostname')
    expected_query = {'user[yob]': yob, 'user[gender]': gender}
    for param in expected_query:
        assert_equal(deep_get(query, [param, 0]), expected_query[param],
                     'expected param %s' % param)
Ejemplo n.º 2
0
def test_device_type_mobile():
    data = api.public_get(VOD_ID, context['partner'],
                          device_type='mobile').json()
    assert_equal(deep_get(data, 'preroll'),
                 deep_get(VOD_SETTINGS, 'preroll.mobile'), 'preroll_url')
    assert_equal(deep_get(data, 'intervalroll.url'),
                 deep_get(VOD_SETTINGS, 'intervalroll.url.mobile'),
                 'intervalroll_url')
Ejemplo n.º 3
0
def test_defaults():
    partner_id = context['partner']['id']
    defaults = {'preroll': {'mobile': 'http://defaults.preroll.mobile'}}
    api.internal_defaults_delete(partner_id)
    api.internal_defaults_create(partner_id, defaults)

    data = api.public_get(NON_EXISTANT_ID, context['partner']).json()
    assert_equal(data, api.ad_settings_for_device(defaults),
                 'should be default ad settings with default device URLs')

    api.internal_defaults_delete(partner_id)
Ejemplo n.º 4
0
def test_frequency_cap():
    frequencyCap = 3
    device = 'unknown'
    updated_vod_settings = deep_set(VOD_SETTINGS, 'frequencyCap', frequencyCap)
    api.internal_update(context['partner']['id'], VOD_ID, updated_vod_settings)
    assert_equal(
        deep_get(
            api.internal_get(context['partner']['id'], VOD_ID).json(),
            'adSettings.frequencyCap'), frequencyCap,
        'internal_get after update of frequencyCap')

    response = api.public_get(VOD_ID,
                              context['partner'],
                              user_token=context['user_token'])
    assert_equal(response.status_code, 200, 'status_code API user first time')
    api.public_get_tracking(context['partner'], context['user_id'], device)
    response = api.public_get(VOD_ID,
                              context['partner'],
                              user_token=context['user_token'])
    assert_equal(response.status_code, 404, 'status_code API user second time')
Ejemplo n.º 5
0
def test_free_users_only():
    response = api.public_get(VOD_ID,
                              context['partner'],
                              user_token=context['user_token'])
    assert_equal(response.status_code, 200,
                 'status_code before setting freeUsersOnly=true')

    updated_vod_settings = deep_set(VOD_SETTINGS, 'freeUsersOnly', True)
    api.internal_update(context['partner']['id'], VOD_ID, updated_vod_settings)

    assert_equal(
        deep_get(
            api.internal_get(context['partner']['id'], VOD_ID).json(),
            'adSettings.freeUsersOnly'), True,
        'internal_get after update of freeUsersOnly')

    response = api.public_get(VOD_ID,
                              context['partner'],
                              user_token=context['user_token'])
    assert_equal(response.status_code, 404,
                 'status_code after setting freeUsersOnly=true')
Ejemplo n.º 6
0
def test_user_with_missing_age_gender():
    empty_user_info = {}
    user_api.set_dynamic(context['user_id'], context['clientApiToken'],
                         context['user_token'], empty_user_info)
    data = api.public_get(VOD_ID,
                          context['partner'],
                          user_token=context['user_token']).json()
    api_url = urlparse(deep_get(data, 'preroll'))
    url = urlparse(parse_qs(api_url.query)['vastUrl'][0])
    assert_equal(api_url.hostname,
                 urlparse(config.api_global_url()).hostname,
                 'api url hostname')
    query = parse_qs(url.query)
    expected_url = urlparse(deep_get(VOD_SETTINGS, 'preroll.mobile'))
    assert_equal(url.scheme, expected_url.scheme, 'url scheme')
    assert_equal(url.hostname, expected_url.hostname, 'url hostname')
    expected_query = {'user[yob]': None, 'user[gender]': None}
    for param in expected_query:
        assert_equal(deep_get(query, [param, 0]), expected_query[param],
                     'expected param %s' % param)
Ejemplo n.º 7
0
def test_no_default_404():
    partner_id = context['partner']['id']
    api.internal_defaults_delete(partner_id)
    response = api.public_get(NON_EXISTANT_ID, context['partner'])
    assert_equal(response.status_code, 404, 'status_code')
Ejemplo n.º 8
0
def test_device_type_other():
    data = api.public_get(VOD_ID, context['partner'],
                          device_type='foobar').json()
    assert_equal(deep_get(data, 'preroll'),
                 deep_get(VOD_SETTINGS, 'preroll.mobile'), 'preroll_url')
Ejemplo n.º 9
0
def test_override():
    data = api.public_get(VOD_ID, context['partner']).json()
    assert_equal(deep_get(data, 'preroll'),
                 deep_get(VOD_SETTINGS, 'preroll.mobile'), 'preroll_url')