예제 #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
예제 #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
예제 #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
예제 #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
예제 #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
예제 #6
0
 def test_call_without_service_raises_exception(self):
     stub_endpoint = apiron.StubEndpoint(stub_response="foo")
     with pytest.raises(TypeError):
         stub_endpoint()
예제 #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
예제 #8
0
 def test_repr_method(self):
     foo = apiron.StubEndpoint(path="/bar/baz")
     assert repr(foo) == "StubEndpoint(path='/bar/baz')"
예제 #9
0
 def test_str_method(self):
     foo = apiron.StubEndpoint(path="/bar/baz")
     assert str(foo) == "/bar/baz"
예제 #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
예제 #11
0
 def test_call_static(self, service):
     service.stub_endpoint = apiron.StubEndpoint(stub_response="stub response")
     assert service.stub_endpoint() == "stub response"
예제 #12
0
 def test_stub_default_response(self, service):
     service.stub_endpoint = apiron.StubEndpoint()
     assert service.stub_endpoint() == {"response": "StubEndpoint(path='/')"}