def test_list_view(self, authenticated_client): agreement_1 = AgreementFactory() agreement_2 = AgreementFactory() response = authenticated_client.get(reverse('api:agreement-list')) assert response.status_code == 200 actual_response = sort_list_result(response.json()) assert len(actual_response) == 2 self.assert_agreement(agreement_1, actual_response[agreement_1.slug]) self.assert_agreement(agreement_2, actual_response[agreement_2.slug])
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_manage_extended_information_without_quota_data( mock_generate_document, authenticated_client, ): agreement = AgreementFactory() agreement.save() uri = reverse('schedule:fta:manage-extended-info', kwargs={'slug': agreement.slug}) data = {} response = authenticated_client.post(uri, data=data, follow=True) assert response.status_code == 200 quotas = ExtendedQuota.objects.filter(agreement=agreement) assert quotas.count() == 0 assert not mock_generate_document.called
def __init__(self, country_profile=None, local_sivs=None, local_sivs_commodities_only=None, mfn_rate=0): self.local_sivs_commodities_only = local_sivs_commodities_only or [] self.mfn_rate = mfn_rate self.country_profile = country_profile self.local_sivs = local_sivs or [] if country_profile: self.agreement = AgreementFactory(country_name=country_profile) else: self.agreement = AgreementFactory()
def test_add_licensed_quotas(): agreement = AgreementFactory(country_name='Espana', slug='spain', country_codes=['1011']) application = Application(country_profile='spain') licensed_quota = ExtendedQuotaFactory( quota_type=ExtendedQuota.LICENSED, agreement=application.agreement, ) document = Document(application) document.add_licensed_quotas() assert licensed_quota.quota_order_number_id in document.balance_dict quota_balance = document.balance_dict[licensed_quota.quota_order_number_id] assert quota_balance.y1_balance == 0 assert quota_balance.yx_balance == licensed_quota.opening_balance assert quota_balance.country == agreement.slug assert quota_balance.method == dict( ExtendedQuota.QUOTA_CHOICES)[ExtendedQuota.LICENSED] assert quota_balance.quota_order_number_id == licensed_quota.quota_order_number_id assert quota_balance.origin_quota == 'Yes' assert quota_balance.scope == licensed_quota.scope assert quota_balance.addendum == licensed_quota.addendum assert quota_balance.measurement_unit_code == 'KGM' assert quota_balance.validity_start_date_2019 == datetime(2018, 1, 1, 0, 0) assert quota_balance.validity_end_date_2019 == datetime(2019, 12, 31, 0, 0)
def test_get_commodities_for_local_sivs(measures, expected_local_sivs_commodities_only): AgreementFactory(country_name='Espana', slug='spain', country_codes=['1011']) application = Application(country_profile='spain') for measure_properties in measures: measure = get_mfn_siv_product( measure_properties.pop('goods_nomenclature_item_id'), geographical_area_id='1011', measure_type_id='142', measure_quota_number='99999', **measure_properties) CurrentMeasureFactory( measure_sid=measure.measure_sid, geographical_area_id=measure.geographical_area_id, measure_type_id=measure.measure_type_id, validity_start_date=measure.validity_start_date, validity_end_date=measure.validity_end_date, ordernumber=measure.quota_order_number_id, goods_nomenclature_item_id=measure.goods_nomenclature_item_id, reduction_indicator=measure.reduction_indicator, ) document = Document(application) actual_local_sivs, actual_local_sivs_commodities_only = document.get_commodities_for_local_sivs( ) assert actual_local_sivs_commodities_only == expected_local_sivs_commodities_only assert len(actual_local_sivs) == len(expected_local_sivs_commodities_only) for local_siv in actual_local_sivs: assert local_siv.goods_nomenclature_item_id in expected_local_sivs_commodities_only
def test_detail_view(self, authenticated_client, document_status): agreement = AgreementFactory(document_status=document_status) response = authenticated_client.get( reverse('api:agreement-detail', kwargs={'slug': agreement.slug})) assert response.status_code == 200 actual_result = response.json() self.assert_agreement(agreement, actual_result)
def test_get_quota_measures(): measure = get_mfn_siv_product(1, geographical_area_id='1011', measure_type_id='143') current_measure = CurrentMeasureFactory( measure_sid=measure.measure_sid, geographical_area_id=measure.geographical_area_id, measure_type_id=measure.measure_type_id, validity_start_date=measure.validity_start_date, validity_end_date=measure.validity_end_date, ordernumber=measure.quota_order_number_id, goods_nomenclature_item_id=measure.goods_nomenclature_item_id, reduction_indicator=measure.reduction_indicator, ) AgreementFactory(country_name='Espana', slug='spain', country_codes=['1011']) application = Application(country_profile='spain') document = Document(application) document.get_quota_measures() actual_measure_list = document.measure_list assert len(actual_measure_list) == 1, 'Not the correct things to assert' actual_measure = actual_measure_list[0] assert actual_measure.commodity_code == str( current_measure.goods_nomenclature_item_id) assert actual_measure.measure_sid == current_measure.measure_sid assert actual_measure.quota_order_number_id == str( current_measure.ordernumber) assert actual_measure.validity_start_date == current_measure.validity_start_date assert actual_measure.validity_end_date == current_measure.validity_end_date assert actual_measure.geographical_area_id == current_measure.geographical_area_id assert actual_measure.reduction_indicator == current_measure.reduction_indicator
def test_generate_all_fta_documents_task( mock_generate_fta_document, force, ): agreement = AgreementFactory() generate_all_fta_documents(background=False, force=force) assert mock_generate_fta_document.called is True mock_generate_fta_document.assert_called_once_with(agreement.slug, force=force)
def test_load_sql_file(): agreement = AgreementFactory() TEST_SQL_DIR = os.path.dirname(os.path.abspath(__file__)) with override_settings(BASE_DIR=TEST_SQL_DIR): result = load_data_from_sql('test_utils.sql', {'slug': agreement.slug}, 'default', return_result=True) assert len(result) == 1 assert result[0][0] == agreement.agreement_name
def test_generate_all_fta_documents_task_when_backgrounded( mock_delayed_generate_fta_document, force, ): agreement = AgreementFactory() mock_delayed_generate_fta_document.return_value = None generate_all_fta_documents(background=True, force=force) assert mock_delayed_generate_fta_document.called is True mock_delayed_generate_fta_document.assert_called_once_with(agreement.slug, force=force)
def test_agreement_raises_error_when_no_country_codes_are_associated(): AgreementFactory( slug='israel', country_name='israel', version='2.0', country_codes=[], agreement_date='2019-01-01', ) with pytest.raises(CountryProfileError) as error: Application('israel') assert str(error.value) == 'Country profile has no country codes'
def test_add_first_come_serve_quotas( has_extended_info, expected_origin_quota, expected_addendum, expected_scope, expected_measurement_unit_code, ): geographical_area_id = '1011' country_profile = 'spain' quota_order_number = QuotaOrderNumberFactory() quota_definition = QuotaDefinitionFactory( quota_order_number=quota_order_number, initial_volume=2000, volume=3000, measurement_unit_code='FS') QuotaOrderNumberOriginFactory( quota_order_number_sid=quota_order_number.quota_order_number_sid, geographical_area_id=geographical_area_id, ) agreement = AgreementFactory(country_name=country_profile.capitalize(), slug=country_profile, country_codes=[geographical_area_id]) if has_extended_info: ExtendedQuotaFactory( quota_type=ExtendedQuota.FIRST_COME_FIRST_SERVED, agreement=agreement, scope='FCFS Scope', addendum='FCFS Addendum', measurement_unit_code='KGM', is_origin_quota=True, quota_order_number_id=quota_order_number.quota_order_number_id) application = Application(country_profile=country_profile) document = Document(application) document.add_first_come_first_serve_quotas() assert quota_order_number.quota_order_number_id in document.balance_dict quota_balance = document.balance_dict[ quota_order_number.quota_order_number_id] assert quota_balance.quota_order_number_id == quota_order_number.quota_order_number_id assert quota_balance.y1_balance == quota_definition.initial_volume assert quota_balance.yx_balance == quota_definition.volume assert quota_balance.country == agreement.slug assert quota_balance.method == dict( ExtendedQuota.QUOTA_CHOICES)[ExtendedQuota.FIRST_COME_FIRST_SERVED] assert quota_balance.validity_start_date_2019 == datetime(2018, 1, 1, 0, 0) assert quota_balance.validity_end_date_2019 == datetime(2019, 12, 31, 0, 0) assert quota_balance.origin_quota == expected_origin_quota assert quota_balance.scope == expected_scope assert quota_balance.addendum == expected_addendum assert quota_balance.measurement_unit_code == expected_measurement_unit_code
def test_regenerate_document_when_agreement( mock_generate_document, authenticated_client, document_status, expected_document_to_be_generated ): mock_generate_document.return_value = None agreement = AgreementFactory(slug='hello', document=None, document_status=document_status) uri = reverse('schedule:fta:regenerate', kwargs={'slug': agreement.slug}) response = authenticated_client.get(uri) assert response.status_code == 302 assert response.get('Location') == reverse('schedule:fta:manage') assert mock_generate_document.called is expected_document_to_be_generated
def test_check_for_quotas_is_true(): SimpleCurrentMeasureFactory( measure_type_id='143', geographical_area_id='1234', ordernumber=1, validity_start_date=datetime.today(), ) AgreementFactory(country_name='Espana', slug='spain', country_codes=['1234']) application = Application(country_profile='spain') document = Document(application) assert document.check_for_quotas() is True
def test_agreement_properties_set(): AgreementFactory( slug='israel', country_name='israel', version='2.0', country_codes=['IS', '2334'], agreement_date='2019-01-01', ) application = Application('israel') assert application.agreement.slug == 'israel' assert application.agreement.geo_ids == "'IS', '2334'" assert application.agreement.agreement_date_short == '01/01/2019' assert application.agreement.agreement_date_long == '1 January 2019'
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_admin_views( authenticated_admin_client, url, include_kwargs, post, ): if 'agreementdocumenthistory' in url: factory = AgreementDocumentHistoryFactory() elif '_agreement_' in url: factory = AgreementFactory() elif 'chapterdocumenthistory' in url: factory = ChapterDocumentHistoryFactory() elif 'latinterm' in url: factory = LatinTermFactory() elif 'specialnote' in url: factory = SpecialNoteFactory() elif 'chapternote' in url: factory = ChapterNoteFactory() elif '_chapter_' in url: factory = ChapterFactory() elif '_extendedquota_' in url: factory = ExtendedQuotaFactory() elif 'mfntableofcontent' in url: factory = MFNTableOfContentFactory() else: factory = MFNDocumentHistoryFactory() kwargs = {} if include_kwargs: kwargs = {'object_id': factory.pk} uri = reverse(url, kwargs=kwargs) response = authenticated_admin_client.get(uri) assert response.status_code == status.HTTP_200_OK if post: post_data = get_factory_dict(factory) post_data.update(post) post_response = authenticated_admin_client.post(uri, data=post_data, follow=True) assert post_response.status_code == status.HTTP_200_OK assert b'errorlist' not in post_response.content, str(post_response.content) factory.refresh_from_db() for key, value in post.items(): assert getattr(factory, key) == value
def test_get_measure_conditions(): duty_amount = 200 measure = get_mfn_siv_product(1, duty_amount=duty_amount) AgreementFactory(country_name='Espana', slug='spain', country_codes=['1011']) application = Application(country_profile='spain') document = Document(application) actual_result = document.get_measure_conditions("'103'") assert len(actual_result) == 1 assert measure.measure_sid in actual_result actual_measure_condition = actual_result[measure.measure_sid] assert actual_measure_condition.condition_duty_amount == duty_amount assert actual_measure_condition.measure_sid == measure.measure_sid assert actual_measure_condition.measure_condition_sid == 0 assert actual_measure_condition.component_sequence_number == 1 assert actual_measure_condition.condition_code == 'V'
def test_manage_extended_information_when_data_is_missing(mock_generate_document, authenticated_client): mock_generate_document.return_value = None agreement = AgreementFactory() uri = reverse('schedule:fta:manage-extended-info', kwargs={'slug': agreement.slug}) data = { 'licensed_quotas': '890,,C\r\n\r\n', } response = authenticated_client.post(uri, data=data, follow=True) assert response.status_code == 200 quotas = ExtendedQuota.objects.filter(agreement=agreement) third_quota = quotas.get(quota_order_number_id=890) assert not third_quota.scope assert third_quota.quota_type == ExtendedQuota.LICENSED assert not third_quota.addendum assert third_quota.is_origin_quota is False assert not third_quota.opening_balance assert third_quota.measurement_unit_code == 'C' assert mock_generate_document.called
def test__get_duties(): measure = get_mfn_siv_product(1, geographical_area_id='1011', measure_type_id='143') current_measure = CurrentMeasureFactory( measure_sid=measure.measure_sid, geographical_area_id=measure.geographical_area_id, measure_type_id=measure.measure_type_id, validity_start_date=measure.validity_start_date, validity_end_date=measure.validity_end_date, ordernumber=measure.quota_order_number_id, goods_nomenclature_item_id=measure.goods_nomenclature_item_id, reduction_indicator=measure.reduction_indicator, ) AgreementFactory(country_name='Espana', slug='spain', country_codes=['1011']) application = Application(country_profile='spain') GoodsNomenclatureFactory( goods_nomenclature_item_id=current_measure.goods_nomenclature_item_id) document = Document(application) actual_duties = list(document._get_duties("'143', '146'")) assert len(actual_duties) == 1 actual_duty = actual_duties[0] expected_duty = { 'additional_code_id': None, 'additional_code_type_id': None, 'duty_amount': None, 'duty_expression_id': None, 'geographical_area_id': '1011', 'goods_nomenclature_item_id': '1', 'measure_sid': current_measure.measure_sid, 'measure_type_id': '143', 'measurement_unit_code': None, 'measurement_unit_qualifier_code': None, 'monetary_unit_code': None, 'ordernumber': '10', 'reduction_indicator': 5, 'validity_end_date': datetime(2019, 4, 2, 1, 0, tzinfo=timezone.utc), 'validity_start_date': datetime(2019, 5, 1, 1, 0, tzinfo=timezone.utc) } assert actual_duty == expected_duty
def test_create_agreement_slug_already_exists(): agreement = AgreementFactory() data = { 'version': agreement.version, 'agreement_name': agreement.agreement_name, 'country_codes': agreement.country_codes, 'slug': agreement.slug, 'agreement_date_day': 1, 'agreement_date_month': 2, 'agreement_date_year': 2029, 'country_name': 'Country', } qs = urlencode(data, True) post_data = QueryDict(qs) form = AgreementModelForm(post_data) assert not form.is_valid() assert form.errors == { 'slug': ['Agreement with this Unique ID already exists.'], }
def test_get_quota_definitions(quota_order_number_id, add_balance, expected_quota_order_number_sid, expected_definition): geographical_area_id = '1011' country_profile = 'spain' quota_order_number = QuotaOrderNumberFactory( id=quota_order_number_id, quota_order_number_sid=str(quota_order_number_id)) if not quota_order_number_id.startswith('094'): QuotaDefinitionFactory( quota_order_number_id=quota_order_number.id, quota_order_number_sid=quota_order_number.quota_order_number_sid, initial_volume=2000, volume=3000, measurement_unit_code='') AgreementFactory(country_name=country_profile.capitalize(), slug=country_profile, country_codes=[geographical_area_id]) application = Application(country_profile=country_profile) document = Document(application) document.has_quotas = True if add_balance: qb = get_quota_balance( quota_order_number_id=quota_order_number.quota_order_number_id, y1_balance=6000, ) document.balance_dict[quota_order_number.quota_order_number_id] = qb document.q = [quota_order_number.quota_order_number_id] qon = QuotaOrderNumber(quota_order_number.quota_order_number_id) assert document.quota_definition_list == [] document.quota_order_number_list = [qon] document.get_quota_definitions() assert len(qon.quota_definition_list) == 1 assert qon.quota_definition_list[0].quota_order_number_id == str( quota_order_number_id) assert len(document.quota_definition_list) == 1 assert_object(document.quota_definition_list[0], expected_definition)
def test_create_document( mock_render_to_string, mock_write, context, force, expected_template, expected_document_xml, expected_change, raise_write_exception, ): fake_file_name = 'fake_file.txt' mock_write.return_value = fake_file_name if raise_write_exception: mock_write.side_effect = EndpointConnectionError(endpoint_url='') mock_render_to_string.return_value = expected_document_xml agreement = AgreementFactory(country_name='Espana', slug='spain', country_codes=['1011']) application = Application(country_profile='spain', force_document_generation=force) document = Document(application) document.create_document(context) if expected_document_xml: mock_render_to_string.assert_called_with(expected_template, context) mock_write.asssert_called_with(expected_document_xml) else: assert mock_render_to_string.called is False assert mock_write.called is False if expected_change: document_history = AgreementDocumentHistory.objects.get( agreement=agreement) assert document_history.forced is force assert document_history.data == context assert document_history.change == expected_change assert document_history.remote_file_name == fake_file_name else: assert AgreementDocumentHistory.objects.filter( agreement=agreement).exists() is False
def test_get_quota_order_numbers(quota_order_numbers, has_quotas, expected_q): AgreementFactory(country_name='Espana', slug='spain', country_codes=['1011']) application = Application(country_profile='spain') ignored_measure = get_mfn_siv_product(1, geographical_area_id='1011', measure_type_id='142', measure_quota_number='99999') CurrentMeasureFactory( measure_sid=ignored_measure.measure_sid, geographical_area_id=ignored_measure.geographical_area_id, measure_type_id=ignored_measure.measure_type_id, validity_start_date=ignored_measure.validity_start_date, validity_end_date=ignored_measure.validity_end_date, ordernumber=ignored_measure.quota_order_number_id, goods_nomenclature_item_id=ignored_measure.goods_nomenclature_item_id, reduction_indicator=ignored_measure.reduction_indicator, ) for quota_order_number in quota_order_numbers: measure = get_mfn_siv_product(1, geographical_area_id='1011', measure_type_id='143', measure_quota_number=quota_order_number) CurrentMeasureFactory( measure_sid=measure.measure_sid, geographical_area_id=measure.geographical_area_id, measure_type_id=measure.measure_type_id, validity_start_date=measure.validity_start_date, validity_end_date=measure.validity_end_date, ordernumber=measure.quota_order_number_id, goods_nomenclature_item_id=measure.goods_nomenclature_item_id, reduction_indicator=measure.reduction_indicator, ) document = Document(application) document.get_quota_order_numbers() assert document.has_quotas is has_quotas assert document.q == expected_q assert len(document.quota_order_number_list) == len(expected_q) for qon in document.quota_order_number_list: assert qon.quota_order_number_id in expected_q
def test_get_duties(instrument_type, measure_type_id, expected_duty_list, expected_measure_list, expected_commodity_list, expected_quota_order_number_list): measure = get_mfn_siv_product(1, geographical_area_id='1011', measure_type_id=measure_type_id) current_measure = CurrentMeasureFactory( measure_sid=measure.measure_sid, geographical_area_id=measure.geographical_area_id, measure_type_id=measure.measure_type_id, validity_start_date=measure.validity_start_date, validity_end_date=measure.validity_end_date, ordernumber=measure.quota_order_number_id, goods_nomenclature_item_id=measure.goods_nomenclature_item_id, reduction_indicator=measure.reduction_indicator, ) GoodsNomenclatureFactory( goods_nomenclature_item_id=current_measure.goods_nomenclature_item_id) AgreementFactory(country_name='Espana', slug='spain', country_codes=['1011']) application = Application(country_profile='spain') document = Document(application) document.get_duties(instrument_type) assert len(document.duty_list) == len(expected_duty_list) if document.duty_list: assert_object(document.duty_list[0], expected_duty_list[0]) assert len(document.measure_list) == len(expected_measure_list) if document.measure_list: assert_object(document.measure_list[0], expected_measure_list[0]) assert len(document.commodity_list) == len(expected_commodity_list) if document.commodity_list: assert_object(document.commodity_list[0], expected_commodity_list[0]) assert len(document.quota_order_number_list) == len( expected_quota_order_number_list) if document.quota_order_number_list: assert_object(document.quota_order_number_list[0], expected_quota_order_number_list[0])
def test_update_agreement_errors(update_post_data, expected_errors): GeographicalAreaFactory(geographical_area_id='RTD') GeographicalAreaFactory(geographical_area_id='GB') agreement = AgreementFactory() data = { 'version': agreement.version, 'agreement_name': agreement.agreement_name, 'country_codes': agreement.country_codes, 'slug': agreement.slug, 'agreement_date_day': 1, 'agreement_date_month': 2, 'agreement_date_year': 2029, 'country_name': 'Country', } data.update(update_post_data) qs = urlencode(data, True) post_data = QueryDict(qs) form = AgreementModelForm(post_data, instance=agreement) assert not form.is_valid() assert form.errors == expected_errors