Exemplo n.º 1
0
    def test_get_avatar_id_for_two_users(self):
        # Set up the first avatar
        first_user = self.user
        models.Avatar(owner=first_user, code=self.CODE, game=self.game).save()
        client_one = self.login()

        # Set up the second avatar
        _, _, second_user = create_school_student_directly(
            self.klass.access_code)
        models.Avatar(owner=second_user.new_user,
                      code=self.CODE,
                      game=self.game).save()
        client_two = Client()
        client_two.login(username="******", password="******")

        first_avatar_id, first_response = get_avatar_id(first_user, 1)
        second_avatar_id, second_response = get_avatar_id(
            second_user.new_user, 1)

        # Status code starts with 2, success response can be different than 200.
        assert str(first_response.status_code)[0] == "2"
        assert str(second_response.status_code)[0] == "2"

        assert first_avatar_id == 1
        assert second_avatar_id == 2
Exemplo n.º 2
0
    def test_current_avatar_api_for_two_users(self):
        # Set up the first avatar
        first_user = self.user
        models.Avatar(owner=first_user, code=self.CODE, game=self.game).save()
        client_one = self.login()

        # Set up the second avatar
        second_user = User.objects.create_user("test2", "*****@*****.**",
                                               "password2")
        second_user.save()
        models.Avatar(owner=second_user, code=self.CODE, game=self.game).save()
        client_two = Client()
        client_two.login(username="******", password="******")

        self.game.public = True
        self.game.can_play = [first_user, second_user]
        self.game.save()

        first_response = client_one.get(
            reverse("kurono/current_avatar_in_game", kwargs={"game_id": 1}))
        second_response = client_two.get(
            reverse("kurono/current_avatar_in_game", kwargs={"game_id": 1}))

        # Status code starts with 2, success response can be different than 200.
        self.assertEqual(str(first_response.status_code)[0], "2")
        self.assertEqual(str(second_response.status_code)[0], "2")

        # JSON is returned as string so needs to be evaluated.
        first_id = json.loads(first_response.content)["current_avatar_id"]
        second_id = json.loads(second_response.content)["current_avatar_id"]

        self.assertEqual(first_id, 1)
        self.assertEqual(second_id, 2)
Exemplo n.º 3
0
 def test_games_api(self):
     self.game.main_user = self.user
     self.game.save()
     user2 = User.objects.create_user(username="******", password="******")
     user3 = User.objects.create_user(username="******", password="******")
     models.Avatar(owner=self.user, code=self.CODE, pk=1, game=self.game).save()
     models.Avatar(owner=user2, code="test2", pk=2, game=self.game).save()
     models.Avatar(owner=user3, code="test3", pk=3, game=self.game).save()
     c = Client()
     response = c.get(reverse("aimmo/game_details", kwargs={"id": 1}))
     self.assertJSONEqual(response.content, self.EXPECTED_GAMES)
Exemplo n.º 4
0
 def test_games_api(self):
     self.game.main_user = self.user
     self.game.save()
     user2 = User.objects.create_user(username='******', password='******')
     user3 = User.objects.create_user(username='******', password='******')
     models.Avatar(owner=self.user, code=self.CODE, pk=1,
                   game=self.game).save()
     models.Avatar(owner=user2, code='test2', pk=2, game=self.game).save()
     models.Avatar(owner=user3, code='test3', pk=3, game=self.game).save()
     c = Client()
     response = c.get(reverse('aimmo/game_details', kwargs={'id': 1}))
     self.assertJSONEqual(response.content, self.EXPECTED_GAMES)
Exemplo n.º 5
0
    def test_id_of_current_avatar_same_as_games_url(self):
        """
        Ensures that the id's are consistent throughout the project. Check for ID's received
        by the current_avatar URL as well as the games URL api.
        """
        user = self.user
        models.Avatar(owner=user, code=self.CODE, game=self.game).save()
        client = self.login()

        self.game.public = True
        self.game.can_play = [user]
        self.game.save()

        current_avatar_api_response = client.get(
            reverse("kurono/current_avatar_in_game", kwargs={"game_id": 1}))
        games_api_response = client.get(
            reverse("kurono/game_user_details", kwargs={"id": 1}))

        current_avatar_id = json.loads(
            current_avatar_api_response.content)["current_avatar_id"]
        games_api_users = json.loads(games_api_response.content)["users"]

        self.assertEqual(current_avatar_id, 1)
        self.assertEqual(len(games_api_users), 1)
        self.assertEqual(games_api_users[0]["id"], 1)
