Ejemplo n.º 1
0
    def test_rating_assignation(self):
        """Check ratings are correctly assigned to an exploration"""

        self.exploration = exp_domain.Exploration.create_default_exploration(
            self.EXP_ID, 'A title', 'A category')
        exp_services.save_new_exploration(self.EXP_ID, self.exploration)

        self.assertEqual(
            rating_services.get_overall_ratings(self.EXP_ID),
            {'1': 0, '2': 0, '3': 0, '4': 0, '5': 0})

        self.assertEqual(
            rating_services.get_user_specific_rating(
                self.USER_ID_1, self.EXP_ID), None)

        rating_services.assign_rating(self.USER_ID_1, self.EXP_ID, 2)
        rating_services.assign_rating(self.USER_ID_2, self.EXP_ID, 4)
        rating_services.assign_rating(self.USER_ID_1, self.EXP_ID, 3)

        self.assertEqual(
            rating_services.get_user_specific_rating(
                self.USER_ID_1, self.EXP_ID), 3)
        self.assertEqual(
            rating_services.get_user_specific_rating(
                self.USER_ID_2, self.EXP_ID), 4)
        self.assertEqual(
            rating_services.get_overall_ratings(self.EXP_ID),
            {'1': 0, '2': 0, '3': 1, '4': 1, '5': 0})

        rating_services.assign_rating(self.USER_ID_1, self.EXP_ID, 4)

        self.assertEqual(
            rating_services.get_overall_ratings(self.EXP_ID),
            {'1': 0, '2': 0, '3': 0, '4': 2, '5': 0})
Ejemplo n.º 2
0
    def test_rating_assignation(self):
        """Check ratings are correctly assigned to an exploration"""

        self.exploration = exp_domain.Exploration.create_default_exploration(
            self.EXP_ID, 'A title', 'A category')
        exp_services.save_new_exploration(self.EXP_ID, self.exploration)

        self.assertEqual(
            rating_services.get_overall_ratings(self.EXP_ID),
            {'1': 0, '2': 0, '3': 0, '4': 0, '5': 0})

        self.assertEqual(
            rating_services.get_user_specific_rating(
                self.USER_ID_1, self.EXP_ID), None)

        rating_services.assign_rating(self.USER_ID_1, self.EXP_ID, 2)
        rating_services.assign_rating(self.USER_ID_2, self.EXP_ID, 4)
        rating_services.assign_rating(self.USER_ID_1, self.EXP_ID, 3)

        self.assertEqual(
            rating_services.get_user_specific_rating(
                self.USER_ID_1, self.EXP_ID), 3)
        self.assertEqual(
            rating_services.get_user_specific_rating(
                self.USER_ID_2, self.EXP_ID), 4)
        self.assertEqual(
            rating_services.get_overall_ratings(self.EXP_ID),
            {'1': 0, '2': 0, '3': 1, '4': 1, '5': 0})

        rating_services.assign_rating(self.USER_ID_1, self.EXP_ID, 4)

        self.assertEqual(
            rating_services.get_overall_ratings(self.EXP_ID),
            {'1': 0, '2': 0, '3': 0, '4': 2, '5': 0})
Ejemplo n.º 3
0
    def test_rating_assignations_do_not_conflict(self):
        """Check that ratings of different explorations are independant."""

        EXP_ID_A = 'exp_id_A'
        EXP_ID_B = 'exp_id_B'

        self.exploration = exp_domain.Exploration.create_default_exploration(
            EXP_ID_A, 'A title', 'A category')
        exp_services.save_new_exploration(EXP_ID_A, self.exploration)
        self.exploration = exp_domain.Exploration.create_default_exploration(
            EXP_ID_B, 'A title', 'A category')
        exp_services.save_new_exploration(EXP_ID_B, self.exploration)

        rating_services.assign_rating(self.USER_ID_1, EXP_ID_A, 1)
        rating_services.assign_rating(self.USER_ID_1, EXP_ID_B, 3)
        rating_services.assign_rating(self.USER_ID_2, EXP_ID_A, 2)
        rating_services.assign_rating(self.USER_ID_2, EXP_ID_B, 5)

        self.assertEqual(
            rating_services.get_user_specific_rating(self.USER_ID_1, EXP_ID_A),
            1)
        self.assertEqual(
            rating_services.get_user_specific_rating(self.USER_ID_1, EXP_ID_B),
            3)
        self.assertEqual(
            rating_services.get_user_specific_rating(self.USER_ID_2, EXP_ID_A),
            2)
        self.assertEqual(
            rating_services.get_user_specific_rating(self.USER_ID_2, EXP_ID_B),
            5)

        self.assertEqual(rating_services.get_overall_ratings(EXP_ID_A), {
            '1': 1,
            '2': 1,
            '3': 0,
            '4': 0,
            '5': 0
        })
        self.assertEqual(rating_services.get_overall_ratings(EXP_ID_B), {
            '1': 0,
            '2': 0,
            '3': 1,
            '4': 0,
            '5': 1
        })
Ejemplo n.º 4
0
 def get(self, exploration_id):
     """Handles GET requests."""
     self.values.update({
         'overall_ratings':
             rating_services.get_overall_ratings(exploration_id),
         'user_rating': rating_services.get_user_specific_rating(
             self.user_id, exploration_id) if self.user_id else None
     })
     self.render_json(self.values)
