Example #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)
Example #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)
Example #3
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"))