Exemple #1
0
 def test_new_set_should_be_tie_break_false(self):
     match = MatchFactory(sets_number=5)
     teams = [TeamFactory() for i in range(2)]
     match.teams.add(*teams)
     SetFinishedTeamTwoFactory(match=match)
     SetFinishedTeamTwoFactory(match=match)
     assert match.new_set_should_be_tie_break() is False
Exemple #2
0
 def test_update_game_status_case_one(self):
     """
     Case one description:
         Match
             sets to play 3
             sets played 2
             points 25
             game_status: Playing
             sets [
                 {
                     game_status: Finished
                     t1: 25
                     t2: 0
                 }
                 {
                     game_status: Playing
                     t1: 25
                     t2: 0
                 }
             ]
     change SET game_status to Finished
     change MATCH game_status to Finished
     """
     match = MatchFactory(sets_number=3)
     teams = [TeamFactory() for i in range(2)]
     match.teams.add(*teams)
     SetFinishedTeamOneFactory(match=match)
     _set = SetFinishedTeamOneFactory(match=match)
     match.update_game_status()
     assert Set.objects.get(
         id=_set.id).game_status == Set.GameStatus.FINISHED.value
     assert match.game_status == Match.GameStatus.FINISHED.value
     assert Set.objects.filter(match=match).count() == 2
Exemple #3
0
 def test_get_team_one_and_team_two_won_sets_returns_one_and_cero(self):
     match = MatchFactory(sets_number=5)
     SetFinishedTeamOneFactory(match=match)
     team_one, team_two = match.get_team_one_and_team_two_won_sets(
         match.set_set.all())
     assert team_one == 1
     assert team_two == 0
Exemple #4
0
 def test_update_game_status_case_three(self):
     """
     Case three description:
         Match
             sets to play 5
             sets played 4
             points 25
             game_status: Playing
             sets [
                 {
                     game_status: Finished
                     t1: 25
                     t2: 0
                 }
                 {
                     game_status: Playing
                     t1: 25
                     t2: 0
                 }
                 {
                     game_status: Finished
                     t1: 0
                     t2: 25
                 }
                 {
                     game_status: Finished
                     t1: 0
                     t2: 25
                 }
             ]
     change SET game status to FINISHED
     MATCH game status should be PLAYING
     new SET SHOULD BE CREATED
     """
     match = MatchFactory(sets_number=5)
     teams = [TeamFactory() for i in range(2)]
     match.teams.add(*teams)
     SetFinishedTeamOneFactory(match=match)
     SetFinishedTeamOneFactory(match=match)
     SetFinishedTeamTwoFactory(match=match)
     _set = SetFactory(match=match, team_two_points=25)
     match.update_game_status()
     assert Set.objects.get(
         id=_set.id).game_status == Set.GameStatus.FINISHED.value
     assert match.game_status == Match.GameStatus.PLAYING.value
     assert Set.objects.filter(match=match).count() == 5
     new_set = Set.objects.filter(match=match).order_by('id').last()
     assert new_set.game_status == Set.GameStatus.PLAYING.value
     assert new_set.team_one_points == 0
     assert new_set.team_two_points == 0
     assert new_set.is_tie_break is True
     assert new_set.set_number == 5
Exemple #5
0
 def test_update_game_status_case_four(self):
     """
     Case four description:
         Match
             sets to play 5
             sets played 5
             points 25
             game_status: Playing
             sets [
                 {
                     game_status: Finished
                     t1: 25
                     t2: 0
                 }
                 {
                     game_status: Playing
                     t1: 25
                     t2: 0
                 }
                 {
                     game_status: Finished
                     t1: 0
                     t2: 25
                 }
                 {
                     game_status: Finished
                     t1: 0
                     t2: 25
                 }
                 {
                     game_status: Finished
                     t1: 0
                     t2: 15
                 }
             ]
     change SET game status to FINISHED
     MATCH game status should be FINISHED
     """
     match = MatchFactory(sets_number=5)
     teams = [TeamFactory() for i in range(2)]
     match.teams.add(*teams)
     SetFinishedTeamOneFactory(match=match)
     SetFinishedTeamOneFactory(match=match)
     SetFinishedTeamTwoFactory(match=match)
     SetFinishedTeamTwoFactory(match=match)
     _set = SetFactory(match=match, team_two_points=15, is_tie_break=True)
     match.update_game_status()
     assert Set.objects.get(
         id=_set.id).game_status == Set.GameStatus.FINISHED.value
     assert match.game_status == Match.GameStatus.FINISHED.value
     assert Set.objects.filter(match=match).count() == 5
