def test_query_parameter_in_path_generates_warning(self): with warnings.catch_warnings(record=True) as warning_records: warnings.simplefilter('always') foo = endpoint.Endpoint(path='/?foo=bar') self.assertEqual(1, len(warning_records)) self.assertTrue( issubclass(warning_records[-1].category, UserWarning))
def test_path_when_doesnt_end_with_slash_and_check_is_on(self): with warnings.catch_warnings(record=True) as warning_records: warnings.simplefilter('always') foo = endpoint.Endpoint(path='/foo') self.assertEqual(1, len(warning_records)) self.assertTrue(issubclass(warning_records[-1].category, UserWarning)) self.assertEqual('/foo', foo.path)
def test_format_path_with_extra_kwargs(self): foo = endpoint.Endpoint(path='/{one}/{two}/') path_kwargs = {'one': 'foo', 'two': 'bar', 'three': 'not used'} self.assertEqual('/foo/bar/', foo.get_formatted_path(**path_kwargs))
def test_format_path_with_correct_kwargs(self): foo = endpoint.Endpoint(path='/{one}/{two}/') path_kwargs = {'one': 'foo', 'two': 'bar'} assert '/foo/bar/' == foo.get_formatted_path(**path_kwargs)
def test_str_method(self): foo = endpoint.Endpoint(path='/foo/bar/') self.assertEqual('/foo/bar/', str(foo))
def test_format_path_with_incorrect_kwargs(self): foo = endpoint.Endpoint(path='/{one}/{two}/') path_kwargs = {'foo': 'bar'} with self.assertRaises(KeyError): foo.get_formatted_path(**path_kwargs)
def test_format_response(self): foo = endpoint.Endpoint() mock_response = mock.Mock() mock_response.text = 'foobar' self.assertEqual('foobar', foo.format_response(mock_response))
def test_required_headers(self): foo = endpoint.Endpoint() self.assertDictEqual({}, foo.required_headers)
def test_default_attributes_from_constructor(self): foo = endpoint.Endpoint() self.assertEqual('/', foo.path) self.assertEqual('GET', foo.default_method)
def test_constructor_stores_passed_attributes(self): foo = endpoint.Endpoint(path='/foo/', default_method='POST') self.assertEqual('/foo/', foo.path) self.assertEqual('POST', foo.default_method)
def test_str_method(self): foo = endpoint.Endpoint(path='/foo/bar/') assert '/foo/bar/' == str(foo)
def test_call(self, service): service.foo = endpoint.Endpoint() service.foo()
def test_required_headers(self): foo = endpoint.Endpoint() assert {} == foo.required_headers
def test_format_response(self): foo = endpoint.Endpoint() mock_response = mock.Mock() mock_response.text = 'foobar' assert 'foobar' == foo.format_response(mock_response)
def test_constructor_stores_passed_attributes(self): foo = endpoint.Endpoint(path='/foo/', default_method='POST') assert '/foo/' == foo.path assert 'POST' == foo.default_method
def test_default_attributes_from_constructor(self): foo = endpoint.Endpoint() assert '/' == foo.path assert 'GET' == foo.default_method
def test_call_without_service_raises_exception(self): foo = endpoint.Endpoint() with pytest.raises(TypeError): foo()