Пример #1
0
class TestUpdateEducationGroupAchievement(TestCase):
    def setUp(self):
        self.education_group_year = EducationGroupYearFactory()

        self.achievement_0 = EducationGroupAchievementFactory(
            education_group_year=self.education_group_year)
        self.achievement_1 = EducationGroupAchievementFactory(
            education_group_year=self.education_group_year)
        self.achievement_2 = EducationGroupAchievementFactory(
            education_group_year=self.education_group_year)

        self.user = UserFactory()
        self.person = PersonFactory(user=self.user)
        self.user.user_permissions.add(
            Permission.objects.get(codename="can_access_education_group"))
        self.user.user_permissions.add(
            Permission.objects.get(
                codename="change_educationgroupachievement"))
        PersonEntityFactory(person=self.person,
                            entity=self.education_group_year.management_entity)
        self.client.force_login(self.user)

    def test_update(self):
        code = "The life is like a box of chocolates"
        response = self.client.post(reverse(
            "update_education_group_achievement",
            args=[
                self.education_group_year.pk,
                self.education_group_year.pk,
                self.achievement_2.pk,
            ]),
                                    data={"code_name": code})

        self.assertEqual(response.status_code, 302)
        self.achievement_2.refresh_from_db()
        self.assertEqual(self.achievement_2.code_name, code)

    def test_permission_denied(self):
        self.user.user_permissions.remove(
            Permission.objects.get(
                codename="change_educationgroupachievement"))
        code = "The life is like a box of chocolates"
        response = self.client.post(reverse(
            "update_education_group_achievement",
            args=[
                self.education_group_year.pk,
                self.education_group_year.pk,
                self.achievement_2.pk,
            ]),
                                    data={"code_name": code})

        self.assertEqual(response.status_code, 403)
Пример #2
0
class TestDeleteEducationGroupAchievement(TestCase):
    def setUp(self):

        self.education_group_year = EducationGroupYearFactory()

        self.achievement_0 = EducationGroupAchievementFactory(
            education_group_year=self.education_group_year)
        self.achievement_1 = EducationGroupAchievementFactory(
            education_group_year=self.education_group_year)
        self.achievement_2 = EducationGroupAchievementFactory(
            education_group_year=self.education_group_year)

        self.user = UserFactory()
        self.person = PersonFactory(user=self.user)
        self.user.user_permissions.add(
            Permission.objects.get(codename="can_access_education_group"))
        self.user.user_permissions.add(
            Permission.objects.get(
                codename="delete_educationgroupachievement"))
        PersonEntityFactory(person=self.person,
                            entity=self.education_group_year.management_entity)
        self.client.force_login(self.user)

    def test_delete(self):
        response = self.client.post(reverse(
            "delete_education_group_achievement",
            args=[
                self.education_group_year.pk,
                self.education_group_year.pk,
                self.achievement_0.pk,
            ]),
                                    data={})

        self.assertEqual(response.status_code, 302)
        with self.assertRaises(ObjectDoesNotExist):
            self.achievement_0.refresh_from_db()

    def test_permission_denied(self):
        self.user.user_permissions.remove(
            Permission.objects.get(
                codename="delete_educationgroupachievement"))
        response = self.client.post(reverse(
            "delete_education_group_achievement",
            args=[
                self.education_group_year.pk,
                self.education_group_year.pk,
                self.achievement_2.pk,
            ]),
                                    data={})

        self.assertEqual(response.status_code, 403)
Пример #3
0
 def setUp(self):
     self.education_group_year = EducationGroupYearFactory()
     self.education_group_achievement = EducationGroupAchievementFactory(
         education_group_year=self.education_group_year
     )
     self.education_group_detailed_achievement = EducationGroupDetailedAchievementFactory(
         education_group_achievement=self.education_group_achievement
     )
Пример #4
0
    def test_get_achievements(self):
        achievement = EducationGroupAchievementFactory(
            education_group_year=self.education_group_year)

        response = self._call_url_as_http_get()

        self.assertEqual(response.context["education_group_achievements"][0],
                         achievement)
