Пример #1
0
    def test_show_game_with_existing_game(self):
        test_user, test_player = th.generate_test_user("test-user-1", "fivesPass123", "*****@*****.**", "Test", "User")
        test_game = th.create_game(0, 9, "2018-04-28 14:00", "2018-04-28 15:00", 1, "66 Bankhead Dr", "Edinburgh", "EH11 4EQ", 5, 1, test_user)
        th.create_participation(test_game, test_player, 0)

        game_custom_slug = Game.objects.all()[0].custom_slug
        response = self.client.get(reverse('show_game', kwargs={'game_custom_slug': game_custom_slug}))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Competitive")
Пример #2
0
    def test_show_past_game_not_rated_by_user(self):
        # Create test user and login.
        test_user, test_player = th.generate_test_user("test-user-1", "fivesPass1", "*****@*****.**", "Test", "User")
        test_user2, test_player2 = th.generate_test_user("test-user-2", "fivesPass2", "*****@*****.**", "Test2", "User2")
        self.client.login(username='******', password='******')
        # Create test game and add test users to particpation.
        start_datetime, end_datetime = th.start_and_end_datetime_generator(-100,2)
        test_game = th.create_game(0, 9, start_datetime, end_datetime, 2, "10 Keith St", "Glasgow", "G11 6QQ", 0, 1, test_user)
        th.create_participation(test_game, test_player, 0)
        th.create_participation(test_game, test_player2, 0)

        game_custom_slug = test_game.custom_slug
        response = self.client.get(reverse('show_past_game', kwargs={'player': test_user, 'game_custom_slug': game_custom_slug}))
        self.assertEqual(response.status_code, 200)
        # Check that a formset was passed from view to the template, giving the user the opportunity ro rate.
        formset = response.context['rating_formset']
        self.assertNotEqual(formset, None)
Пример #3
0
 def test_participation_string_representation(self):
     test_user, test_player = th.generate_test_user(
         "test-user-1", "fivesPass123", "*****@*****.**", "Test",
         "User")
     test_game = th.create_game(0, 9, "2018-04-28 14:00",
                                "2018-04-28 15:00", 1, "66 Bankhead Dr",
                                "Edinburgh", "EH11 4EQ", 5, 1, test_user)
     test_participation = th.create_participation(test_game, test_player, 0)
     self.assertEqual(
         str(test_participation),
         str(test_participation.player) + " " +
         str(test_participation.game) + " " + str(test_participation.rated))
Пример #4
0
    def test_create_game_view_with_conflict(self):
        # Add user and login, add game and particpation to database, and redirect to create game.
        test_user, test_player = th.generate_test_user("test-user-1", "fivesPass123", "*****@*****.**", "Test", "User")
        self.client.login(username='******', password='******')

        start_datetime, end_datetime = th.start_and_end_datetime_generator(10,2)
        test_game = th.create_game(0, 9, start_datetime, end_datetime, 2, "10 Keith St", "Glasgow", "G11 6QQ", 0, 0, test_user)
        th.create_participation(test_game, test_player, 0)

        self.client.get(reverse('create_game'))

        # Try creating a game with a time conflict.
        start_date, start_time = th.start_date_and_time_generator(10)
        response = self.client.post(reverse('create_game'), {'game_type': 0, 'date': start_date, 'time': start_time, 'duration': 1,
                                                  'street': "66 Bankhead Dr", 'city': "Edinburgh", 'postcode': "EH11 4EQ", 'price': 5, 'booked': 1} )

        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "You already have a game scheduled during this time")

        # Game should not have been added to the database.
        response = self.client.get(reverse('index'))
        num_games = len(response.context['games'])
        self.assertEqual(num_games , 1)