def test_malfomed_request(self, setup, dependency_mocks): post_data = { "malformed": "penguin", "connections": "sarah, michael and jonny" } with dependency_mocks as mocks: mocks["credential_offer_accept"].return_value = None response = self.client.post( path=f"/{self.path}", data=post_data, format="json", ) returns_status_code_http_200_ok(response) mocks["credential_offer_accept"].assert_not_called() mocks["credential_offer_create"].assert_not_called() mocks["LOGGER"].assert_has_calls([ call.info( "webhook: received: topic: 'issue_credential' - state: 'None' - message: {'malformed': 'penguin', 'connections': 'sarah, michael and jonny'}" ), call.info( "webhook: topic: issue_credential and state: None is invalid" ), ])
def test_invalid_connection_id(self, setup, dependency_mocks): post_data = { "state": "response", "connection_id": "random test connection id" } with dependency_mocks as mocks: mocks["connection_invitation_accept"].return_value = None response = self.client.post( path=f"/{self.path}", data=post_data, format="json", ) returns_status_code_http_200_ok(response) mocks["connection_invitation_accept"].assert_called_once_with( "random test connection id") mocks["credential_offer_create"].assert_not_called() mocks["LOGGER"].assert_has_calls([ call.info( "webhook: received: topic: 'connections' - state: 'response' - message: {'state': 'response', 'connection_id': 'random test connection id'}" ), call.error( "webhook: connection_invitation_accept: connection_id: random test connection id not found" ), ])
def test_webhook_raises_exception(self, setup, mocker): response = self.client.post(path=f"/{self.path}", data="invalid_json", format="json") returns_status_code_http_200_ok(response) mocker.patch("manager.views.credential_offer_accept", side_effect=Exception()) response = self.client.post(path=f"/{self.path}", data=self.post_data, format="json") returns_status_code_http_200_ok(response)
def test_calls_credential_workflow(self, setup, dependency_mocks): with dependency_mocks as mocks: response = self.client.post( path=f"/{self.path}", data=self.message, format="json", ) returns_status_code_http_200_ok(response) mocks["credential_offer_create"].assert_not_called() mocks["credential_offer_accept"].assert_called_once_with("1") mocks["LOGGER"].assert_has_calls([ call.info( "webhook: received: topic: 'issue_credential' - state: 'credential_issued' - message: {'state': 'credential_issued', 'connection_id': '1'}" ), call.info( "webhook: processing: credential accepted - connection_id: 1" ), ])
def test_invalid_state(self, setup, dependency_mocks): post_data = {"state": "random test state", "connection_id": "1"} with dependency_mocks as mocks: response = self.client.post( path=f"/{self.path}", data=post_data, format="json", ) returns_status_code_http_200_ok(response) mocks["connection_invitation_accept"].assert_not_called() mocks["credential_offer_create"].assert_not_called() mocks["LOGGER"].assert_has_calls([ call.info( "webhook: received: topic: 'connections' - state: 'random test state' - message: {'state': 'random test state', 'connection_id': '1'}" ), call.info( "webhook: topic: connections and state: random test state is invalid" ), ])
def test_calls_credential_workflow(self, setup, dependency_mocks): with dependency_mocks as mocks: mocks[ "connection_invitation_accept"].return_value = "mock connection invitation" response = self.client.post( path=f"/{self.path}", data=self.post_data, format="json", ) returns_status_code_http_200_ok(response) mocks["connection_invitation_accept"].assert_called_once_with("1") mocks["credential_offer_create"].assert_called_once_with( "1", "mock connection invitation") mocks["LOGGER"].assert_has_calls([ call.info( "webhook: received: topic: 'connections' - state: 'response' - message: {'state': 'response', 'connection_id': '1'}" ), call.info( "webhook: processing: connection accepted - connection_id: 1" ), ], )
def test_put_with_authentication(self, setup, authenticate, put_response): returns_status_code_http_200_ok(put_response)
def test_delete_with_authentication(self, setup, authenticate, delete_response): returns_status_code_http_200_ok(delete_response)
def test_post_without_authentication(self, setup, post_response): returns_status_code_http_200_ok(post_response)