Esempio n. 1
0
    def test_doesnt_change_wave(self) -> None:
        self.create_active_wave()
        application = Application(**self.application_fields, wave=self.wave1)
        application.save()
        self.user.application = application
        self.user.save()
        self.application_fields["resume"] = SimpleUploadedFile(
            "resume2.pdf", b"dummy")

        self.client.post(
            reverse_lazy("application:update", args=(application.id, )),
            data=self.application_fields,
        )

        application.refresh_from_db()
        self.assertEqual(application.wave, self.wave1)
Esempio n. 2
0
    def test_only_owner_can_view_application(self) -> None:
        self.client.force_login(self.user2)
        self.create_active_wave()
        application = Application(**self.application_fields, wave=self.wave1)
        application.save()
        self.user.application = application
        self.user.save()
        new_first_name = "Mack"
        self.application_fields["first_name"] = new_first_name
        self.application_fields["resume"] = SimpleUploadedFile(
            "resume2.pdf", b"dummy")

        response: HttpResponse = self.client.post(
            reverse_lazy("application:update", args=(application.id, )),
            data=self.application_fields,
        )
        self.assertEqual(response.status_code, 403)
        application.refresh_from_db()
        self.assertNotEqual(application.first_name, new_first_name)
Esempio n. 3
0
    def test_actually_changes_application(self) -> None:
        self.client.force_login(self.user)
        self.create_active_wave()
        application = Application(**self.application_fields, wave=self.wave1)
        application.save()
        self.user.application = application
        self.user.save()
        new_first_name = "Mack"
        self.application_fields["first_name"] = new_first_name
        self.application_fields["resume"] = SimpleUploadedFile(
            "resume2.pdf", b"dummy")

        self.client.post(
            reverse_lazy("application:update", args=(application.id, )),
            data=self.application_fields,
        )

        application.refresh_from_db()
        self.assertEqual(application.first_name, new_first_name)
Esempio n. 4
0
class ApplicationAdminTestCase(test_case.SharedTestCase):
    def setUp(self):
        super().setUp()
        self.create_active_wave()
        self.app = Application(**self.application_fields, wave=self.wave1)
        self.app.full_clean()
        self.app.save()

    def test_approval_email_customizes_event_name(self):
        event_name = "BIGGEST HACKATHON EVER"
        with self.settings(EVENT_NAME=event_name):
            subject, *_ = build_approval_email(self.app, timezone.now())
            self.assertIn(event_name, subject)

    def test_approval_email_customizes_organizer_email(self):
        organizer_email = "*****@*****.**"
        with self.settings(ORGANIZER_EMAIL=organizer_email):
            _, message, *_ = build_approval_email(self.app, timezone.now())
            self.assertIn(organizer_email, message)

    def test_approval_email_customizes_user_first_name(self):
        _, message, *_ = build_approval_email(self.app, timezone.now())

        self.assertIn(self.app.first_name, message)

    def test_rejection_email_customizes_event_name(self):
        event_name = "BIGGEST HACKATHON EVER"
        with self.settings(EVENT_NAME=event_name):
            subject, *_ = build_rejection_email(self.app)
            self.assertIn(event_name, subject)

    def test_rejection_email_customizes_first_name(self):
        _, message, *_ = build_rejection_email(self.app)

        self.assertIn(self.app.first_name, message)

    def test_approval_action_approves_application(self):
        self.client.force_login(self.admin)
        change_url = reverse_lazy("admin:application_application_changelist")

        self.client.post(
            change_url,
            {
                "action": "approve",
                admin.ACTION_CHECKBOX_NAME: [self.app.pk]
            },
            follow=True,
        )

        self.app.refresh_from_db()
        self.assertEqual(self.app.status, STATUS_ADMITTED)

    def test_approval_action_sends_approval_email(self):
        self.client.force_login(self.admin)
        change_url = reverse_lazy("admin:application_application_changelist")

        self.client.post(change_url, {
            "action": "approve",
            admin.ACTION_CHECKBOX_NAME: [self.app.pk]
        })

        self.assertEqual(len(mail.outbox), 1)

    def test_reject_action_sends_rejection_email(self):
        self.client.force_login(self.admin)
        change_url = reverse_lazy("admin:application_application_changelist")

        self.client.post(
            change_url,
            {
                "action": "reject",
                admin.ACTION_CHECKBOX_NAME: [self.app.pk]
            },
            follow=True,
        )

        self.assertEqual(len(mail.outbox), 1)

    def test_reject_action_rejects_application(self):
        self.client.force_login(self.admin)
        change_url = reverse_lazy("admin:application_application_changelist")
        self.client.post(
            change_url,
            {
                "action": "reject",
                admin.ACTION_CHECKBOX_NAME: [self.app.pk]
            },
            follow=True,
        )
        self.app.refresh_from_db()
        self.assertEqual(self.app.status, STATUS_REJECTED)

    def test_export_application_emails(self):
        self.client.force_login(self.admin)
        change_url = reverse_lazy("admin:application_application_changelist")
        response = self.client.post(
            change_url,
            {
                "action": "export_application_emails",
                admin.ACTION_CHECKBOX_NAME: [self.app.pk],
            },
            follow=True,
        )
        self.assertEqual(response.status_code, 200)

    def test_resend_confirmation_email(self):
        self.client.force_login(self.admin)
        change_url = reverse_lazy("admin:application_application_changelist")
        response = self.client.post(
            change_url,
            {
                "action": "resend_confirmation",
                admin.ACTION_CHECKBOX_NAME: [self.app.pk],
            },
            follow=True,
        )
        self.assertEqual(response.status_code, 200)

        self.assertEqual(len(mail.outbox), 1)