def test_get_report_if_exists_invalid_identifier(self):
     populator = ReportPopulator(submission={},
                                 agency=Agency.objects.get(pk=5),
                                 user=self.user)
     populator.submission = {'local_identifier': "Random Non existent ID"}
     populator.get_report_if_exists()
     self.assertIsNone(populator.report)
 def test_get_report_if_exists_valid_identifier(self):
     populator = ReportPopulator(submission={},
                                 agency=Agency.objects.get(pk=5),
                                 user=self.user)
     populator.submission = {'local_identifier': "EQARAG0021-EQARIN0001-01"}
     populator.get_report_if_exists()
     self.assertEqual(populator.report.id, 1)
Exemple #3
0
 def _report_upsert(self):
     """
     Create or insert Report instance.
     """
     rp = ReportPopulator(self.data, self.agency, self.user)
     rp.populate()
     self.report = rp.report
 def test_report_link_upsert(self):
     populator = ReportPopulator(submission={},
                                 agency=Agency.objects.get(pk=5),
                                 user=self.user)
     esg_activity = AgencyESGActivity.objects.get(pk=1)
     status = ReportStatus.objects.get(pk=2)
     decision = ReportDecision.objects.get(pk=1)
     populator.submission = {
         'local_identifier':
         "EQARAG0021-EQARIN0001-01",
         'esg_activity':
         esg_activity,
         'status':
         status,
         'decision':
         decision,
         'valid_from':
         '2008-10-10',
         'report_links': [{
             "link": "http://example.com"
         }, {
             "link": "http://example2.com",
             "link_display_name": "Link display name example"
         }]
     }
     populator.get_report_if_exists()
     populator._report_upsert()
     populator._report_link_upsert()
     self.assertEqual(populator.report.reportlink_set.count(), 2)
     self.assertEqual(
         populator.report.reportlink_set.first().link_display_name,
         "View report record on agency site")
 def test_report_file_upsert(self):
     populator = ReportPopulator(submission={},
                                 agency=Agency.objects.get(pk=5),
                                 user=self.user)
     esg_activity = AgencyESGActivity.objects.get(pk=1)
     status = ReportStatus.objects.get(pk=2)
     decision = ReportDecision.objects.get(pk=1)
     populator.submission = {
         'local_identifier':
         "EQARAG0021-EQARIN0001-01",
         'esg_activity':
         esg_activity,
         'status':
         status,
         'decision':
         decision,
         'valid_from':
         '2008-10-10',
         'report_files': [{
             "original_location": "http://example.com/example.pdf",
             "report_language": [Language.objects.get(pk=1)]
         }, {
             "original_location":
             "http://example2.com/example2.pdf",
             "display_name":
             "2nd example document",
             "report_language":
             [Language.objects.get(pk=1),
              Language.objects.get(pk=2)]
         }]
     }
     populator.get_report_if_exists()
     populator._report_upsert()
     populator._report_file_upsert()
     self.assertEqual(populator.report.reportfile_set.count(), 2)
     self.assertEqual(
         populator.report.reportfile_set.all()[0].file_display_name,
         "example.pdf")
     self.assertEqual(
         populator.report.reportfile_set.all()[1].file_display_name,
         "2nd example document")
     self.assertEqual(
         populator.report.reportfile_set.all()[0].languages.count(), 1)
     self.assertEqual(
         populator.report.reportfile_set.all()[1].languages.count(), 2)
 def test_report_upsert_existing_report(self):
     populator = ReportPopulator(submission={},
                                 agency=Agency.objects.get(pk=5),
                                 user=self.user)
     esg_activity = AgencyESGActivity.objects.get(pk=1)
     status = ReportStatus.objects.get(pk=2)
     decision = ReportDecision.objects.get(pk=1)
     populator.submission = {
         'local_identifier': "EQARAG0021-EQARIN0001-01",
         'esg_activity': esg_activity,
         'status': status,
         'decision': decision,
         'valid_from': '2008-10-10'
     }
     populator.get_report_if_exists()
     populator._report_upsert()
     self.assertEqual(populator.report.status.id, 2)
 def test_repot_upsert_non_existing_report(self):
     populator = ReportPopulator(submission={},
                                 agency=Agency.objects.get(pk=5),
                                 user=self.user)
     esg_activity = AgencyESGActivity.objects.get(pk=1)
     status = ReportStatus.objects.get(pk=2)
     decision = ReportDecision.objects.get(pk=1)
     populator.submission = {
         'local_identifier': "NonExistingReportID",
         'esg_activity': esg_activity,
         'status': status,
         'decision': decision,
         'valid_from': '2008-10-10'
     }
     populator.get_report_if_exists()
     populator._report_upsert()
     report = Report.objects.get(local_identifier='NonExistingReportID')
     self.assertEqual(report.status_id, 2)
 def test_init(self):
     populator = ReportPopulator(submission={},
                                 agency=Agency.objects.get(pk=5),
                                 user=self.user)
     settings.TEST_RUNNER = 'djcelery.contrib.test_runner.CeleryTestSuiteRunner'
     self.assertEqual(populator.agency.acronym_primary, "ACQUIN")