示例#1
0
 def test_format_path_with_incorrect_kwargs(self):
     foo = apiron.Endpoint(path="/{one}/{two}/")
     path_kwargs = {"foo": "bar"}
     with pytest.warns(RuntimeWarning,
                       match="An unknown path kwarg was supplied"):
         with pytest.raises(KeyError):
             foo.get_formatted_path(**path_kwargs)
示例#2
0
 def test_using_path_kwargs_produces_warning(self, mock_send, service):
     service.foo = apiron.Endpoint(path='/foo/{one}')
     with warnings.catch_warnings(record=True) as warning_records:
         warnings.simplefilter('always')
         _ = service.foo(path_kwargs={'one': 'bar'})
         assert 1 == len(warning_records)
         assert issubclass(warning_records[-1].category, RuntimeWarning)
示例#3
0
 def test_format_path_with_extra_kwargs(self):
     foo = apiron.Endpoint(path='/{one}/{two}/')
     path_kwargs = {'one': 'foo', 'two': 'bar', 'three': 'not used'}
     with warnings.catch_warnings(record=True) as warning_records:
         assert '/foo/bar/' == foo.get_formatted_path(**path_kwargs)
         assert 1 == len(warning_records)
         assert issubclass(warning_records[-1].category, RuntimeWarning)
示例#4
0
 def test_format_path_with_incorrect_kwargs(self):
     foo = apiron.Endpoint(path='/{one}/{two}/')
     path_kwargs = {'foo': 'bar'}
     with pytest.raises(KeyError):
         with warnings.catch_warnings(record=True) as warning_records:
             warnings.simplefilter('always')
             foo.get_formatted_path(**path_kwargs)
         assert 1 == len(warning_records)
         assert issubclass(warning_records[-1].category, RuntimeWarning)
示例#5
0
    def test_legacy_endpoint_usage_with_instantiated_service(
            self, MockSession, mock_timeout, service):
        service.foo = apiron.Endpoint(path="/foo/")
        instantiated_service = service()

        mock_logger = mock.Mock()
        request = mock.Mock()
        request.url = "http://host1.biz/foo/"

        ServiceCaller.call(instantiated_service,
                           instantiated_service.foo,
                           timeout_spec=mock_timeout,
                           logger=mock_logger)
示例#6
0
 def test_call(self, service):
     service.foo = apiron.Endpoint()
     service.foo()
示例#7
0
 def test_path_placeholders_when_present(self):
     foo = apiron.Endpoint(path='/foo/{one}/{two}')
     assert ['one', 'two'] == foo.path_placeholders
示例#8
0
 def test_format_path_with_correct_kwargs(self):
     foo = apiron.Endpoint(path="/{one}/{two}/")
     path_kwargs = {"one": "foo", "two": "bar"}
     assert "/foo/bar/" == foo.get_formatted_path(**path_kwargs)
示例#9
0
 def test_path_placeholders_when_none_present(self):
     foo = apiron.Endpoint()
     assert [] == foo.path_placeholders
示例#10
0
 def test_required_headers(self):
     foo = apiron.Endpoint()
     assert {} == foo.required_headers
示例#11
0
 def test_constructor_stores_passed_attributes(self):
     foo = apiron.Endpoint(path="/foo/", default_method="POST")
     assert "/foo/" == foo.path
     assert "POST" == foo.default_method
示例#12
0
 def test_str_method(self):
     foo = apiron.Endpoint(path="/bar/baz")
     assert str(foo) == "/bar/baz"
示例#13
0
 def test_get_merged_params_with_required_and_default_param(self):
     foo = apiron.Endpoint(default_params={"foo": "bar"}, required_params={"foo"})
     assert {"foo": "bar"} == foo.get_merged_params()
示例#14
0
 def test_query_parameter_in_path_generates_warning(self):
     with warnings.catch_warnings(record=True) as warning_records:
         warnings.simplefilter('always')
         _ = apiron.Endpoint(path='/?foo=bar')
         assert 1 == len(warning_records)
         assert issubclass(warning_records[-1].category, UserWarning)
示例#15
0
 def test_format_path_with_correct_kwargs(self):
     foo = apiron.Endpoint(path='/{one}/{two}/')
     path_kwargs = {'one': 'foo', 'two': 'bar'}
     assert '/foo/bar/' == foo.get_formatted_path(**path_kwargs)
示例#16
0
 def test_call_without_service_raises_exception(self):
     foo = apiron.Endpoint()
     with pytest.raises(TypeError):
         foo()
示例#17
0
 def test_repr_method(self):
     foo = apiron.Endpoint(path="/bar/baz")
     assert repr(foo) == "Endpoint(path='/bar/baz')"
示例#18
0
 def test_default_attributes_from_constructor(self):
     foo = apiron.Endpoint()
     assert "/" == foo.path
     assert "GET" == foo.default_method
示例#19
0
 def test_get_merged_params(self):
     foo = apiron.Endpoint(default_params={"foo": "bar"}, required_params={"baz"})
     assert {"foo": "bar", "baz": "qux"} == foo.get_merged_params({"baz": "qux"})
示例#20
0
 def test_format_response(self):
     foo = apiron.Endpoint()
     mock_response = mock.Mock()
     mock_response.text = "foobar"
     assert "foobar" == foo.format_response(mock_response)
示例#21
0
    def test_get_merged_params_with_unsupplied_param(self):
        foo = apiron.Endpoint(default_params={"foo": "bar"}, required_params={"baz"})

        with pytest.raises(apiron.UnfulfilledParameterException):
            foo.get_merged_params()
示例#22
0
 def test_str_method(self):
     foo = apiron.Endpoint(path="/foo/bar/")
     assert "/foo/bar/" == str(foo)
示例#23
0
 def test_format_path_with_extra_kwargs(self):
     foo = apiron.Endpoint(path="/{one}/{two}/")
     path_kwargs = {"one": "foo", "two": "bar", "three": "not used"}
     with pytest.warns(RuntimeWarning,
                       match="An unknown path kwarg was supplied"):
         assert "/foo/bar/" == foo.get_formatted_path(**path_kwargs)
示例#24
0
 def test_path_placeholders_when_present(self):
     foo = apiron.Endpoint(path="/foo/{one}/{two}")
     assert ["one", "two"] == foo.path_placeholders
示例#25
0
 def test_constructor_stores_passed_attributes(self):
     foo = apiron.Endpoint(path='/foo/', default_method='POST')
     assert '/foo/' == foo.path
     assert 'POST' == foo.default_method
示例#26
0
 def test_get_merged_params_with_empty_param(self):
     foo = apiron.Endpoint(default_params={"foo": "bar"}, required_params={"baz"})
     with pytest.warns(RuntimeWarning, match="endpoint was called with empty parameters"):
         assert {"foo": "bar", "baz": None} == foo.get_merged_params({"baz": None})
示例#27
0
 def test_str_method(self):
     foo = apiron.Endpoint(path='/foo/bar/')
     assert '/foo/bar/' == str(foo)
示例#28
0
 def test_query_parameter_in_path_generates_warning(self):
     with pytest.warns(UserWarning,
                       match="Endpoint path may contain query parameters"):
         _ = apiron.Endpoint(path="/?foo=bar")
示例#29
0
 def test_using_path_kwargs_produces_warning(self, mock_send, service):
     service.foo = apiron.Endpoint(path="/foo/{one}")
     with pytest.warns(RuntimeWarning,
                       match="path_kwargs is no longer necessary"):
         _ = service.foo(path_kwargs={"one": "bar"})