def handle_application_csv(csv_file): csv_file_text_mode = codecs.iterdecode(csv_file, "utf-8") csv_reader = csv.reader(csv_file_text_mode, delimiter=',') for row in csv_reader: try: email = row[0] date_commitment = True if row[1] == "1" else False name = row[2] faculty = row[3] other_faculty = row[4] project_name = row[5] idea = row[6] fit_for_blue = row[7] media_link = row[8] country = row[9] year = row[10] valid = True application = Application(email=email, date_commitment=date_commitment, name=name, faculty=faculty, other_faculty=other_faculty, project_name=project_name, idea=idea, fit_for_blue=fit_for_blue, media_link=media_link, country=country, year=year, valid=valid) application.full_clean() except ValidationError as e: """Fields are not valid.""" print('; '.join(e.messages)) return True, "The csv fields are not valid." else: application.save() return False, "Uploaded applications"
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)