コード例 #1
0
def test_call_recommendation_server_parameters(requests_get):
    taar_url = settings.RECOMMENDATION_ENGINE_URL
    taar_timeout = settings.RECOMMENDATION_ENGINE_TIMEOUT
    requests_get.return_value = HttpResponse(
        json.dumps({'results': ['@lolwut']}))
    # No locale or platform
    call_recommendation_server('123456', {}, taar_url)
    requests_get.assert_called_with(taar_url + '123456/', timeout=taar_timeout)
    # locale no platform
    call_recommendation_server('123456', {'locale': 'en-US'}, taar_url)
    requests_get.assert_called_with(
        taar_url + '123456/?locale=en-US', timeout=taar_timeout)
    # platform no locale
    call_recommendation_server('123456', {'platform': 'WINNT'}, taar_url)
    requests_get.assert_called_with(
        taar_url + '123456/?platform=WINNT', timeout=taar_timeout)
    # both locale and platform
    call_recommendation_server(
        '123456', {'locale': 'en-US', 'platform': 'WINNT'}, taar_url)
    requests_get.assert_called_with(
        taar_url + '123456/?locale=en-US&platform=WINNT', timeout=taar_timeout)
    # and some extra parameters
    call_recommendation_server(
        '123456',
        {'locale': 'en-US', 'platform': 'WINNT', 'study': 'sch',
         'branch': 'tree'},
        settings.RECOMMENDATION_ENGINE_URL)
    requests_get.assert_called_with(
        taar_url + '123456/?branch=tree&locale=en-US&platform=WINNT&study=sch',
        timeout=taar_timeout)
コード例 #2
0
def test_call_recommendation_server_parameters(requests_get):
    taar_url = settings.RECOMMENDATION_ENGINE_URL
    taar_timeout = settings.RECOMMENDATION_ENGINE_TIMEOUT
    requests_get.return_value = HttpResponse(
        json.dumps({'results': ['@lolwut']}))
    # No locale or platform
    call_recommendation_server('123456', {})
    requests_get.assert_called_with(taar_url + '123456/', timeout=taar_timeout)
    # locale no platform
    call_recommendation_server('123456', {'locale': 'en-US'})
    requests_get.assert_called_with(taar_url + '123456/?locale=en-US',
                                    timeout=taar_timeout)
    # platform no locale
    call_recommendation_server('123456', {'platform': 'WINNT'})
    requests_get.assert_called_with(taar_url + '123456/?platform=WINNT',
                                    timeout=taar_timeout)
    # both locale and platform
    call_recommendation_server('123456', {
        'locale': 'en-US',
        'platform': 'WINNT'
    })
    requests_get.assert_called_with(taar_url +
                                    '123456/?locale=en-US&platform=WINNT',
                                    timeout=taar_timeout)
    # and some extra parameters
    call_recommendation_server('123456', {
        'locale': 'en-US',
        'platform': 'WINNT',
        'study': 'sch',
        'branch': 'tree'
    })
    requests_get.assert_called_with(
        taar_url + '123456/?branch=tree&locale=en-US&platform=WINNT&study=sch',
        timeout=taar_timeout)
コード例 #3
0
ファイル: test_utils.py プロジェクト: st333v/addons-server
def test_call_recommendation_server_no_parameters(requests_get, requests_post):
    url = settings.RECOMMENDATION_ENGINE_URL
    taar_timeout = settings.RECOMMENDATION_ENGINE_TIMEOUT
    requests_get.return_value = HttpResponse(json.dumps({'results': ['@lolwut']}))
    # No parameters
    call_recommendation_server(url, '123456', {})
    requests_get.assert_called_with(url + '123456/', timeout=taar_timeout)
    assert not requests_post.called
コード例 #4
0
ファイル: test_utils.py プロジェクト: iamVP7/addons-server
def test_call_recommendation_server_no_parameters(requests_get, requests_post):
    url = settings.RECOMMENDATION_ENGINE_URL
    taar_timeout = settings.RECOMMENDATION_ENGINE_TIMEOUT
    requests_get.return_value = HttpResponse(
        json.dumps({'results': ['@lolwut']}))
    # No parameters
    call_recommendation_server(url, '123456', {})
    requests_get.assert_called_with(url + '123456/', timeout=taar_timeout)
    assert not requests_post.called
コード例 #5
0
ファイル: test_utils.py プロジェクト: st333v/addons-server
def test_call_recommendation_server_post_no_parameters(requests_get, requests_post):
    url = 'http://example.com/taar_is_awesome/'
    taar_timeout = settings.RECOMMENDATION_ENGINE_TIMEOUT
    requests_get.return_value = HttpResponse(json.dumps({'results': ['@lolwut']}))
    call_recommendation_server(url, '4815162342', None, verb='post')
    assert not requests_get.called
    requests_post.assert_called_with(
        url + '4815162342/', json=None, timeout=taar_timeout
    )