Exemple #6
0
    def test_it_add_one_to_the_correct_team_response_and_db(self):
        action = AddPointsAction()
        request = get_fake_request()
        match = MatchFactory()
        match.teams.add(*[TeamFactory() for i in range(2)])
        match.init_sets()
        action.common['match'] = match
        response = json.loads(
            action.run(request=request, match_id=match.id,
                       team='team_one').content)
        sets = Set.objects.filter(match_id=match.id)

        assert len(response['match']['sets']) == 1
        assert response['match']['sets'][0][
            'game_status'] == Set.GameStatus.PLAYING.value
        assert response['match']['sets'][0]['team_one_points'] == 1
        assert response['match']['sets'][0]['team_two_points'] == 0
        assert response['match']['sets'][0]['match_id'] == match.id
        assert response['match']['sets'][0]['set_number'] == 1
        assert response['match']['sets'][0]['is_tie_break'] is False

        assert response['match']['sets_number'] == match.sets_number
        assert response['match'][
            'set_points_number'] == match.set_points_number
        assert response['match'][
            'points_difference'] == match.points_difference
        assert response['match']['tie_break_points'] == match.tie_break_points
        assert response['match']['teams'][0]['name'] == match.teams.all(
        )[0].name
        assert response['match']['teams'][0]['color'] == match.teams.all(
        )[0].color
        assert response['match']['teams'][1]['name'] == match.teams.all(
        )[1].name
        assert response['match']['teams'][1]['color'] == match.teams.all(
        )[1].color

        match_db = Match.objects.get(id=match.id)

        assert sets.count() == 1
        assert match_db.sets_number == match.sets_number
        assert match_db.set_points_number == match.set_points_number
        assert match_db.points_difference == match.points_difference
        assert match_db.tie_break_points == match.tie_break_points
        assert match_db.game_status == Match.GameStatus.PLAYING.value
        assert len(sets) == 1
        assert sets[0].game_status == Set.GameStatus.PLAYING.value
        assert sets[0].team_one_points == 1
        assert sets[0].team_two_points == 0
Exemple #7
0
 def test_it_raises_bad_request_when_no_token_provided(self):
     action = SubPointsAction()
     request = get_fake_request()
     match = MatchFactory()
     with pytest.raises(BadRequestError) as e:
         action.validate(request, match_id=match.id, team='team_one')
     assert e.value.error_code == INVALID_TOKEN
Exemple #8
0
 def test_it_raises_invalid_when_invalid_game_status(self):
     action = SubPointsAction()
     match = MatchFactory(game_status=Match.GameStatus.FINISHED.value)
     request = get_fake_request(get_params={'token': match.token})
     with pytest.raises(BadRequestError) as e:
         action.validate(request, match_id=match.id, team='team_one')
     assert e.value.error_code == INVALID_MATCH_STATUS
Exemple #9
0
 def test_it_does_not_raise_error_when_valid_id_and_write_match_in_common(
         self):
     action = GetMatchByIdAction()
     match = MatchFactory()
     request = get_fake_request()
     action.validate(request, match_id=match.id)
     assert action.common.get('match').id == match.id
Exemple #10
0
 def test_winner_team_returns_team_two(self):
     match = MatchFactory(sets_number=3)
     teams = [TeamFactory() for i in range(2)]
     match.teams.add(*teams)
     SetFinishedTeamTwoFactory(match=match)
     SetFinishedTeamTwoFactory(match=match)
     assert match.winner_team.id == teams[1].id
Exemple #11
0
 def test_it_raises_invalid_when_no_playing_sets(self):
     action = SubPointsAction()
     match = MatchFactory()
     request = get_fake_request(get_params={'token': match.token})
     with pytest.raises(BadRequestError) as e:
         action.validate(request, match_id=match.id, team='team_one')
     assert e.value.error_code == INVALID_SET_STATUS
