def test_should_fail_when_guess_does_already_exist(self): expected_guess = random_guess() game = random_game(game_id=expected_guess.game_id) existing_guess = random_guess(guess_id=expected_guess.guess_id) self.context.game_repository.insert(game) self.context.guess_repository.insert(existing_guess) request_data = { "guess_id": expected_guess.guess_id.guess_id, "first_code_peg": expected_guess.first_peg.peg_type, "second_code_peg": expected_guess.second_peg.peg_type, "third_code_peg": expected_guess.third_peg.peg_type, "fourth_code_peg": expected_guess.fourth_peg.peg_type } endpoint = self.__guess_endpoint_for_game_id(expected_guess.game_id) response = self.test_client.post(endpoint, data=request_data) self.assertEqual(response.status_code, 409) self.assertNotEquals(json.loads(response.data), {}) self.assertEqual( self.context.guess_repository.search(expected_guess.guess_id), existing_guess )
def test_should_fail_when_the_guesses_limit_is_surpassed(self): expected_guess = random_guess() game = random_game(game_id=expected_guess.game_id) self.context.game_repository.insert(game) for _ in range(10): self.context.guess_repository.insert( random_guess(game_id=expected_guess.game_id) ) request_data = { "guess_id": expected_guess.guess_id.guess_id, "first_code_peg": expected_guess.first_peg.peg_type, "second_code_peg": expected_guess.second_peg.peg_type, "third_code_peg": expected_guess.third_peg.peg_type, "fourth_code_peg": expected_guess.fourth_peg.peg_type } endpoint = self.__guess_endpoint_for_game_id(expected_guess.game_id) response = self.test_client.post(endpoint, data=request_data) self.assertEqual(response.status_code, 409) self.assertNotEquals(json.loads(response.data), {}) self.assertEqual( self.context.guess_repository.search(expected_guess.guess_id), None )
def test_should_find_existing_game(self): game = random_game() self.game_repository.insert(game) self.assertEqual( self.game_repository.search(game.game_id), game )
def test_should_fail_if_game_already_exists(self): command = random_create_game_command() game_id = GameId(command.game_id) self.should_find_game(game_id, random_game(game_id=game_id)) with self.assertRaises(GameAlreadyExists) as context: self.handler.handle(command) self.assertEqual(context.exception, GameAlreadyExists(game_id))
def test_invalid_third_code_peg(self): game = random_game() request_data = { "game_id": game.game_id.game_id, "first_code_peg": game.first_peg.peg_type, "second_code_peg": game.second_peg.peg_type, "third_code_peg": invalid_code_peg(), "fourth_code_peg": game.fourth_peg.peg_type } response = self.test_client.post(self.GAME_ENDPOINT, data=request_data) self.assertEqual(response.status_code, 422)
def test_game_already_exists(self): game = random_game() request_data = { "game_id": game.game_id.game_id, "first_code_peg": game.first_peg.peg_type, "second_code_peg": game.second_peg.peg_type, "third_code_peg": game.third_peg.peg_type, "fourth_code_peg": game.fourth_peg.peg_type } self.context.game_repository.insert(game) response = self.test_client.post(self.GAME_ENDPOINT, data=request_data) self.assertEqual(response.status_code, 409)
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_create_game_on_request(self): expected_game = random_game() request_data = { "game_id": expected_game.game_id.game_id, "first_code_peg": expected_game.first_peg.peg_type, "second_code_peg": expected_game.second_peg.peg_type, "third_code_peg": expected_game.third_peg.peg_type, "fourth_code_peg": expected_game.fourth_peg.peg_type } response = self.test_client.post(self.GAME_ENDPOINT, data=request_data) self.assertEqual(response.status_code, 201) self.assertEqual(json.loads(response.data), {}) self.assertEqual( self.context.game_repository.search(expected_game.game_id), expected_game)
def test_should_insert_game(self): game = random_game() self.game_repository.insert(game)