def test_handle_agreement_document_generation_fail_when_agreement_does_not_exist_that_is_generating( slug, document_status, expected_status, ): agreement = AgreementFactory(slug='agreement-1', document_status=document_status) assert handle_agreement_document_generation_fail(None, None, None, [slug], None, None) is None agreement.refresh_from_db() assert agreement.document_status == expected_status
def test_upload_document_to_s3(): agreement = AgreementFactory() fake_file_content = b'information' with tempfile.NamedTemporaryFile() as f: f.write(fake_file_content) f.seek(0) actual_remote_file_name = upload_document_to_s3(agreement, f.name) agreement.refresh_from_db() assert agreement.document.read() == fake_file_content assert actual_remote_file_name.endswith('docx') assert agreement.document_created_at == timezone.now()
def test_write(): file_contents = 'XML' agreement = AgreementFactory(country_name='Espana', slug='spain', country_codes=['1011']) application = Application(country_profile='spain') document = Document(application) actual_remote_file_name = document.write(file_contents) agreement.refresh_from_db() assert agreement.document.name == actual_remote_file_name with zipfile.ZipFile(agreement.document) as fh: actual_files = [f.filename for f in fh.filelist] assert set(actual_files) == { '[Content_Types].xml', '_rels/.rels', 'word/webSettings.xml', 'word/footer2.xml', 'word/settings.xml', 'word/footnotes.xml', 'word/footer1.xml', 'word/fontTable.xml', 'word/header1.xml', 'word/document.xml', 'word/endnotes.xml', 'word/styles.xml', 'word/numbering.xml', 'word/_rels/document.xml.rels', 'word/theme/theme1.xml', 'customXml/item1.xml', 'customXml/itemProps1.xml', 'customXml/_rels/item1.xml.rels' } actual_document_xml = fh.read('word/document.xml') assert actual_document_xml == bytes(file_contents, 'utf-8')
def test_main_with_no_quotas(mock_create_document): mock_create_document.return_value = None agreement = AgreementFactory( slug='israel', country_name='israel', version='2.0', country_codes=['IS', '2334'], agreement_date='2019-01-01', document_status=DocumentStatus.UNAVAILABLE ) application = Application('israel') application.main() agreement.refresh_from_db() assert agreement.document_status == DocumentStatus.AVAILABLE assert mock_create_document.called is True expected_context = { 'AGREEMENT_NAME': agreement.agreement_name, 'VERSION': '2.0', 'AGREEMENT_DATE': '1 January 2019', 'AGREEMENT_DATE_SHORT': '01/01/2019', 'COUNTRY_NAME': 'israel', 'TARIFF_WIDTH_CLASSIFICATION': '400', 'TARIFF_WIDTH_DUTY': '1450', 'TARIFF_TABLE_ROWS': [], 'WIDTH_QUOTA_NUMBER': '8', 'WIDTH_ORIGIN_QUOTA': '7', 'WIDTH_COMMODITY_CODE': '11', 'WIDTH_PREFERENTIAL_QUOTA_DUTY_RATE': '22', 'WIDTH_QUOTA_VOLUME': '16', 'WIDTH_QUOTA_OPEN_DATE': '10', 'WIDTH_QUOTA_CLOSE_DATE': '10', 'WIDTH_2019_QUOTA_VOLUME': '16', 'QUOTA_TABLE_ROWS': [], 'HAS_QUOTAS': False } mock_create_document.assert_called_with(expected_context)
def test_agreement_model(): agreement = AgreementFactory( slug='israel', country_name='israel', version='2.0', country_codes=['IS', '2334'], agreement_date='2019-01-01', agreement_name='Test agreement', ) agreement.refresh_from_db() assert agreement.slug == 'israel' assert agreement.country_profile == 'israel' assert agreement.geo_ids == "'IS', '2334'" assert agreement.country_codes_string == 'IS, 2334' assert agreement.agreement_date_short == '01/01/2019' assert agreement.agreement_date_long == '1 January 2019' assert str(agreement) == f'Test agreement - israel' assert agreement.download_url == reverse('schedule:fta:download', kwargs={'slug': agreement.slug}) assert agreement.edit_url == reverse('schedule:fta:edit', kwargs={'slug': agreement.slug}) assert agreement.regenerate_url == reverse('schedule:fta:regenerate', kwargs={'slug': agreement.slug}) assert agreement.is_document_available is True assert agreement.is_document_unavailable is False assert agreement.is_document_generating is False
def test_update_agreement_document_status(): agreement = AgreementFactory() update_document_status(agreement, DocumentStatus.UNAVAILABLE) agreement.refresh_from_db() assert agreement.document_status == DocumentStatus.UNAVAILABLE