def test_not_found(self, ctx, mock_member_repository: MagicMock, member_manager: MemberManager): # Given... mock_member_repository.search_member_by = MagicMock(return_value=([], 0)) # When... with raises(MemberNotFoundError): member_manager.get_logs(ctx, TEST_USERNAME)
def test_fetch_failed(self, ctx, mock_logs_repository: MagicMock, mock_member_repository: MagicMock, sample_member: Member, member_manager: MemberManager): # Given... mock_member_repository.search_member_by = MagicMock( return_value=([sample_member], 1)) mock_logs_repository.get_logs = MagicMock(side_effect=LogFetchError) # When... result = member_manager.get_logs(ctx, TEST_USERNAME) # Expect use case to 'fail open', do not throw any error, assume there is no log. assert [] == result
def test_happy_path(self, ctx, mock_logs_repository: MagicMock, mock_member_repository: MagicMock, sample_member: Member, member_manager: MemberManager): # Given... mock_member_repository.search_member_by = MagicMock( return_value=([sample_member], 1)) # When... result = member_manager.get_logs(ctx, TEST_USERNAME) # Expect... assert TEST_LOGS == result mock_logs_repository.get_logs.assert_called_once_with( ctx, TEST_USERNAME, [])