コード例 #6
0
ファイル: test_utils.py プロジェクト: st333v/addons-server
def test_call_recommendation_server_some_parameters(requests_get, requests_post):
    url = 'http://example.com/whatever/'
    taar_timeout = settings.RECOMMENDATION_ENGINE_TIMEOUT
    requests_get.return_value = HttpResponse(json.dumps({'results': ['@lolwut']}))
    data = {'some': 'params', 'and': 'more'}
    call_recommendation_server(url, '123456', data)
    requests_get.assert_called_with(
        url + '123456/?and=more&some=params', timeout=taar_timeout
    )
    assert not requests_post.called
コード例 #7
0
ファイル: test_utils.py プロジェクト: iamVP7/addons-server
def test_call_recommendation_server_post_no_parameters(
        requests_get, requests_post):
    url = 'http://example.com/taar_is_awesome/'
    taar_timeout = settings.RECOMMENDATION_ENGINE_TIMEOUT
    requests_get.return_value = HttpResponse(
        json.dumps({'results': ['@lolwut']}))
    call_recommendation_server(url, '4815162342', None, verb='post')
    assert not requests_get.called
    requests_post.assert_called_with(
        url + '4815162342/', json=None, timeout=taar_timeout)
コード例 #8
0
ファイル: test_utils.py プロジェクト: iamVP7/addons-server
def test_call_recommendation_server_some_parameters(
        requests_get, requests_post):
    url = 'http://example.com/whatever/'
    taar_timeout = settings.RECOMMENDATION_ENGINE_TIMEOUT
    requests_get.return_value = HttpResponse(
        json.dumps({'results': ['@lolwut']}))
    data = {'some': 'params', 'and': 'more'}
    call_recommendation_server(url, '123456', data)
    requests_get.assert_called_with(
        url + '123456/?and=more&some=params', timeout=taar_timeout)
    assert not requests_post.called
コード例 #9
0
ファイル: test_utils.py プロジェクト: st333v/addons-server
def test_call_recommendation_server_fails_nice(requests_get, statsd_incr):
    requests_get.side_effect = requests.exceptions.RequestException()
    # Check the exception in requests.get is handled okay.
    assert (
        call_recommendation_server(settings.RECOMMENDATION_ENGINE_URL, '123456', {})
        is None
    )
    statsd_incr.assert_called_with('services.recommendations.fail')
コード例 #10
0
ファイル: test_utils.py プロジェクト: st333v/addons-server
def test_call_recommendation_server_get_parameter_is_an_url(
    requests_get, requests_post
):
    url = 'http://example.com/taar_is_awesome/'
    requests_get.return_value = HttpResponse(json.dumps({'results': []}))

    assert call_recommendation_server(url, 'http://evil.com', {}, verb='get') is None
    assert not requests_get.called
    assert not requests_post.called

    assert call_recommendation_server(url, 'http://evil.com/', {}, verb='get') is None
    assert not requests_get.called
    assert not requests_post.called

    assert call_recommendation_server(url, 'http://[evil.com/', {}, verb='get') is None
    assert not requests_get.called
    assert not requests_post.called

    assert (
        call_recommendation_server(url, 'http://evil.com/foo', {}, verb='get') is None
    )
    assert not requests_get.called
    assert not requests_post.called

    assert call_recommendation_server(url, '/foo', {}, verb='get') is None
    assert not requests_get.called
    assert not requests_post.called

    assert call_recommendation_server(url, '//foo', {}, verb='get') is None
    assert not requests_get.called
    assert not requests_post.called
コード例 #11
0
ファイル: utils.py プロジェクト: diox/olympia
def get_addon_recommendations(guid_param, taar_enable):
    guids = None
    fail_reason = None
    if taar_enable:
        guids = call_recommendation_server(
            settings.TAAR_LITE_RECOMMENDATION_ENGINE_URL, guid_param, {})
        outcome = (TAAR_LITE_OUTCOME_REAL_SUCCESS if guids
                   else TAAR_LITE_OUTCOME_REAL_FAIL)
        if not guids:
            fail_reason = (TAAR_LITE_FALLBACK_REASON_EMPTY if guids == []
                           else TAAR_LITE_FALLBACK_REASON_TIMEOUT)
    else:
        outcome = TAAR_LITE_OUTCOME_CURATED
    if not guids:
        guids = TAAR_LITE_FALLBACKS
    return guids, outcome, fail_reason
コード例 #12
0
def get_addon_recommendations(guid_param, taar_enable):
    guids = None
    fail_reason = None
    if taar_enable:
        guids = call_recommendation_server(
            guid_param, {}, settings.TAAR_LITE_RECOMMENDATION_ENGINE_URL)
        outcome = (TAAR_LITE_OUTCOME_REAL_SUCCESS
                   if guids else TAAR_LITE_OUTCOME_REAL_FAIL)
        if not guids:
            fail_reason = (TAAR_LITE_FALLBACK_REASON_EMPTY if guids == [] else
                           TAAR_LITE_FALLBACK_REASON_TIMEOUT)
    else:
        outcome = TAAR_LITE_OUTCOME_CURATED
    if not guids:
        guids = TAAR_LITE_FALLBACKS
    return guids, outcome, fail_reason
