Пример #1
0
    def test_get_game_stats_after_creating_2_answers(self):
        # Create 2 answers
        url = "{}{}/user/{}/".format(self.url, self.game['id'], self.user.id)
        answers1 = [0, 2, 2]
        response1 = self.client.post(url, {'answers': answers1}, HTTP_AUTHORIZATION=self.user_token)
        self.assertEqual(202, response1.status_code)
        url = "{}{}/user/{}/".format(self.url, self.game['id'], self.another_user.id)
        answers2 = [0, 1, 0]
        response2 = self.client.post(url, {'answers': answers2}, HTTP_AUTHORIZATION=self.another_token)
        self.assertEqual(202, response2.status_code)

        game_answer1 = response1.data['data']
        self.assertEqual('Upstanding', game_answer1['ending'])
        game_answer2 = response2.data['data']
        self.assertEqual('<equal>', game_answer2['ending'])

        stats = GameSuperuserSerializer(
            Game.objects.get(id=self.game['id'])
        ).data['stats']
        self.assertEqual(stats['num_of_responses'], 2)

        expected_stats = [[2,0,0], [0,1,1], [0,0, 1]]
        self.assertTrue(self.traverse_to_check_stats(answers1, self.game, expected_stats))
        expected_stats = [[2,0,0], [0,1,1], [1,0,0]]
        self.assertTrue(self.traverse_to_check_stats(answers2, self.game, expected_stats))
        expected_end_stats = {
            '<equal>': 1,
            'Bullying': 0,
            'Ignoring': 0,
            'Upstanding': 1
        }
        self.assertEqual(expected_end_stats, stats['answers'][self.game['last_scene']])
Пример #2
0
    def test_create_an_answer_with_too_many_choices(self):
        url = "{}{}/user/{}/".format(self.url, self.game['id'], self.user.id)
        answers = [0, 0, 0, 1, 2, 1]
        response = self.client.post(url, {'answers': answers}, HTTP_AUTHORIZATION=self.user_token)
        self.assertEqual(202, response.status_code)
        stats = GameSuperuserSerializer(
            Game.objects.get(id=self.game['id'])
        ).data['stats']

        self.assertEqual(stats['num_of_responses'], 1)
        count = 0
        for ans in iter(stats['answers'].values()):
            if ans == [1, 0, 0]:
                count += 1
        self.assertEqual(count, 3)

        expected_stats = [[1,0,0], [1,0,0], [1,0,0]]
        self.assertTrue(self.traverse_to_check_stats(answers, self.game, expected_stats))
        expected_end_stats = {
            '<equal>': 1,
            'Bullying': 0,
            'Ignoring': 0,
            'Upstanding': 0
        }
        self.assertEqual(expected_end_stats, stats['answers'][self.game['last_scene']])
Пример #3
0
    def test_delete_a_game(self):
        url = "{}{}/".format(self.url, self.game['id'])
        response = self.client.delete(url, HTTP_AUTHORIZATION=self.superuser_token)
        self.assertEqual(202, response.status_code)

        all_games = GameSuperuserSerializer(Game.objects.all(), many=True).data
        self.assertEqual(0, len(all_games))
        al_scenes = GameSceneSerializer(GameScene.objects.all(), many=True).data
        self.assertEqual(0, len(al_scenes))
Пример #4
0
    def test_create_a_unfinished_answer(self):
        url = "{}{}/user/{}/".format(self.url, self.game['id'], self.user.id)
        answers = [2, 1]
        response = self.client.post(url, {'answers': answers}, HTTP_AUTHORIZATION=self.user_token)
        self.assertEqual(202, response.status_code)
        stats = GameSuperuserSerializer(
            Game.objects.get(id=self.game['id'])
        ).data['stats']

        self.assertEqual(stats['num_of_responses'], 1)
        expected_stats = [[0,0,1], [0,1,0]]
        self.assertTrue(self.traverse_to_check_stats(answers, self.game, expected_stats))
        self.assertTrue(all(ending == 0 for ending in stats['answers'][self.game['last_scene']].values()))
Пример #5
0
    def traverse_to_get_scenes_in_path(self, answer_data):
        game = GameSuperuserSerializer(Game.objects.get(id=answer_data['game'])).data
        scenes = self.populate_game_scenes_2(answer_data['game'])
        cur_scene = scenes[game['first_scene']]
        answer_scenes = {}

        for ans in iter(answer_data['answers']):
            if cur_scene['is_end'] or not 0 <= int(ans) < len(cur_scene['choices']):
                break

            answer_scenes[cur_scene['id']] = cur_scene
            next_scene_id = cur_scene['choices'][int(ans)]['pathway']
            cur_scene = scenes[next_scene_id]
        return answer_scenes
Пример #6
0
    def test_create_an_answer(self):
        url = "{}{}/user/{}/".format(self.url, self.game['id'], self.user.id)
        answers = [2, 1, 1]
        response = self.client.post(url, {'answers': answers}, HTTP_AUTHORIZATION=self.user_token)
        self.assertEqual(202, response.status_code)
        game_answer = response.data['data']
        self.assertEqual('Bullying', game_answer['ending'])

        stats = GameSuperuserSerializer(
            Game.objects.get(id=self.game['id'])
        ).data['stats']
        self.assertEqual(stats['num_of_responses'], 1)
        expected_stats = [[0,0,1], [0,1,0], [0,1,0]]
        self.assertTrue(self.traverse_to_check_stats(answers, self.game, expected_stats))
        expected_end_stats = {
            '<equal>': 0,
            'Bullying': 1,
            'Ignoring': 0,
            'Upstanding': 0
        }
        self.assertEqual(expected_end_stats, stats['answers'][self.game['last_scene']])