def test_a_report_is_generated(self, mock_method): GENERATED_FILE_CONTENT = REPORT_TEMPLATE = b'some-content' mock_method.return_value = GENERATED_FILE_CONTENT report_template = ReportTemplateFactory(template__data=REPORT_TEMPLATE) user = UserFactory() instances = [ BackOfficeAssetFactory( user=UserFactory(first_name="James", last_name="Bond")) ] attachment = BackOfficeAsset._generate_report(report_template.name, user, instances, report_template.language) correct_filename = '{}_{}-{}_{}.pdf'.format( timezone.now().isoformat()[:10], 'james', 'bond', report_template.report.name, ) self.assertEqual(attachment.original_filename, correct_filename) self.assertEqual(attachment.file.read(), GENERATED_FILE_CONTENT)
def release_report(cls, instances, requester, transition_id, **kwargs): report_name = get_report_name_for_transition_id(transition_id) return BackOfficeAsset._generate_report( instances=instances, name=report_name, requester=requester, language=kwargs['report_language'] )