Пример #5
0
    def setUpTestData(cls):
        cls.education_group_year = EducationGroupYearFactory()

        cls.achievement_0 = EducationGroupAchievementFactory(
            education_group_year=cls.education_group_year)
        cls.achievement_1 = EducationGroupAchievementFactory(
            education_group_year=cls.education_group_year)
        cls.achievement_2 = EducationGroupAchievementFactory(
            education_group_year=cls.education_group_year)

        cls.user = UserFactory()
        cls.person = PersonWithPermissionsFactory(
            'can_access_education_group',
            'change_educationgroupachievement',
            'delete_educationgroupachievement',
            user=cls.user)
        PersonEntityFactory(person=cls.person,
                            entity=cls.education_group_year.management_entity)
Пример #6
0
    def setUp(self):
        self.education_group_year = EducationGroupYearFactory()

        self.achievement_0 = EducationGroupAchievementFactory(
            education_group_year=self.education_group_year)
        self.achievement_1 = EducationGroupAchievementFactory(
            education_group_year=self.education_group_year)
        self.achievement_2 = EducationGroupAchievementFactory(
            education_group_year=self.education_group_year)

        self.user = UserFactory()
        self.person = PersonFactory(user=self.user)
        self.user.user_permissions.add(
            Permission.objects.get(codename="can_access_education_group"))
        self.user.user_permissions.add(
            Permission.objects.get(
                codename="change_educationgroupachievement"))
        PersonEntityFactory(person=self.person,
                            entity=self.education_group_year.management_entity)
        self.client.force_login(self.user)
Пример #7
0
    def test_create_detailed_achievement(self):
        code = "The life is like a box of chocolates"
        achievement = EducationGroupAchievementFactory(education_group_year=self.education_group_year)
        response = self.client.post(
            reverse(
                "create_education_group_detailed_achievement",
                args=[
                    self.education_group_year.pk,
                    self.education_group_year.pk,
                    achievement.pk,
                ]), data={"code_name": code}
        )

        self.assertEqual(response.status_code, 302)
        self.assertEqual(EducationGroupDetailedAchievement.objects.filter(education_group_achievement=achievement).count(), 1)
Пример #8
0
class TestEducationGroupAchievementAction(TestCase):
    def setUp(self):
        self.education_group_year = EducationGroupYearFactory()

        self.achievement_0 = EducationGroupAchievementFactory(
            education_group_year=self.education_group_year)
        self.achievement_1 = EducationGroupAchievementFactory(
            education_group_year=self.education_group_year)
        self.achievement_2 = EducationGroupAchievementFactory(
            education_group_year=self.education_group_year)

        self.user = UserFactory()
        self.person = PersonFactory(user=self.user)
        self.user.user_permissions.add(
            Permission.objects.get(codename="can_access_education_group"))
        self.user.user_permissions.add(
            Permission.objects.get(
                codename="change_educationgroupachievement"))
        PersonEntityFactory(person=self.person,
                            entity=self.education_group_year.management_entity)
        self.client.force_login(self.user)

    def test_form_valid_up(self):
        response = self.client.post(reverse(
            "education_group_achievements_actions",
            args=[
                self.education_group_year.pk,
                self.education_group_year.pk,
                self.achievement_2.pk,
            ]),
                                    data={"action": "up"})

        self.assertEqual(response.status_code, 302)
        self.achievement_2.refresh_from_db()
        self.assertEqual(self.achievement_2.order, 1)

    def test_form_valid_down(self):
        response = self.client.post(reverse(
            "education_group_achievements_actions",
            args=[
                self.education_group_year.pk,
                self.education_group_year.pk,
                self.achievement_0.pk,
            ]),
                                    data={"action": "down"})

        self.assertEqual(response.status_code, 302)
        self.achievement_0.refresh_from_db()
        self.assertEqual(self.achievement_0.order, 1)

    def test_form_invalid(self):
        response = self.client.post(reverse(
            "education_group_achievements_actions",
            args=[
                self.education_group_year.pk,
                self.education_group_year.pk,
                self.achievement_2.pk,
            ]),
                                    data={"action": "not_an_action"})

        self.assertEqual(response.status_code, 302)

        messages = [m.message for m in get_messages(response.wsgi_request)]
        self.assertEqual(messages[0], _("Invalid action"))
Пример #9
0
 def setUpTestData(cls):
     cls.achievement = EducationGroupAchievementFactory()
     cls.serializer = AchievementSerializer(cls.achievement)