コード例 #13
0
ファイル: test_utils.py プロジェクト: tsl143/addons-server
def test_call_recommendation_server_parameters(requests_get):
    taar_url = settings.RECOMMENDATION_ENGINE_URL
    taar_timeout = settings.RECOMMENDATION_ENGINE_TIMEOUT
    requests_get.return_value = HttpResponse(
        json.dumps({'results': ['@lolwut']}))
    # No locale or platform
    call_recommendation_server('123456', None, None)
    requests_get.assert_called_with(taar_url + '123456/', timeout=taar_timeout)
    # locale no platform
    call_recommendation_server('123456', 'en-US', None)
    requests_get.assert_called_with(
        taar_url + '123456/?locale=en-US', timeout=taar_timeout)
    # platform no locale
    call_recommendation_server('123456', None, 'WINNT')
    requests_get.assert_called_with(
        taar_url + '123456/?platform=WINNT', timeout=taar_timeout)
    # both locale and platform
    call_recommendation_server('123456', 'en-US', 'WINNT')
    requests_get.assert_called_with(
        taar_url + '123456/?locale=en-US&platform=WINNT', timeout=taar_timeout)
コード例 #14
0
def test_call_recommendation_server_parameters(requests_get):
    taar_url = settings.RECOMMENDATION_ENGINE_URL
    taar_timeout = settings.RECOMMENDATION_ENGINE_TIMEOUT
    requests_get.return_value = HttpResponse(
        json.dumps({'results': ['@lolwut']}))
    # No locale or platform
    call_recommendation_server('123456', None, None)
    requests_get.assert_called_with(taar_url + '123456/', timeout=taar_timeout)
    # locale no platform
    call_recommendation_server('123456', 'en-US', None)
    requests_get.assert_called_with(taar_url + '123456/?locale=en-US',
                                    timeout=taar_timeout)
    # platform no locale
    call_recommendation_server('123456', None, 'WINNT')
    requests_get.assert_called_with(taar_url + '123456/?platform=WINNT',
                                    timeout=taar_timeout)
    # both locale and platform
    call_recommendation_server('123456', 'en-US', 'WINNT')
    requests_get.assert_called_with(taar_url +
                                    '123456/?locale=en-US&platform=WINNT',
                                    timeout=taar_timeout)
コード例 #15
0
def test_call_recommendation_server_fails_nice(requests_post):
    requests_post.side_effect = requests.exceptions.RequestException()
    # Check the exception in requests.post is handled okay.
    assert call_recommendation_server('123456') == []
コード例 #16
0
def test_call_recommendation_server_succeeds(requests_get, statsd_incr):
    requests_get.return_value = HttpResponse(
        json.dumps({'results': ['@lolwut']}))
    assert call_recommendation_server(settings.RECOMMENDATION_ENGINE_URL,
                                      '123456', {}) == ['@lolwut']
    statsd_incr.assert_called_with('services.recommendations.success')
コード例 #17
0
ファイル: test_utils.py プロジェクト: tsl143/addons-server
def test_call_recommendation_server_succeeds(requests_get, statsd_incr):
    requests_get.return_value = HttpResponse(
        json.dumps({'results': ['@lolwut']}))
    assert call_recommendation_server('123456', None, None) == ['@lolwut']
    statsd_incr.assert_called_with('services.recommendations.success')
コード例 #18
0
ファイル: test_utils.py プロジェクト: iamVP7/addons-server
def test_call_recommendation_server_succeeds(requests_get, statsd_incr):
    requests_get.return_value = HttpResponse(
        json.dumps({'results': ['@lolwut']}))
    assert call_recommendation_server(
        settings.RECOMMENDATION_ENGINE_URL, '123456', {}) == ['@lolwut']
    statsd_incr.assert_called_with('services.recommendations.success')
コード例 #19
0
ファイル: test_utils.py プロジェクト: iamVP7/addons-server
def test_call_recommendation_server_fails_nice(requests_get, statsd_incr):
    requests_get.side_effect = requests.exceptions.RequestException()
    # Check the exception in requests.get is handled okay.
    assert call_recommendation_server(
        settings.RECOMMENDATION_ENGINE_URL, '123456', {}) is None
    statsd_incr.assert_called_with('services.recommendations.fail')
コード例 #20
0
def test_call_recommendation_server_succeeds(requests_get, statsd_incr):
    requests_get.return_value = HttpResponse(
        json.dumps({'results': ['@lolwut']}))
    assert call_recommendation_server('123456') == ['@lolwut']
    assert statsd_incr.called_with('services.recommendations.succeed')
コード例 #21
0
def test_call_recommendation_server_fails_nice(requests_get, statsd_incr):
    requests_get.side_effect = requests.exceptions.RequestException()
    # Check the exception in requests.get is handled okay.
    assert call_recommendation_server('123456', {}) == []
    statsd_incr.assert_called_with('services.recommendations.fail')
コード例 #22
0
ファイル: test_utils.py プロジェクト: tsl143/addons-server
def test_call_recommendation_server_fails_nice(requests_get, statsd_incr):
    requests_get.side_effect = requests.exceptions.RequestException()
    # Check the exception in requests.get is handled okay.
    assert call_recommendation_server('123456', None, None) == []
    statsd_incr.assert_called_with('services.recommendations.fail')