Exemplo n.º 1
0
 def test_get_merged_params(self):
     foo = apiron.JsonEndpoint(default_params={'foo': 'bar'},
                               required_params={'baz'})
     assert {
         'foo': 'bar',
         'baz': 'qux'
     } == foo.get_merged_params({'baz': 'qux'})
Exemplo n.º 2
0
 def test_get_merged_params(self):
     foo = apiron.JsonEndpoint(default_params={"foo": "bar"},
                               required_params={"baz"})
     assert {
         "foo": "bar",
         "baz": "qux"
     } == foo.get_merged_params({"baz": "qux"})
Exemplo n.º 3
0
    def test_format_response_when_unordered(self):
        foo = apiron.JsonEndpoint()
        mock_response = mock.Mock()

        with mock.patch.object(mock_response, "json") as mock_json:
            mock_json.return_value = {"foo": "bar"}
            assert {"foo": "bar"} == foo.format_response(mock_response)
            mock_json.assert_called_once_with(object_pairs_hook=None)
Exemplo n.º 4
0
 def test_get_merged_params_with_empty_param(self):
     foo = apiron.JsonEndpoint(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})
Exemplo n.º 5
0
    def test_format_response_when_ordered(self):
        foo = apiron.JsonEndpoint(preserve_order=True)
        mock_response = mock.Mock()

        with mock.patch.object(mock_response, 'json') as mock_json:
            mock_json.return_value = {'foo': 'bar'}
            assert {'foo': 'bar'} == foo.format_response(mock_response)
            mock_json.assert_called_once_with(
                object_pairs_hook=collections.OrderedDict)
Exemplo n.º 6
0
    def test_get_merged_params_with_empty_param(self):
        foo = apiron.JsonEndpoint(default_params={'foo': 'bar'},
                                  required_params={'baz'})

        with warnings.catch_warnings(record=True) as warning_records:
            warnings.simplefilter('always')
            assert {
                'foo': 'bar',
                'baz': None
            } == foo.get_merged_params({'baz': None})
            assert 1 == len(warning_records)
            assert issubclass(warning_records[-1].category, RuntimeWarning)
Exemplo n.º 7
0
    def test_get_merged_params_with_unsupplied_param(self):
        foo = apiron.JsonEndpoint(default_params={"foo": "bar"},
                                  required_params={"baz"})

        with pytest.raises(apiron.UnfulfilledParameterException):
            foo.get_merged_params()
Exemplo n.º 8
0
 def test_required_headers(self):
     foo = apiron.JsonEndpoint()
     assert {"Accept": "application/json"} == foo.required_headers
Exemplo n.º 9
0
 def test_get_merged_params_with_required_and_default_param(self):
     foo = apiron.JsonEndpoint(default_params={"foo": "bar"},
                               required_params={"foo"})
     assert {"foo": "bar"} == foo.get_merged_params()
Exemplo n.º 10
0
 def test_repr_method(self):
     foo = apiron.JsonEndpoint(path="/bar/baz")
     assert repr(foo) == "JsonEndpoint(path='/bar/baz')"
Exemplo n.º 11
0
 def test_str_method(self):
     foo = apiron.JsonEndpoint(path="/bar/baz")
     assert str(foo) == "/bar/baz"
Exemplo n.º 12
0
 def test_required_headers(self):
     foo = apiron.JsonEndpoint()
     assert {'Accept': 'application/json'} == foo.required_headers
Exemplo n.º 13
0
 def test_get_merged_params_with_required_and_default_param(self):
     foo = apiron.JsonEndpoint(default_params={'foo': 'bar'},
                               required_params={'foo'})
     assert {'foo': 'bar'} == foo.get_merged_params()