def test_should_execute_successfully_a_empty_controller_with_jwt_requirement_with_user( given_any_petisco, given_any_token_type_with_user, given_headers_provider, given_auth_token_headers_creator, given_any_client_id, given_any_user_id, given_any_correlation_id, given_info_id_only_correlation_id, ): logger = FakeLogger() expected_info_id = InfoId( client_id=given_any_client_id, user_id=given_any_user_id, correlation_id=given_any_correlation_id, ) @controller_handler( logger=logger, token_manager=TokenManager(accepted_tokens=[ AcceptedToken(token_type=given_any_token_type_with_user, require_user=True) ]), headers_provider=given_headers_provider({ **given_auth_token_headers_creator( given_any_token_type_with_user, given_any_client_id, given_any_user_id, ), **given_info_id_only_correlation_id.get_http_headers(), }), ) def my_controller(info_id: InfoId): assert info_id == expected_info_id return Success("Hello Petisco") http_response = my_controller() assert http_response == ({"message": "OK"}, 200) first_logging_message = logger.get_logging_messages()[0] second_logging_message = logger.get_logging_messages()[1] assert first_logging_message == ( DEBUG, LogMessageMother.get_controller( operation="my_controller", message="Processing Request", info_id=expected_info_id, ).to_dict(), ) assert second_logging_message == ( DEBUG, LogMessageMother.get_controller( operation="my_controller", message="Result[status: success | value: Hello Petisco]", info_id=expected_info_id, ).to_dict(), )
def test_should_execute_successfully_a_empty_controller_with_several_jwt_requirement( accepted_tokens, token_type, user_id, expected_status_code, given_any_petisco, given_headers_provider, given_auth_token_headers_creator, given_any_client_id, given_any_correlation_id, given_info_id_only_correlation_id, ): logger = FakeLogger() expected_info_id = InfoId( client_id=given_any_client_id, user_id=user_id, correlation_id=given_any_correlation_id, ) @controller_handler( logger=logger, token_manager=TokenManager(accepted_tokens=accepted_tokens), headers_provider=given_headers_provider({ **given_auth_token_headers_creator(token_type, given_any_client_id, user_id), **given_info_id_only_correlation_id.get_http_headers(), }), ) def my_controller(info_id: InfoId): assert info_id == expected_info_id return Success("Hello Petisco") http_response = my_controller() assert http_response[1] == expected_status_code
def given_any_notifier_message_with_info_id(given_any_client_id, given_any_user_id, given_any_message): return NotifierMessage( message=given_any_message, info_id=InfoId(client_id=given_any_client_id, user_id=given_any_user_id), )
def given_any_complete_notifier_message( given_any_client_id, given_any_user_id, given_any_message, given_any_info_petisco, given_any_title, ): return NotifierMessage( title=given_any_title, message=given_any_message, info_id=InfoId(client_id=given_any_client_id, user_id=given_any_user_id), info_petisco=given_any_info_petisco, )
def given_long_traceback_complete_notifier_exception_message( given_any_client_id, given_any_user_id, given_any_message, given_any_info_petisco, given_any_exception, given_long_traceback, ): return NotifierExceptionMessage( executor="test_function", exception=given_any_exception, traceback=given_long_traceback, info_id=InfoId(client_id=given_any_client_id, user_id=given_any_user_id), info_petisco=given_any_info_petisco, )
def test_should_inherit_from_pattern_base_and_extend_it_with_info_id(): class MyRepository(PatternBase): pass repository = MyRepository() client_id = ClientId("client-id") user_id = UserId.generate() info_id = InfoId(client_id, user_id) repository_with_info_id_id = repository.with_info_id(info_id) assert isinstance(repository_with_info_id_id, MyRepository) assert isinstance(repository_with_info_id_id.get_client_id(), ClientId) assert isinstance(repository_with_info_id_id.get_client_id_value(), str) assert repository_with_info_id_id.get_client_id() == client_id assert isinstance(repository_with_info_id_id.get_user_id(), UserId) assert isinstance(repository_with_info_id_id.get_user_id_value(), str) assert repository_with_info_id_id.get_user_id() == user_id assert isinstance(repository_with_info_id_id.get_info_id(), InfoId) assert repository_with_info_id_id.get_info_id() == info_id