Exemplo n.º 1
0
 def test_call_static(self, service):
     """
     Test calling a ``StubEndpoint`` with a static response
     """
     service.stub_endpoint = apiron.StubEndpoint(
         stub_response="stub response")
     actual_response = service.stub_endpoint()
     expected_response = "stub response"
     assert actual_response == expected_response
Exemplo n.º 2
0
        def _test_case(call_kwargs, expected_response):
            def stub_response(**kwargs):
                if kwargs.get("params") and kwargs["params"].get(
                        "param_key") == "param_value":
                    return {"stub response": "for param_key=param_value"}
                else:
                    return {"default": "response"}

            service.stub_endpoint = apiron.StubEndpoint(
                stub_response=stub_response)
            actual_response = service.stub_endpoint(**call_kwargs)
            assert actual_response == expected_response
Exemplo n.º 3
0
        def _test_case(call_kwargs, expected_response):
            def stub_response(**kwargs):
                if kwargs.get('params') and kwargs['params'].get(
                        'param_key') == 'param_value':
                    return {'stub response': 'for param_key=param_value'}
                else:
                    return {'default': 'response'}

            service.stub_endpoint = apiron.StubEndpoint(
                stub_response=stub_response)
            actual_response = service.stub_endpoint(**call_kwargs)
            assert actual_response == expected_response
Exemplo n.º 4
0
 def test_extra_params(self):
     """
     Test initializing a stub endpoint with extra params
     """
     stub_endpoint = apiron.StubEndpoint(
         stub_response="stub response",
         path="/some/path/",
         default_params={"param_name": "param_val"},
         required_params={"param_name"},
         arbitrary_kwarg="foo",
     )
     expected_params = {
         "path": "/some/path/",
         "default_params": {
             "param_name": "param_val"
         },
         "required_params": {"param_name"},
         "arbitrary_kwarg": "foo",
     }
     assert expected_params == stub_endpoint.endpoint_params
Exemplo n.º 5
0
 def test_extra_params(self):
     """
     Test initializing a stub endpoint with extra params
     """
     stub_endpoint = apiron.StubEndpoint(
         stub_response='stub response',
         path='/some/path/',
         default_params={'param_name': 'param_val'},
         required_params={'param_name'},
         arbitrary_kwarg='foo',
     )
     expected_params = {
         'path': '/some/path/',
         'default_params': {
             'param_name': 'param_val'
         },
         'required_params': {'param_name'},
         'arbitrary_kwarg': 'foo',
     }
     assert expected_params == stub_endpoint.endpoint_params
Exemplo n.º 6
0
 def test_call_without_service_raises_exception(self):
     stub_endpoint = apiron.StubEndpoint(stub_response="foo")
     with pytest.raises(TypeError):
         stub_endpoint()
Exemplo n.º 7
0
 def test_stub_response(self):
     """
     Test initializing a stub endpoint with a stub response
     """
     stub_endpoint = apiron.StubEndpoint(stub_response="stub response")
     assert "stub response" == stub_endpoint.stub_response
Exemplo n.º 8
0
 def test_repr_method(self):
     foo = apiron.StubEndpoint(path="/bar/baz")
     assert repr(foo) == "StubEndpoint(path='/bar/baz')"
Exemplo n.º 9
0
 def test_str_method(self):
     foo = apiron.StubEndpoint(path="/bar/baz")
     assert str(foo) == "/bar/baz"
Exemplo n.º 10
0
 def test_call_dynamic(self, test_call_kwargs, expected_response, service, stub_function):
     service.stub_endpoint = apiron.StubEndpoint(stub_response=stub_function)
     actual_response = service.stub_endpoint(**test_call_kwargs)
     assert actual_response == expected_response
Exemplo n.º 11
0
 def test_call_static(self, service):
     service.stub_endpoint = apiron.StubEndpoint(stub_response="stub response")
     assert service.stub_endpoint() == "stub response"
Exemplo n.º 12
0
 def test_stub_default_response(self, service):
     service.stub_endpoint = apiron.StubEndpoint()
     assert service.stub_endpoint() == {"response": "StubEndpoint(path='/')"}