Exemplo n.º 6
0
    def test_id_of_current_avatar_same_as_games_url(self):
        """
        Ensures that the id's are consistent throughout the project. Check for ID's received
        by the current_avatar URL as well as the games URL api.
        """
        user = self.user
        models.Avatar(owner=user, code=self.CODE, game=self.game).save()
        client = self.login()

        self.game.public = True
        self.game.can_play = [user]
        self.game.save()

        current_avatar_api_response = client.get(
            reverse('aimmo/current_avatar_in_game', kwargs={'game_id': 1}))
        games_api_response = client.get(
            reverse('aimmo/game_details', kwargs={'id': 1}))

        current_avatar_id = ast.literal_eval(
            current_avatar_api_response.content)['current_avatar_id']
        games_api_users = json.loads(
            games_api_response.content)['main']['users']

        self.assertEqual(current_avatar_id, 1)
        self.assertEqual(len(games_api_users), 1)
        self.assertEqual(games_api_users[0]['id'], 1)
Exemplo n.º 7
0
 def test_update_code(self):
     c = self.login()
     models.Avatar(owner=self.user, code="test", game=self.game).save()
     response = c.post(reverse("kurono/code", kwargs={"id": 1}),
                       {"code": self.CODE})
     self.assertEqual(response.status_code, 200)
     self.assertEqual(
         models.Avatar.objects.get(owner__username="******").code, self.CODE)
Exemplo n.º 8
0
 def test_update_code(self):
     c = self.login()
     models.Avatar(owner=self.user, code='test', game=self.game).save()
     response = c.post(reverse('aimmo/code', kwargs={'id': 1}),
                       {'code': self.CODE})
     self.assertEqual(response.status_code, 200)
     self.assertEqual(
         models.Avatar.objects.get(owner__username='******').code, self.CODE)
Exemplo n.º 9
0
 def test_retrieve_code(self):
     models.Avatar(owner=self.user, code=self.CODE, game=self.game).save()
     c = self.login()
     response = c.get(reverse("kurono/code", kwargs={"id": 1}))
     self.assertEqual(response.status_code, 200)
     self.assertJSONEqual(
         response.content,
         {
             "code": self.CODE,
             "starterCode": self.game.worksheet.starter_code
         },
     )
Exemplo n.º 10
0
    def test_current_avatar_api_call_returns_404_for_logged_out_user(self):
        user = self.user
        models.Avatar(owner=user, code=self.CODE, game=self.game).save()
        client_one = Client()

        self.game.public = True
        self.game.can_play = [user]
        self.game.save()

        first_response = client_one.get(
            reverse("kurono/current_avatar_in_game", kwargs={"game_id": 1}))

        self.assertEqual(first_response.status_code, 404)
Exemplo n.º 11
0
    def test_connection_parameters_api_call_returns_404_for_logged_out_user(
            self):
        user = self.user
        models.Avatar(owner=user, code=self.CODE, game=self.game).save()
        client_one = Client()

        self.game.public = True
        self.game.can_play.set([user])
        self.game.save()

        first_response = client_one.get(
            reverse("kurono/connection_parameters", kwargs={"game_id": 1}))

        assert first_response.status_code == 403
Exemplo n.º 12
0
    def test_update_game_worksheet_updates_avatar_codes(
            self, mock_game_manager):
        # Set up the first avatar
        first_user = self.user
        models.Avatar(owner=first_user, code=self.CODE, game=self.game).save()
        client1 = self.login()

        # Set up the second avatar
        _, _, second_user = create_school_student_directly(
            self.klass.access_code)
        models.Avatar(owner=second_user.new_user,
                      code=self.CODE,
                      game=self.game).save()

        client2 = Client()
        client2.login(username="******", password="******")

        data = json.dumps({"worksheet_id": self.worksheet2.id})

        response = client1.put(
            reverse("game-detail", kwargs={"pk": self.game.id}),
            data,
            content_type="application/json",
        )

        # GameManager is called when a game is edited.
        assert mock_game_manager.called
        assert response.status_code == 200

        game = models.Game.objects.get(id=1)
        avatar1 = models.Avatar.objects.get(id=1)
        avatar2 = models.Avatar.objects.get(id=2)

        assert game.worksheet == self.worksheet2

        assert avatar1.code == self.worksheet2.starter_code
        assert avatar2.code == self.worksheet2.starter_code
Exemplo n.º 13
0
 def test_retrieve_code(self):
     models.Avatar(owner=self.user, code=self.CODE, game=self.game).save()
     c = self.login()
     response = c.get(reverse('aimmo/code', kwargs={'id': 1}))
     self.assertEqual(response.status_code, 200)
     self.assertJSONEqual(response.content, {'code': self.CODE})