Ejemplo n.º 1
0
class TestGameModel:
    def _service(self, secret):
        return Game(secret)

    @pytest.mark.parametrize(**parametrize_from_json_file(
        'input_secret, input_guess, expected',
        fpath=join(CURRENT_DIR, 'test_cases/test_game_model.json'),
        test_class_name='TestGameService',
        test_class_method='eval_guess'))
    def test_eval_guess(self, input_secret, input_guess, expected):
        secret = Guess(input_secret)
        guess = Guess(input_guess)
        result = self._service(secret).eval_guess(guess)
        assert result.values == expected

    @pytest.mark.parametrize(**parametrize_from_json_file(
        'input_secret, expected',
        fpath=join(CURRENT_DIR, 'test_cases/test_game_model.json'),
        test_class_name='TestGameService',
        test_class_method='secret_raw_values'))
    def test_secret_raw_values(self, input_secret, expected):
        secret = Guess(input_secret)
        result = self._service(secret).secret_raw_values
        assert result == expected

    @pytest.mark.parametrize(**parametrize_from_json_file(
        'input_secret, expected',
        fpath=join(CURRENT_DIR, 'test_cases/test_game_model.json'),
        test_class_name='TestGameService',
        test_class_method='from_data'))
    def test_from_data(self, input_secret, expected):
        game_data = GameData(secret=';'.join(input_secret))
        result = Game.from_data(game_data)
        assert isinstance(result, Game)
        assert result.secret_raw_values == expected
Ejemplo n.º 2
0
class TestGameController(BaseControllerTest):
    @pytest.mark.parametrize(**parametrize_from_json_file(
        fpath=join(CURRENT_DIR, 'test_cases/test_game_controller.json'),
        test_class_name='TestGameController',
        test_class_method='new_game'))
    def test_new_game(self, method, url, headers, url_parameters, data,
                      query_string, status_code, response_data, config, app,
                      mocker):
        self._run_standard_test(method=method,
                                url=url,
                                headers=headers,
                                url_parameters=url_parameters,
                                data=data,
                                query_string=query_string,
                                status_code=status_code,
                                response_data=response_data,
                                config=config,
                                app=app)

    @pytest.mark.parametrize(**parametrize_from_json_file(
        fpath=join(CURRENT_DIR, 'test_cases/test_game_controller.json'),
        test_class_name='TestGameController',
        test_class_method='get_single_game'))
    def test_get_single_game(self, method, url, headers, url_parameters, data,
                             query_string, status_code, response_data, config,
                             app, mocker):
        self._run_standard_test(method=method,
                                url=url,
                                headers=headers,
                                url_parameters=url_parameters,
                                data=data,
                                query_string=query_string,
                                status_code=status_code,
                                response_data=response_data,
                                config=config,
                                app=app)

    @pytest.mark.parametrize(**parametrize_from_json_file(
        fpath=join(CURRENT_DIR, 'test_cases/test_game_controller.json'),
        test_class_name='TestGameController',
        test_class_method='new_guess'))
    def test_new_guess(self, method, url, headers, url_parameters, data,
                       query_string, status_code, response_data, config, app,
                       mocker):
        self._run_standard_test(method=method,
                                url=url,
                                headers=headers,
                                url_parameters=url_parameters,
                                data=data,
                                query_string=query_string,
                                status_code=status_code,
                                response_data=response_data,
                                config=config,
                                app=app)
Ejemplo n.º 3
0
class TestResultModel:
    @pytest.mark.parametrize(**parametrize_from_json_file(
        'input_secret, input_guess, expected',
        fpath=join(CURRENT_DIR, 'test_cases/test_result_model.json'),
        test_class_name='TestResultModel',
        test_class_method='values'))
    def test_values(self, input_secret, input_guess, expected):
        secret = Guess(input_secret)
        guess = Guess(input_guess)
        assert Result(secret=secret, current=guess).values == expected

    @pytest.mark.parametrize(**parametrize_from_json_file(
        'input_secret, input_guess, expected',
        fpath=join(CURRENT_DIR, 'test_cases/test_result_model.json'),
        test_class_name='TestResultModel',
        test_class_method='guessed'))
    def test_guessed(self, input_secret, input_guess, expected):
        secret = Guess(input_secret)
        guess = Guess(input_guess)
        assert Result(secret=secret, current=guess).guessed() == expected
class TestGuessModel:
    @pytest.mark.parametrize(**parametrize_from_json_file(
        'input_guess',
        fpath=join(CURRENT_DIR, 'test_cases/test_guess_model.json'),
        test_class_name='TestGuessModel',
        test_class_method='raise_when_invalid_length'))
    def test_raise_when_invalid_length(self, input_guess):
        with pytest.raises(InvalidGuessLength) as _:
            Guess(input_guess)

    @pytest.mark.parametrize(**parametrize_from_json_file(
        'input_guess, expected',
        fpath=join(CURRENT_DIR, 'test_cases/test_guess_model.json'),
        test_class_name='TestGuessModel',
        test_class_method='guess_creation'))
    def test_guess_creation(self, input_guess, expected):
        guess = Guess(input_guess)
        expected_guess = Guess(expected)
        assert guess == expected_guess

    @pytest.mark.parametrize(**parametrize_from_json_file(
        'input_guess, expected',
        fpath=join(CURRENT_DIR, 'test_cases/test_guess_model.json'),
        test_class_name='TestGuessModel',
        test_class_method='values'))
    def test_values(self, input_guess, expected):
        guess = Guess(input_guess)
        assert guess.values == expected

    @pytest.mark.parametrize(**parametrize_from_json_file(
        'input_guess, secret',
        fpath=join(CURRENT_DIR, 'test_cases/test_guess_model.json'),
        test_class_name='TestGuessModel',
        test_class_method='eval'))
    def test_eval(self, input_guess, secret):
        res = Guess(input_guess).eval(Guess(secret))
        assert isinstance(res, Result)
class TestBoardModel:
    @pytest.mark.parametrize(
        **parametrize_from_json_file(
            'input_secret, input_old_guesses, input_new_guess, expected_msg',
            fpath=join(CURRENT_DIR, 'test_cases/test_board_model.json'),
            test_class_name='TestBoardModel',
            test_class_method='new_turn_raise'
        ))
    def test_new_turn_raise_exception(self, input_secret, input_old_guesses, input_new_guess, expected_msg):
        with pytest.raises(FinishedGameException) as e:
            Board(
                game=Game(secret=Guess(input_secret)),
                turns=[Guess(g) for g in input_old_guesses]
            ).new_turn(guess=Guess(input_new_guess))
        assert e.value.args[0] == expected_msg