Пример #1
0
class BaseActionTestCase(BaseTestCase):

    def setUp(self):
        super(BaseActionTestCase, self).setUp()
        self.base = RbxBaseAction(None, {'timeout': '10',
                                         'endpoint': 'http://mock',
                                         'version': '4.2'}, None, None, False)

    def test_request_timeout_is_set_if_not(self):
        ret = self.base._set_request_timeout({})
        assert ret == {'timeout': 10}

    def test_request_timeout_left_untouched_if_set(self):
        ret = self.base._set_request_timeout({'timeout': 40})
        assert ret == {'timeout': 40}

    def test_raise_for_status_return_api_error_exception(self):
        class FakeRequestsResponse:
            status_code = 403

            def raise_for_status(self):
                raise HTTPError('Message')

            def json(self):
                return {'message': 'Something'}

        with pytest.raises(APIError) as excinfo:
            self.base._raise_for_status(FakeRequestsResponse())
        assert excinfo.errisinstance(APIError)

    def test_request_method_called(self):
        def my_method(path, **kwargs):
            assert '/foo/bar' in path
            assert 'timeout' in kwargs

        self.base.my_method = my_method
        self.base.req('my_method', '/foo/bar')

    def test_url_marking(self):
        url = self.base.make_url('/foo/bar')
        assert url == 'http://mock/v4.2/foo/bar'

    def test_result_can_return_json(self):
        class FakeRequestsResponse:
            def raise_for_status(self):
                pass

            def json(self):
                return {'foo': 'bar'}

        result = self.base.result(FakeRequestsResponse(), True)
        assert result == {'foo': 'bar'}

    def test_result_can_return_raw_text(self):
        class FakeRequestsResponse:
            text = 'My test'

            def raise_for_status(self):
                pass

        result = self.base.result(FakeRequestsResponse())
        assert result == 'My test'
Пример #2
0
 def setUp(self):
     super(BaseActionTestCase, self).setUp()
     self.base = RbxBaseAction(None, {'timeout': '10',
                                      'endpoint': 'http://mock',
                                      'version': '4.2'}, None, None, False)