本文整理汇总了Python中callisto.delivery.models.Report类的典型用法代码示例。如果您正苦于以下问题:Python Report类的具体用法?Python Report怎么用?Python Report使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Report类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_done_saves_anonymised_qs
def test_done_saves_anonymised_qs(self, mockReport):
self.maxDiff = None
radio_button_q = RadioButton.objects.create(text="this is a radio button question", page=self.page2)
for i in range(5):
Choice.objects.create(text="This is choice %i" % i, question=radio_button_q)
wizard = EncryptedFormWizard.wizard_factory()()
PageOneForm = wizard.form_list[0]
PageTwoForm = wizard.form_list[1]
KeyForm = wizard.form_list[2]
page_one = PageOneForm({'question_%i' % self.question1.pk: 'test answer'})
page_one.is_valid()
page_two = PageTwoForm({'question_%i' % self.question2.pk: 'another answer to a different question',
'question_%i' % radio_button_q.pk: radio_button_q.choice_set.all()[2].pk})
page_two.is_valid()
key_form = KeyForm({'key': self.report_key, 'key2': self.report_key})
key_form.is_valid()
mock_report = Report()
mock_report.save = Mock()
mock_report.owner = self.request.user
mockReport.return_value = mock_report
self._get_wizard_response(wizard, form_list=[page_one, page_two, key_form], request=self.request)
示例2: test_no_times_by_default
def test_no_times_by_default(self):
report = Report(owner=self.user)
report.encrypt_report("test report", "key")
report.save()
self.assertIsNone(Report.objects.first().last_edited)
self.assertIsNone(Report.objects.first().submitted_to_school)
self.assertIsNone(Report.objects.first().entered_into_matching)
示例3: ExistingRecordTest
class ExistingRecordTest(RecordFormBaseTest):
def setUp(self):
super(ExistingRecordTest, self).setUp()
User.objects.create_user(username='dummy', password='dummy')
self.client.login(username='dummy', password='dummy')
self.request = HttpRequest()
self.request.GET = {}
self.request.method = 'GET'
self.request.user = User.objects.get(username='dummy')
self.report_text = """[
{ "answer": "test answer",
"id": %i,
"section": 1,
"question_text": "first question",
"type": "SingleLineText"
},
{ "answer": "another answer to a different question",
"id": %i,
"section": 1,
"question_text": "2nd question",
"type": "SingleLineText"
}
]""" % (self.question1.pk, self.question2.pk)
self.report = Report(owner=self.request.user)
self.report_key = 'bananabread! is not my key'
self.report.encrypt_report(self.report_text, self.report_key)
self.report.save()
row = EvalRow()
row.anonymise_record(action=EvalRow.CREATE, report=self.report, decrypted_text=self.report_text)
row.save()
示例4: test_can_decrypt_report
def test_can_decrypt_report(self):
report = Report(owner=self.user)
report.encrypt_report("this text should be encrypted, yes it should by golly!", key='this is my key')
report.save()
saved_report = Report.objects.first()
self.assertEqual(saved_report.decrypted_report('this is my key'),
"this text should be encrypted, yes it should by golly!")
示例5: MatchReportTest
class MatchReportTest(TestCase):
def setUp(self):
self.user = User.objects.create_user(username="dummy", password="dummy")
self.report = Report(owner=self.user)
self.report.encrypt_report("test report", "key")
self.report.save()
match_report = MatchReport(report=self.report, identifier='dummy')
match_report.encrypt_match_report("test match report", match_report.identifier)
match_report.save()
def test_entered_into_matching_property_is_set(self):
self.assertIsNotNone(Report.objects.first().entered_into_matching)
def test_entered_into_matching_is_blank_before_entering_into_matching(self):
report = Report(owner=self.user)
report.encrypt_report("test non-matching report", "key")
report.save()
self.assertIsNone(Report.objects.get(pk=report.id).entered_into_matching)
def test_can_encrypt_match_report(self):
saved_match_report = MatchReport.objects.first()
self.assertIsNotNone(saved_match_report.salt)
self.assertNotEqual(saved_match_report.salt, '')
self.assertIsNotNone(saved_match_report.encrypted)
self.assertTrue(len(saved_match_report.encrypted) > 0)
def test_can_decrypt_match_report(self):
saved_match_report = MatchReport.objects.first()
self.assertEqual(saved_match_report.get_match('dummy'), "test match report")
示例6: test_deleted_report_doesnt_delete_sent_match_report
def test_deleted_report_doesnt_delete_sent_match_report(self):
match_report = MatchReport(report=self.report, identifier='dummy')
match_report.encrypt_match_report("test match report", 'dummy')
match_report.save()
user2 = User.objects.create_user(username="dummy2", password="dummy")
report2 = Report(owner=user2)
report2.encrypt_report("test report 2", "key")
report2.save()
match_report2 = MatchReport(report=report2, identifier='dummy')
match_report2.encrypt_match_report("test match report 2", 'dummy')
match_report2.save()
sent_match_report = SentMatchReport.objects.create()
sent_match_report.reports.add(match_report, match_report2)
self.report.match_found = True
self.report.save()
report2.match_found = True
report2.save()
self.assertIsNotNone(match_report.sentmatchreport_set.first())
self.assertIsNotNone(match_report2.sentmatchreport_set.first())
self.assertEqual(match_report, SentMatchReport.objects.first().reports.all()[0])
self.assertEqual(match_report2, SentMatchReport.objects.first().reports.all()[1])
self.report.delete()
self.assertEqual(Report.objects.count(), 1)
self.assertEqual(MatchReport.objects.count(), 1)
self.assertEqual(SentMatchReport.objects.first(), sent_match_report)
self.assertEqual(SentMatchReport.objects.first().reports.count(), 1)
self.assertEqual(SentMatchReport.objects.first().reports.first(), match_report2)
self.assertTrue(Report.objects.first().match_found)
report2.delete()
self.assertEqual(Report.objects.count(), 0)
self.assertEqual(SentMatchReport.objects.first(), sent_match_report)
示例7: test_entered_into_matching_property_is_set
def test_entered_into_matching_property_is_set(self):
report = Report(owner = self.user)
report.encrypt_report("test report", "key")
report.save()
MatchReport.objects.create(report = report, contact_phone='phone',
contact_email='[email protected]', identifier='dummy')
self.assertIsNotNone(Report.objects.first().entered_into_matching)
示例8: EvalActionTest
class EvalActionTest(MatchTest):
def setUp(self):
super(EvalActionTest, self).setUp()
self.client.login(username='dummy', password='dummy')
self.request = HttpRequest()
self.request.GET = {}
self.request.method = 'GET'
self.request.user = User.objects.get(username='dummy')
self.report_text = json.dumps({'test_question': 'test answer'})
self.key = 'a key a key a key'
self.report = Report(owner=self.user1)
self.report.encrypt_report(self.report_text, self.key)
self.report.save()
@patch('callisto.delivery.views.run_matching')
@patch('callisto.delivery.views.EvalRow.anonymise_record')
def test_submission_to_matching_creates_eval_row(self, mock_anonymise_record, mock_run_matching):
response = self.client.post(('/test_reports/match/%s/' % self.report.pk),
data={'name': 'test submitter',
'email': '[email protected]',
'phone_number': '555-555-1212',
'email_confirmation': "False",
'key': self.key,
'form-0-perp': 'facebook.com/test_url',
'form-TOTAL_FORMS': '1',
'form-INITIAL_FORMS': '1',
'form-MAX_NUM_FORMS': '', })
self.assertEqual(response.status_code, 200)
self.assertNotIn('submit_error', response.context)
mock_anonymise_record.assert_called_with(action=EvalRow.MATCH, report=self.report, match_identifier="test_url",
decrypted_text=None)
@patch('callisto.delivery.matching.EvalRow.anonymise_record')
@patch('callisto.delivery.matching.send_notification_email')
@patch('callisto.delivery.matching.PDFMatchReport.send_matching_report_to_school')
def test_match_trigger_creates_eval_row(self, mock_send_to_school, mock_notify, mock_anonymise_record):
match1 = self.create_match(self.user1, 'dummy')
match2 = self.create_match(self.user2, 'dummy')
run_matching()
call1 = call(action=EvalRow.MATCH_FOUND, report=match1.report, decrypted_text=None, match_identifier=None)
call2 = call(action=EvalRow.MATCH_FOUND, report=match2.report, decrypted_text=None, match_identifier=None)
mock_anonymise_record.assert_has_calls([call1, call2])
@patch('callisto.delivery.views.EvalRow.anonymise_record')
@patch('callisto.delivery.report_delivery.PDFFullReport.send_report_to_school')
def test_submit_creates_eval_row(self, mock_send_report, mock_anonymise_record):
response = self.client.post(('/test_reports/submit/%s/' % self.report.pk),
data={'name': 'test submitter',
'email': '[email protected]',
'phone_number': '555-555-1212',
'email_confirmation': "False",
'key': self.key})
self.assertEqual(response.status_code, 200)
self.assertNotIn('submit_error', response.context)
mock_anonymise_record.assert_called_with(action=EvalRow.SUBMIT, report=self.report, decrypted_text=None,
match_identifier=None)
示例9: test_match_sends_report_immediately
def test_match_sends_report_immediately(self):
self.client.post((self.submission_url % self.report.pk),
data={'name': 'test submitter 1',
'email': '[email protected]',
'phone_number': '555-555-1212',
'email_confirmation': "False",
'key': self.report_key,
'form-0-perp': 'facebook.com/triggered_match',
'form-TOTAL_FORMS': '1',
'form-INITIAL_FORMS': '1',
'form-MAX_NUM_FORMS': '', })
user2 = User.objects.create_user(username='dummy2', password='dummy')
self.client.login(username='dummy2', password='dummy')
report2_text = """[
{ "answer": "test answer",
"id": %i,
"section": 1,
"question_text": "first question",
"type": "SingleLineText"
},
{ "answer": "another answer to a different question",
"id": %i,
"section": 1,
"question_text": "2nd question",
"type": "SingleLineText"
}
]""" % (self.question1.pk, self.question2.pk)
report2 = Report(owner=user2)
report2_key = 'a key a key a key a key key'
report2.encrypt_report(report2_text, report2_key)
report2.save()
response = self.client.post((self.submission_url % report2.pk),
data={'name': 'test submitter 2',
'email': '[email protected]',
'phone_number': '555-555-1213',
'email_confirmation': "False",
'key': report2_key,
'form-0-perp': 'facebook.com/triggered_match',
'form-TOTAL_FORMS': '1',
'form-INITIAL_FORMS': '1',
'form-MAX_NUM_FORMS': '', })
self.assertNotIn('submit_error', response.context)
self.assertEqual(len(mail.outbox), 3)
message = mail.outbox[0]
self.assertEqual(message.subject, 'test match notification')
self.assertEqual(message.to, ['[email protected]'])
self.assertIn('Matching" <[email protected]', message.from_email)
self.assertIn('test match notification body', message.body)
message = mail.outbox[1]
self.assertEqual(message.subject, 'test match notification')
self.assertEqual(message.to, ['[email protected]'])
self.assertIn('Matching" <[email protected]', message.from_email)
self.assertIn('test match notification body', message.body)
message = mail.outbox[2]
self.assertEqual(message.subject, 'test match delivery')
self.assertEqual(message.to, ['[email protected]'])
self.assertIn('"Reports" <[email protected]', message.from_email)
self.assertIn('test match delivery body', message.body)
self.assertRegexpMatches(message.attachments[0][0], 'report_.*\.pdf\.gpg')
示例10: test_can_decrypt_old_reports
def test_can_decrypt_old_reports(self):
legacy_report = LegacyReportData()
legacy_report.encrypt_report("this text should be encrypted otherwise bad things", key='this is my key')
report = Report(owner=self.user, encrypted=legacy_report.encrypted, salt=legacy_report.salt)
report.save()
saved_report = Report.objects.first()
self.assertEqual(saved_report.decrypted_report('this is my key'),
"this text should be encrypted otherwise bad things")
示例11: test_can_encrypt_report
def test_can_encrypt_report(self):
report = Report(owner=self.user)
report.encrypt_report("this text should be encrypted", key='this is my key')
report.save()
saved_report = Report.objects.first()
self.assertIsNotNone(saved_report.salt)
self.assertNotEqual(saved_report.salt, '')
self.assertIsNotNone(saved_report.encrypted)
self.assertTrue(len(saved_report.encrypted) > 0)
示例12: create_match
def create_match(self, user, identifier, match_report_content=None):
report = Report(owner=user)
report.encrypt_report("test report 1", "key")
report.save()
match_report = MatchReport(report=report, identifier=identifier)
match_report_object = match_report_content if match_report_content else MatchReportContent(
identifier='test', perp_name='test', email='[email protected]', phone="test")
match_report.encrypt_match_report(json.dumps(match_report_object.__dict__), identifier)
match_report.save()
return match_report
示例13: test_user_identifier
def test_user_identifier(self):
user_with_email = User.objects.create_user(username="email_dummy", password="dummy", email="[email protected]")
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())
示例14: test_edit_sets_edited_time
def test_edit_sets_edited_time(self):
report = Report(owner=self.user)
report.encrypt_report("test report", "key")
report.save()
report.encrypt_report("a different report", "key")
report.save()
self.assertIsNotNone(Report.objects.first().last_edited)
示例15: test_can_decrypt_old_match_report
def test_can_decrypt_old_match_report(self):
legacy_match_report = LegacyMatchReportData()
legacy_match_report.encrypt_match_report("test legacy match report", "dumbo")
legacy_report = LegacyReportData()
legacy_report.encrypt_report("this text should be encrypted otherwise bad things", key='this is my key')
report = Report(owner=self.user, encrypted=legacy_report.encrypted, salt=legacy_report.salt)
report.save()
new_match_report = MatchReport(report=report, encrypted=legacy_match_report.encrypted,
salt=legacy_match_report.salt, identifier="dumbo")
new_match_report.save()
self.assertEqual(new_match_report.get_match("dumbo"), "test legacy match report")