Exemple #12
0
 def test_it_raises_invalid_when_invalid_team(self):
     action = SubPointsAction()
     match = MatchFactory()
     request = get_fake_request(get_params={'token': match.token})
     with pytest.raises(BadRequestError) as e:
         action.validate(request,
                         match_id=match.id,
                         team='no_existing_team')
     assert e.value.error_code == INVALID_TEAM_SELECTION
Exemple #13
0
 def test_it_returns_match(self):
     action = GetMatchByIdAction()
     match = MatchFactory.build()
     request = get_fake_request()
     action.common = {'match': match}
     result = json.loads(action.run(request, match_id=match.id).content)
     expected = {
         'match': {
             'id': match.id,
             'sets_number': match.sets_number,
             'access_code': match.access_code,
             'status': match.status,
             'game_status': match.game_status,
             'set_points_number': match.set_points_number,
             'points_difference': match.points_difference,
             'tie_break_points': match.tie_break_points,
             'teams': [],
             'sets': [],
             'winner_team': match.winner_team,
         }
     }
     assert expected == result
Exemple #14
0
 def test_get_counters(self):
     match = MatchFactory(sets_number=7)
     SetFinishedTeamOneFactory(match=match)
     t1c, t2c = match.get_counters()
     assert t1c == 1
     assert t2c == 0
     SetFinishedTeamOneFactory(match=match)
     t1c, t2c = match.get_counters()
     assert t1c == 2
     assert t2c == 0
     SetFinishedTeamTwoFactory(match=match)
     t1c, t2c = match.get_counters()
     assert t1c == 2
     assert t2c == 1
     SetFinishedTeamTwoFactory(match=match)
     t1c, t2c = match.get_counters()
     assert t1c == 2
     assert t2c == 2
Exemple #15
0
 def test_get_minimum_sets_to_play_return_4_when_sets_is_7(self):
     match = MatchFactory.build(sets_number=7)
     result = match.get_minimum_sets_to_play()
     assert result == 4
Exemple #16
0
 def test_winner_team_no_winner(self):
     match = MatchFactory(sets_number=3)
     teams = [TeamFactory() for i in range(2)]
     match.teams.add(*teams)
     SetFinishedTeamOneFactory(match=match)
     assert match.winner_team is None
Exemple #17
0
 def test_can_substract_points_no_set_returns_false(self):
     match = MatchFactory(sets_number=5)
     assert match.can_substract_points('team_one') is False
Exemple #18
0
 def test_can_substract_points_playing_set_return_false_team_two(self):
     match = MatchFactory(sets_number=5)
     SetFactory(match=match,
                game_status=Set.GameStatus.PLAYING.value,
                team_one_points=1)
     assert match.can_substract_points('team_two') is False
Exemple #19
0
 def test_can_substract_points_finished_sets_returns_false(self):
     match = MatchFactory(sets_number=5)
     SetFactory(match=match, game_status=Set.GameStatus.FINISHED.value)
     assert match.can_substract_points('team_one') is False
Exemple #20
0
 def test_get_team_one_and_team_two_won_sets_returns_cero_and_cero(self):
     match = MatchFactory(sets_number=5)
     team_one, team_two = match.get_team_one_and_team_two_won_sets(
         match.set_set.all())
     assert team_one == 0
     assert team_two == 0
Exemple #21
0
 def test_team_two_is_team_two(self):
     match = MatchFactory(sets_number=7)
     teams = [TeamFactory() for i in range(2)]
     match.teams.add(*teams)
     assert match.team_two.id == teams[1].id
Exemple #22
0
 def test_it_does_not_raise_error_when_valid_request(self):
     action = SubPointsAction()
     match = MatchFactory()
     request = get_fake_request(get_params={'token': match.token})
     SetFactory(match=match, team_one_points=1)
     action.validate(request, match_id=match.id, team='team_one')
Exemple #23
0
 def test_it_does_not_raise_invalid_when_valid_request(self):
     action = AddPointsAction()
     request = get_fake_request()
     match = MatchFactory()
     request = get_fake_request(get_params={'token': match.token})
     action.validate(request, match_id=match.id, team='team_one')