コード例 #1
0
 def test_calculate_score_for_game__None(self):
     game = game_models.Game(total_score=None)
     serializer_instance = serializers.ScoreSerializer(game)
     assert serializer_instance.data == {
         'total_score': None,
         'game_id': None
     }
コード例 #2
0
 def test_calculate_score_for_game__open_frame(self):
     game = game_models.Game(game_id='abcde12345', total_score=6)
     serializer_instance = serializers.ScoreSerializer(game)
     assert serializer_instance.data == {
         'total_score': 6,
         'game_id': 'abcde12345'
     }
コード例 #3
0
 def test_calculate_score_for_all_strikes(self):
     scores = ['X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X-X-X']
     for score in scores:
         services.set_frame_score(self.queryset,
                                  self.game_registration.game_id, score)
     game_object = services.get_frame_score(self.queryset,
                                            self.game_registration.game_id)
     assert game_object == game_models.Game(self.game_registration.game_id,
                                            300)
コード例 #4
0
 def test_calculate_score_for_completed_game_5(self):
     scores = ['X', '7/', '7-2', '9/', 'X', 'X', 'X', '2-3', '6/', 'X-4/']
     for score in scores:
         services.set_frame_score(self.queryset,
                                  self.game_registration.game_id, score)
     game_object = services.get_frame_score(self.queryset,
                                            self.game_registration.game_id)
     assert game_object == game_models.Game(self.game_registration.game_id,
                                            178)
コード例 #5
0
 def test_calculate_score_for_active_game(self):
     scores = ['X', '7/', '7-2', '9/', 'X', 'X', 'X']
     for score in scores:
         services.set_frame_score(self.queryset,
                                  self.game_registration.game_id, score)
     game_object = services.get_frame_score(self.queryset,
                                            self.game_registration.game_id)
     assert game_object == game_models.Game(self.game_registration.game_id,
                                            96)
コード例 #6
0
 def test_game_id_not_found(self):
     score_object = services.get_frame_score(self.queryset, 'abcde12345')
     game_object = game_models.Game('abcde12345')
     game_object.errors = [
         game_models.Error(
             error_code=404,
             error_message='No game was found for the game id: abcde12345.')
     ]
     assert score_object == game_object
コード例 #7
0
    def setUp(self):
        self.player = models.Player(first_name="Dakota",
                                    last_name="Lillie",
                                    email="*****@*****.**")
        self.player.set_password("helloworld")
        self.player.save()

        country_players = {
            country: self.player
            for country in constants.COUNTRIES.as_list()
        }

        self.game = models.Game(title="New Game")
        self.game.save(country_players=country_players)
コード例 #8
0
def get_frame_score(queryset, game_id):
    """Gets the scores of the all the frames in addition to the total score."""
    with transaction.atomic(savepoint=False):
        game_object, is_returned = _get_game_object(game_id, game_models.Game)
        game_object.game_id = game_id
        if not is_returned:
            return game_object
        spf_qs = queryset.filter(game=game_object).order_by('frame')
        # If number of played frames = 10, that means the game has been
        # completed. In that event,
        total_score = None
        for score in reversed(spf_qs):
            if total_score is None and score.total_score_for_frame is not None:
                total_score = score.total_score_for_frame
        return game_models.Game(game_id, total_score)
コード例 #9
0
 def test_calculate_score_for_new_game(self):
     game_object = services.get_frame_score(self.queryset,
                                            self.game_registration.game_id)
     assert game_object == game_models.Game(self.game_registration.game_id)