def test_suppress_none_product_line(self): application = mock.MagicMock( document_type=SCHEDULE, OUTPUT_DIR='/tmp', ) commodity_1 = Commodity( application, product_line_suffix='80', commodity_code='1200000000', indents=0, ) commodity_2 = Commodity( application, product_line_suffix='82', commodity_code='1211000000', indents=3, ) commodity_3 = Commodity(application, product_line_suffix='80', commodity_code='1211110000', indents=10) commodity_3.suppress_duty = True db_chapter = ChapterFactory(id=1, description='Test') chapter = ScheduleChapter(application, db_chapter) chapter.suppress_none_product_line( [commodity_1, commodity_2, commodity_3]) assert commodity_1.suppress_duty is False assert commodity_2.suppress_duty is True assert commodity_3.suppress_duty is False
def test_check_for_seasonal( product_line_suffix, commodity_code, add_season, expected_result, expected_combined_duty, expected_notes_list, expected_special_list, expected_assigned_status, ): seasonal_quota = SeasonalQuotaFactory(quota_order_number_id='1234567890') if add_season: start_date = datetime.now() end_date_1 = start_date + timedelta(days=100) end_date_2 = start_date + timedelta(days=150) SeasonalQuotaSeasonFactory(seasonal_quota=seasonal_quota, duty='DUTY DTN', start_date=start_date, end_date=end_date_1) SeasonalQuotaSeasonFactory(seasonal_quota=seasonal_quota, duty='DTN G', start_date=start_date + timedelta(days=30), end_date=end_date_2) application = mock.MagicMock() commodity = Commodity(application, commodity_code=commodity_code, product_line_suffix=product_line_suffix) assert commodity.check_for_seasonal() == expected_result assert commodity.notes_list == expected_notes_list assert commodity.special_list == expected_special_list assert commodity.assigned is expected_assigned_status assert commodity.combined_duty == expected_combined_duty
def test_assign_inherited_duty_to_commodity(self, combined_duty, expected_child_combined_duty): application = mock.MagicMock( document_type=SCHEDULE, OUTPUT_DIR='/tmp', ) commodity_1 = Commodity(application, product_line_suffix='80', commodity_code='1200000000', indents=0) commodity_1.combined_duty = combined_duty commodity_2 = Commodity( application, product_line_suffix='82', commodity_code='1211000000', indents=3, ) commodity_3 = Commodity(application, product_line_suffix='80', commodity_code='1211110000', indents=10) db_chapter = ChapterFactory(id=1, description='Test') chapter = ScheduleChapter(application, db_chapter) actual_max_indent = chapter.assign_inherited_duty_to_commodity( [commodity_1, commodity_2, commodity_3]) assert actual_max_indent == 10 assert commodity_2.combined_duty == expected_child_combined_duty assert commodity_3.combined_duty == expected_child_combined_duty
def test_assign_authorised_use_commodities(self): SeasonalQuotaFactory(quota_order_number_id='1234567891') SeasonalQuotaFactory(quota_order_number_id='1234567892') application = mock.MagicMock( document_type=SCHEDULE, OUTPUT_DIR='/tmp', authorised_use_list=['1234567891', '1234567892'], ) commodity_1 = Commodity(application, product_line_suffix='80', commodity_code='1234567891') commodity_2 = Commodity(application, product_line_suffix='82', commodity_code='1234567892') commodity_3 = Commodity(application, product_line_suffix='80', commodity_code='1234567893') db_chapter = ChapterFactory(id=1, description='Test') chapter = ScheduleChapter(application, db_chapter) assert chapter.contains_authorised_use is False assert chapter.seasonal_records == 0 chapter.assign_authorised_use_commodities( [commodity_1, commodity_2, commodity_3]) assert chapter.contains_authorised_use is True assert chapter.seasonal_records == 1
def test_combine_notes( notes_list, expected_notes_string, ): application = mock.MagicMock() commodity = Commodity(application) commodity.notes_list = notes_list commodity.combine_notes() assert commodity.notes_string == expected_notes_string
def test_combine_duties( duty_list, expected_combined_duty, ): application = mock.MagicMock() commodity = Commodity(application) duty_list = [Duty(**duty_dict) for duty_dict in duty_list] commodity.duty_list = duty_list commodity.combine_duties() assert commodity.combined_duty == expected_combined_duty
def test_check_for_authorised_use(product_line_suffix, commodity_code, authorised_use_list, special_list, expected_combined_duty, expected_notes_list, expected_special_list, expected_assigned_status): application = mock.MagicMock(authorised_use_list=authorised_use_list, ) commodity = Commodity(application, commodity_code=commodity_code, product_line_suffix=product_line_suffix) commodity.special_list = special_list commodity.check_for_authorised_use() assert commodity.combined_duty == expected_combined_duty assert commodity.special_list == expected_special_list assert commodity.assigned is expected_assigned_status assert commodity.notes_list == expected_notes_list
def test_initialise(): application = mock.MagicMock() commodity = Commodity(application) assert commodity.application == application assert commodity.commodity_code == '' assert commodity.commodity_code_formatted == '' assert commodity.description == '' assert_xml(commodity.description_formatted, "<w:r/><w:r/><w:r><w:rPr> <w:b/></w:rPr></w:r><w:r/><w:r/>") assert commodity.product_line_suffix == '' assert commodity.indents == 0 assert commodity.leaf == 0 assert commodity.assigned is False assert commodity.combined_duty == '' assert commodity.notes_list == [] assert commodity.notes_string == '' assert commodity.duty_list == [] assert commodity.suppress_row is False assert commodity.suppress_duty is False assert commodity.significant_children is False assert commodity.measure_count == 0 assert commodity.measure_type_count == 0 assert commodity.special_list == [] assert commodity.child_duty_list == [] assert commodity.indent_string == '<w:ind w:left="0" w:hanging="0"/>' assert commodity.significant_digits == 10
def test_check_for_mixture( commodity_code, combined_duty, expected_combined_duty, expected_notes_list, expected_special_list, expected_assigned_status, ): application = mock.MagicMock() commodity = Commodity(application, commodity_code=commodity_code) commodity.combined_duty = combined_duty commodity.check_for_mixture() assert commodity.special_list == expected_special_list assert commodity.assigned is expected_assigned_status assert commodity.combined_duty == expected_combined_duty assert commodity.notes_list == expected_notes_list
def test_latinise(): LatinTermFactory(text='weather') LatinTermFactory(text='sunny thynnus') LatinTermFactory(text='weather') LatinTermFactory(text='sunny') application = mock.MagicMock() application.latin_phrases = get_latin_terms() commodity = Commodity(application) assert commodity.application.latin_phrases == { 'weather', 'sunny thynnus', 'sunny' } assert ( commodity.latinise( 'sunny thynnus is bad, no the weather is good thynnus. sunny') == '<i>sunny thynnus</i> is bad, no the <i>weather</i> is good thynnus. <i>sunny</i>' )
def test_check_for_specials( commodity_code, application_special_list, expected_special_list, expected_assigned_status, ): application_special_list = [ SpecialNoteFactory(quota_order_number_id=commodity_code) for commodity_code in application_special_list ] expected_notes_list = [ special_note.note for special_note in application_special_list ] application = mock.MagicMock(special_list=application_special_list, ) commodity = Commodity(application, commodity_code=commodity_code) commodity.check_for_specials() assert commodity.notes_list == expected_notes_list assert commodity.special_list == expected_special_list assert commodity.assigned is expected_assigned_status assert commodity.combined_duty == ''
def test_assign_duties_to_commodities(self): application = mock.MagicMock( document_type=SCHEDULE, OUTPUT_DIR='/tmp', ) commodity_1 = Commodity(application, product_line_suffix='80', commodity_code='1234567891') commodity_2 = Commodity(application, product_line_suffix='82', commodity_code='1234567892') Commodity(application, product_line_suffix='80', commodity_code='1234567893') duty_1 = Duty(commodity_code=commodity_1.commodity_code) Duty(commodity_code=commodity_2.commodity_code) db_chapter = ChapterFactory(id=1, description='Test') chapter = ScheduleChapter(application, db_chapter) chapter.duty_list = [duty_1] chapter.assign_duties_to_commodities([commodity_1]) assert commodity_1.assigned is True assert commodity_1.duty_list == [duty_1] assert commodity_1.commodity_code_formatted == '1234 56 78 91'
def test_format_table(self): application = mock.MagicMock( document_type=SCHEDULE, OUTPUT_DIR='/tmp', ) commodity_1 = Commodity( application, product_line_suffix='80', commodity_code='1200000000', indents=0, ) commodity_2 = Commodity( application, product_line_suffix='80', commodity_code='1211000000', indents=3, ) commodity_2.notes_list = ['2 notes'] commodity_3 = Commodity(application, product_line_suffix='80', commodity_code='1211110000', indents=10) commodity_3.notes_list = ['3 notes'] db_chapter = ChapterFactory(id=1, description='Test') chapter = ScheduleChapter(application, db_chapter) actual_table = chapter.format_table_content( [commodity_1, commodity_2, commodity_3]) assert 'commodity_list' in actual_table assert len(actual_table['commodity_list']) == 3 assert set(actual_table['commodity_list'][0].keys()) == { 'DUTY', 'DESCRIPTION', 'INDENT', 'COMMODITY', 'NOTES' } assert actual_table['commodity_list'][0]['COMMODITY'] == '1200' assert actual_table['commodity_list'][1]['COMMODITY'] == '1211' assert actual_table['commodity_list'][2]['COMMODITY'] == '1211 11' assert 'w:left="0"' in actual_table['commodity_list'][0]['INDENT'] assert 'w:left="340"' in actual_table['commodity_list'][1]['INDENT'] assert 'w:left="1134"' in actual_table['commodity_list'][2]['INDENT'] assert actual_table['commodity_list'][0][ 'NOTES'] == '<w:r><w:t></w:t></w:r>' assert actual_table['commodity_list'][1][ 'NOTES'] == '<w:r><w:t>2 notes</w:t></w:r>' assert actual_table['commodity_list'][2][ 'NOTES'] == '<w:r><w:t>3 notes</w:t></w:r>'
def test_suppress_row_for_commodity_when_lowest_child_is_assigned(self): application = mock.MagicMock( document_type=SCHEDULE, OUTPUT_DIR='/tmp', ) commodity_1 = Commodity( application, product_line_suffix='80', commodity_code='1200000000', indents=0, ) commodity_2 = Commodity( application, product_line_suffix='82', commodity_code='1211000000', indents=1, ) commodity_3 = Commodity(application, product_line_suffix='80', commodity_code='1211110000', indents=2) commodity_4 = Commodity(application, product_line_suffix='80', commodity_code='1211111100', indents=3) commodity_5 = Commodity(application, product_line_suffix='80', commodity_code='1211111111', indents=4) commodity_5.assigned = True commodity_5.suppress_row = True db_chapter = ChapterFactory(id=1, description='Test') chapter = ScheduleChapter(application, db_chapter) chapter.suppress_row_for_commodity( [commodity_1, commodity_2, commodity_3, commodity_4, commodity_5], 4) assert commodity_5.prevent_row_suppression is True assert commodity_5.suppress_row is False
def test_format_description(db_description, indents, expected_description): application = mock.MagicMock() commodity = Commodity(application, indents=indents) actual_description = str(commodity.format_description(db_description)) assert_xml(actual_description, expected_description)
def test_style_latin(phrase, indents, expected_result): application = mock.MagicMock() commodity = Commodity(application, indents=indents) assert commodity.style_latin(phrase) == expected_result
def test_get_significant_digits(commodity_code, expected_result): application = mock.MagicMock() commodity = Commodity(application, commodity_code=commodity_code) assert commodity.significant_digits == expected_result
def test_get_indent_string(indents, expected_result): application = mock.MagicMock() commodity = Commodity(application, indents=indents) assert commodity.get_indent_string() == expected_result
def test_format_commodity_code(product_line_suffix, commodity_code, expected_result): application = mock.MagicMock() commodity = Commodity(application, product_line_suffix=product_line_suffix) assert commodity.format_commodity_code(commodity_code) == expected_result