def test_should_not_find_unexisting_game(self): query = random_search_game_query() game_id = random_game_id(query.game_id) expected_response = SearchGameResponse(None) self.should_not_find_game(game_id) self.assertEqual(self.handler.handle(query), expected_response)
def random_game(game_id: GameId = None, first_peg: CodePeg = None, second_peg: CodePeg = None, third_peg: CodePeg = None, fourth_peg: CodePeg = None) -> Game: game_id = random_game_id() if game_id is None else game_id first_peg = random_code_peg() if first_peg is None else first_peg second_peg = random_code_peg() if second_peg is None else second_peg third_peg = random_code_peg() if third_peg is None else third_peg fourth_peg = random_code_peg() if fourth_peg is None else fourth_peg return Game(game_id, first_peg, second_peg, third_peg, fourth_peg)
def test_should_find_existing_game(self): query = random_search_game_query() game_id = random_game_id(query.game_id) game = random_game(game_id=game_id) expected_response = SearchGameResponse( GameResponse(game.game_id.game_id, game.first_peg.peg_type, game.second_peg.peg_type, game.third_peg.peg_type, game.fourth_peg.peg_type)) self.should_find_game(game_id, game) self.assertEqual(self.handler.handle(query), expected_response)
def test_should_search_guesses_by_game_id(self): game_id = random_game_id() guesses_of_game = [random_guess(game_id=game_id) for _ in range(5)] guesses_not_of_game = [random_guess() for _ in range(5)] for guess in chain(guesses_of_game, guesses_not_of_game): self.guess_repository.insert(guess) found = self.guess_repository.search_by_game_id(game_id) self.assertEqual(len(found), len(guesses_of_game)) for guess in guesses_of_game: self.assertIn(guess, found) for guess in guesses_not_of_game: self.assertNotIn(guess, found)
def random_create_game_command(game_id: str = None, first_peg: str = None, second_peg: str = None, third_peg: str = None, fourth_peg: str = None) -> CreateGameCommand: game_id = random_game_id().game_id if game_id is None \ else game_id first_peg = random_code_peg().peg_type if first_peg is None \ else first_peg second_peg = random_code_peg().peg_type if second_peg is None \ else second_peg third_peg = random_code_peg().peg_type if third_peg is None \ else third_peg fourth_peg = random_code_peg().peg_type if fourth_peg is None \ else fourth_peg return CreateGameCommand(game_id, first_peg, second_peg, third_peg, fourth_peg)
def random_create_guess_command( guess_id: str = None, game_id: str = None, first_code_peg: int = None, second_code_peg: int = None, third_code_peg: int = None, fourth_code_peg: int = None) -> CreateGuessCommand: guess_id = random_guess_id().guess_id if guess_id is None else guess_id game_id = random_game_id().game_id if game_id is None else game_id first_code_peg = random_code_peg().peg_type if first_code_peg is None \ else first_code_peg second_code_peg = random_code_peg( ).peg_type if second_code_peg is None else second_code_peg third_code_peg = random_code_peg().peg_type if third_code_peg is None \ else third_code_peg fourth_code_peg = random_code_peg( ).peg_type if fourth_code_peg is None else fourth_code_peg return CreateGuessCommand(guess_id, game_id, first_code_peg, second_code_peg, third_code_peg, fourth_code_peg)
def random_game_response(game_id: str = None, first_peg: str = None, second_peg: str = None, third_peg: str = None, fourth_peg: str = None)->GameResponse: game_id = random_game_id().game_id if game_id is None \ else game_id first_peg = random_code_peg().peg_type if first_peg is None \ else first_peg second_peg = random_code_peg().peg_type if second_peg is None \ else second_peg third_peg = random_code_peg().peg_type if third_peg is None\ else third_peg fourth_peg = random_code_peg().peg_type if fourth_peg is None\ else fourth_peg return GameResponse( game_id, first_peg, second_peg, third_peg, fourth_peg )
def test_should_not_find_unexisting_game(self): self.assertIsNone(self.game_repository.search(random_game_id()))
def random_search_game_query(game_id: str = None) -> SearchGameQuery: game_id = random_game_id().game_id if game_id is None else game_id return SearchGameQuery(game_id)