Ejemplo n.º 5
0
    def test_rating_assignation(self):
        """Check ratings are correctly assigned to an exploration"""

        self.exploration = exp_domain.Exploration.create_default_exploration(self.EXP_ID, "A title", "A category")
        exp_services.save_new_exploration(self.EXP_ID, self.exploration)

        self.assertEqual(rating_services.get_overall_ratings(self.EXP_ID), {"1": 0, "2": 0, "3": 0, "4": 0, "5": 0})

        self.assertEqual(rating_services.get_user_specific_rating(self.USER_ID_1, self.EXP_ID), None)

        rating_services.assign_rating(self.USER_ID_1, self.EXP_ID, 2)
        rating_services.assign_rating(self.USER_ID_2, self.EXP_ID, 4)
        rating_services.assign_rating(self.USER_ID_1, self.EXP_ID, 3)

        self.assertEqual(rating_services.get_user_specific_rating(self.USER_ID_1, self.EXP_ID), 3)
        self.assertEqual(rating_services.get_user_specific_rating(self.USER_ID_2, self.EXP_ID), 4)
        self.assertEqual(rating_services.get_overall_ratings(self.EXP_ID), {"1": 0, "2": 0, "3": 1, "4": 1, "5": 0})

        rating_services.assign_rating(self.USER_ID_1, self.EXP_ID, 4)

        self.assertEqual(rating_services.get_overall_ratings(self.EXP_ID), {"1": 0, "2": 0, "3": 0, "4": 2, "5": 0})
Ejemplo n.º 6
0
    def test_rating_assignations_do_not_conflict(self):
        """Check that ratings of different explorations are independant."""

        EXP_ID_A = "exp_id_A"
        EXP_ID_B = "exp_id_B"

        self.exploration = exp_domain.Exploration.create_default_exploration(EXP_ID_A, "A title", "A category")
        exp_services.save_new_exploration(EXP_ID_A, self.exploration)
        self.exploration = exp_domain.Exploration.create_default_exploration(EXP_ID_B, "A title", "A category")
        exp_services.save_new_exploration(EXP_ID_B, self.exploration)

        rating_services.assign_rating(self.USER_ID_1, EXP_ID_A, 1)
        rating_services.assign_rating(self.USER_ID_1, EXP_ID_B, 3)
        rating_services.assign_rating(self.USER_ID_2, EXP_ID_A, 2)
        rating_services.assign_rating(self.USER_ID_2, EXP_ID_B, 5)

        self.assertEqual(rating_services.get_user_specific_rating(self.USER_ID_1, EXP_ID_A), 1)
        self.assertEqual(rating_services.get_user_specific_rating(self.USER_ID_1, EXP_ID_B), 3)
        self.assertEqual(rating_services.get_user_specific_rating(self.USER_ID_2, EXP_ID_A), 2)
        self.assertEqual(rating_services.get_user_specific_rating(self.USER_ID_2, EXP_ID_B), 5)

        self.assertEqual(rating_services.get_overall_ratings(EXP_ID_A), {"1": 1, "2": 1, "3": 0, "4": 0, "5": 0})
        self.assertEqual(rating_services.get_overall_ratings(EXP_ID_B), {"1": 0, "2": 0, "3": 1, "4": 0, "5": 1})
Ejemplo n.º 7
0
    def test_rating_assignations_do_not_conflict(self):
        """Check that ratings of different explorations are independant."""

        EXP_ID_A = 'exp_id_A'
        EXP_ID_B = 'exp_id_B'

        self.exploration = exp_domain.Exploration.create_default_exploration(
            EXP_ID_A, 'A title', 'A category')
        exp_services.save_new_exploration(EXP_ID_A, self.exploration)
        self.exploration = exp_domain.Exploration.create_default_exploration(
            EXP_ID_B, 'A title', 'A category')
        exp_services.save_new_exploration(EXP_ID_B, self.exploration)

        rating_services.assign_rating(self.USER_ID_1, EXP_ID_A, 1)
        rating_services.assign_rating(self.USER_ID_1, EXP_ID_B, 3)
        rating_services.assign_rating(self.USER_ID_2, EXP_ID_A, 2)
        rating_services.assign_rating(self.USER_ID_2, EXP_ID_B, 5)

        self.assertEqual(
            rating_services.get_user_specific_rating(
                self.USER_ID_1, EXP_ID_A), 1)
        self.assertEqual(
            rating_services.get_user_specific_rating(
                self.USER_ID_1, EXP_ID_B), 3)
        self.assertEqual(
            rating_services.get_user_specific_rating(
                self.USER_ID_2, EXP_ID_A), 2)
        self.assertEqual(
            rating_services.get_user_specific_rating(
                self.USER_ID_2, EXP_ID_B), 5)

        self.assertEqual(
            rating_services.get_overall_ratings(EXP_ID_A),
            {'1': 1, '2': 1, '3': 0, '4': 0, '5': 0})
        self.assertEqual(
            rating_services.get_overall_ratings(EXP_ID_B),
            {'1': 0, '2': 0, '3': 1, '4': 0, '5': 1})