def test_raises_warning_on_not_the_newest_api_version(api):
    response = Response()
    newest_version = 'v{}'.format(int(API_VERSION.strip('v')) + 1)
    response.status_code = 200
    response.headers['X-Current-Api-Version'] = newest_version

    with warns(Warning) as cm:
        api._validate_response(response)  # pylint: disable=protected-access

    msg = 'Used api version ({}) is outdated, use newest version ({}) by updating ' \
        'rtbhouse_sdk package.'.format(API_VERSION, newest_version)
    assert str(cm[0].message) == msg
示例#2
0
    def test_raises_warning_on_not_the_newest_api_version(self):
        response = Response()
        newest_version = 'v{}'.format(int(API_VERSION.strip('v')) + 1)
        response.status_code = 200
        response.headers['X-Current-Api-Version'] = newest_version

        with self.assertWarns(Warning) as cm:
            self.api._validate_response(response)

        msg = 'Used api version ({}) is outdated, use newest version ({}) by updating ' \
            'rtbhouse_sdk package.'.format(API_VERSION, newest_version)
        self.assertEqual(str(cm.warning), msg)
def test_raise_error_on_too_old_api_version(api):
    response = Response()
    newest_version = 'v{}'.format(int(API_VERSION.strip('v')) + 2)
    response.status_code = 410
    response.headers['X-Current-Api-Version'] = newest_version

    with raises(ReportsApiException) as cm:
        api._validate_response(response)  # pylint: disable=protected-access

    msg = 'Unsupported api version ({}), use newest version ({}) by updating rtbhouse_sdk package.' \
        .format(API_VERSION, newest_version)
    assert cm.value.message == msg
示例#4
0
    def test_raise_error_on_too_old_api_version(self):
        response = Response()
        newest_version = 'v{}'.format(int(API_VERSION.strip('v')) + 2)
        response.status_code = 410
        response.headers['X-Current-Api-Version'] = newest_version

        with self.assertRaises(ReportsApiException) as cm:
            self.api._validate_response(response)

        msg = 'Unsupported api version ({}), use newest version ({}) by updating rtbhouse_sdk package.' \
            .format(API_VERSION, newest_version)
        self.assertEqual(cm.exception.message, msg)