コード例 #1
0
 def test_pdf_full_report_is_generated(self):
     report = PDFFullReport(self.report, self.decrypted_report)
     output = report.generate_pdf_report(recipient=None, report_id=None)
     exported_report = BytesIO(output)
     pdfReader = PyPDF2.PdfFileReader(exported_report)
     self.assertIn("Submitted by: dummy", pdfReader.getPage(0).extractText())
     self.assertIn("test answer", pdfReader.getPage(1).extractText())
     self.assertIn("answer to 2nd question", pdfReader.getPage(1).extractText())
コード例 #2
0
 def test_user_identifier(self):
     user_with_email = User.objects.create_user(username="******", password="******", email="*****@*****.**")
     report = Report(owner=user_with_email)
     report.encrypt_report(self.decrypted_report, "a key a key a key")
     report.save()
     pdf_report = PDFFullReport(report, self.decrypted_report)
     output = pdf_report.generate_pdf_report(recipient=None, report_id=None)
     exported_report = BytesIO(output)
     pdfReader = PyPDF2.PdfFileReader(exported_report)
     self.assertIn("Submitted by: [email protected]", pdfReader.getPage(0).extractText())
コード例 #3
0
 def test_submission_to_school(self):
     EmailNotification.objects.create(name='report_delivery', subject="test delivery", body="test body")
     report = PDFFullReport(self.report, self.decrypted_report)
     report.send_report_to_school()
     sent_report_id = SentFullReport.objects.latest('id').get_report_id()
     self.assertEqual(len(mail.outbox), 1)
     message = mail.outbox[0]
     self.assertEqual(message.subject, 'test delivery')
     self.assertIn('"Reports" <reports', message.from_email)
     self.assertEqual(message.attachments[0][0], 'report_%s.pdf.gpg' % sent_report_id)
コード例 #4
0
 def test_pdf_full_report_is_generated(self):
     report = PDFFullReport(self.report, self.decrypted_report)
     output = report.generate_pdf_report(recipient=None, report_id=None)
     exported_report = BytesIO(output)
     pdfReader = PyPDF2.PdfFileReader(exported_report)
     self.assertIn("Submitted by: dummy",
                   pdfReader.getPage(0).extractText())
     self.assertIn("test answer", pdfReader.getPage(1).extractText())
     self.assertIn("answer to 2nd question",
                   pdfReader.getPage(1).extractText())
コード例 #5
0
 def test_pdf_report_generated_with_timestamp(self):
     # test_tzname matches TIME_ZONE in tests/settings.py
     test_tzname = 'Europe/Paris'
     report = PDFFullReport(self.report, self.decrypted_report)
     output = report.generate_pdf_report(recipient=None, report_id=None)
     exported_report = BytesIO(output)
     pdfReader = PyPDF2.PdfFileReader(exported_report)
     date_format = "%m/%d/%Y @%H:%M%p"
     timezone.activate(pytz.timezone(test_tzname))
     expected_time = localtime(timezone.now()).strftime(date_format)
     self.assertIn(expected_time, pdfReader.getPage(0).extractText())
コード例 #6
0
 def test_user_identifier(self):
     user_with_email = User.objects.create_user(username="******",
                                                password="******",
                                                email="*****@*****.**")
     report = Report(owner=user_with_email)
     report.encrypt_report(self.decrypted_report, "a key a key a key")
     report.save()
     pdf_report = PDFFullReport(report, self.decrypted_report)
     output = pdf_report.generate_pdf_report(recipient=None, report_id=None)
     exported_report = BytesIO(output)
     pdfReader = PyPDF2.PdfFileReader(exported_report)
     self.assertIn("Submitted by: [email protected]",
                   pdfReader.getPage(0).extractText())
コード例 #7
0
 def test_submission_to_school(self):
     EmailNotification.objects.create(name='report_delivery',
                                      subject="test delivery",
                                      body="test body")
     report = PDFFullReport(self.report, self.decrypted_report)
     report.send_report_to_school()
     sent_report_id = SentFullReport.objects.latest('id').get_report_id()
     self.assertEqual(len(mail.outbox), 1)
     message = mail.outbox[0]
     self.assertEqual(message.subject, 'test delivery')
     self.assertIn('"Reports" <reports', message.from_email)
     self.assertEqual(message.attachments[0][0],
                      'report_%s.pdf.gpg' % sent_report_id)