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