def test_check_for_restarted_measures(): commodity = QuotaCommodity(None, None) first_measure = get_measure() first_measure.extent = 65 second_measure = get_measure() second_measure.extent = 300 commodity.measure_list.extend([first_measure, second_measure]) assert commodity.check_for_restarted_measures() is True
def test_is_entry_price_when_combined_duty_set(): commodity = QuotaCommodity(None, None) entry_price_measure = get_measure() entry_price_measure.combined_duty = "Test that Entry Price is found" commodity.measure_list.extend( [get_measure(), entry_price_measure, get_measure()]) assert commodity.is_entry_price()
def test_process_single_measure(): commodity = Commodity(None) first_measure = get_measure() second_measure = get_measure() commodity.measure_list.extend([first_measure, second_measure]) assert commodity.process_single_measure(True) is None assert commodity.measure_list == [first_measure, second_measure] assert commodity.duty_string == '<w:r><w:t></w:t></w:r>' assert commodity.suppress is False
def test_is_all_full_year_when_measure_has_no_full_years(): commodity = Commodity(None) commodity.measure_list.append(get_measure()) commodity.measure_list.append( get_measure( validity_start_date=datetime.now(), validity_end_date=datetime(2020, 1, 1, 0, 0), ), ) assert not commodity.is_all_full_year()
def test_is_any_infinite(): commodity = Commodity(None) commodity.measure_list.append( get_measure( validity_start_date=datetime.now(), validity_end_date=datetime(2020, 1, 1, 0, 0), ), ) commodity.measure_list.append(get_measure()) assert commodity.is_any_infinite()
def test_get_partial_period_list(): commodity = Commodity(None) first_measure = get_measure( validity_start_date=datetime.now(), validity_end_date=datetime(2019, 1, 10, 0, 0), ) second_measure = get_measure() commodity.measure_list.extend([first_measure, second_measure]) actual_partial_list = commodity.get_partial_period_list() assert len(actual_partial_list) == 1 assert actual_partial_list[0].marked is False assert actual_partial_list[0].validity_start_day == 5 assert actual_partial_list[0].validity_start_month == 1
def test_process_single_measure_with_end_date_before_brexit(): commodity = Commodity(None) first_measure = get_measure( validity_start_date=datetime.now(), validity_end_date=datetime(2019, 1, 2, 0, 0), ) second_measure = get_measure(validity_start_date=datetime.now(), validity_end_date=datetime(2019, 1, 2, 0, 0)) commodity.measure_list.extend([first_measure, second_measure]) assert commodity.process_single_measure(True) is None assert commodity.measure_list == [first_measure, second_measure] assert commodity.duty_string == '<w:r><w:t></w:t></w:r>' assert commodity.suppress is True
def test_resolve_measure_when_not_seasonal(): commodity = QuotaCommodity(None, None) first_measure = get_measure() first_measure.suppress = False first_measure.combined_duty = 'Combined duty 1' first_measure.extent = 265 second_measure = get_measure() second_measure.suppress = False second_measure.combined_duty = 'Combined duty 2' second_measure.extent = 100 commodity.measure_list.extend([first_measure, second_measure]) commodity.resolve_measures() assert commodity.duty_string == 'Combined duty 2'
def test_assign_measures_to_commodities(mock_combine_duties, commodity_list, measure_list, expected_assigned_measure): mock_combine_duties.return_value = None application = mock.MagicMock(country_name='spain') document = Document(application) commodity_list = [ Commodity(commodity_code) for commodity_code in commodity_list ] measure_list = [ get_measure(**measure_properties) for measure_properties in measure_list ] document.commodity_list = commodity_list document.measure_list = measure_list for commodity in commodity_list: assert commodity.measure_list == [] document.assign_measures_to_commodities() for commodity in document.commodity_list: if expected_assigned_measure: assert len(commodity.measure_list) == 1 # TODO: MPP not a very dynamic test as it makes assumptions. Consider a better way to assert assert commodity.measure_list[0].measure_sid == measure_list[ 0].measure_sid else: assert commodity.measure_list == []
def test_assign_duties_to_measures(mock_combine_duties, duty_list, measure_list, expected_assigned_duty): mock_combine_duties.return_value = None application = mock.MagicMock(country_name='spain') document = Document(application) duty_list = [ get_duty_object(**duty_properties) for duty_properties in duty_list ] measure_list = [ get_measure(**measure_properties) for measure_properties in measure_list ] document.duty_list = duty_list document.measure_list = measure_list for measure in measure_list: assert measure.duty_list == [] document.assign_duties_to_measures() for measure in document.measure_list: if expected_assigned_duty: assert len(measure.duty_list) == 1 # TODO: MPP not a very dynamic test as it makes assumptions. Consider a better way to assert assert measure.duty_list[0].measure_sid == measure_list[ 0].measure_sid else: assert measure.duty_list == []
def test_resolve_measure_when_measures_are_combined(): commodity = Commodity(None) measure = get_measure(commodity_code='12345', validity_start_date=datetime(2019, 1, 10, 0, 0), validity_end_date=datetime(2019, 1, 20, 0, 0)) measure.combined_duty = 'Duty' second_measure = get_measure( commodity_code='12345', validity_start_date=datetime(2019, 1, 21, 0, 0), validity_end_date=datetime(2019, 1, 31, 0, 0), ) second_measure.combined_duty = 'Duty' commodity.measure_list.extend([second_measure, measure]) commodity.resolve_measures() assert 'Duty' in commodity.duty_string assert '<w:r><w:t>10/01 to 31/01</w:t></w:r>' in commodity.duty_string
def test_suppress_if_eps_or_full_year_when_one_measure(): commodity = QuotaCommodity(None, None) first_measure = get_measure() first_measure.suppress = False commodity.measure_list.extend([first_measure]) commodity.suppress_if_eps_or_full_year(False, True) assert first_measure.suppress is False
def test_suppress_if_eps_or_full_year(): commodity = QuotaCommodity(None, None) first_measure = get_measure() first_measure.suppress = False second_measure = get_measure() second_measure.suppress = False third_measure = get_measure() third_measure.suppress = False commodity.measure_list.extend( [first_measure, second_measure, third_measure]) commodity.suppress_if_eps_or_full_year(False, True) assert first_measure.suppress is True assert second_measure.suppress is True assert third_measure.suppress is False
def test_compare_measures_with_measures(): commodity = Commodity(None) measure = get_measure(commodity_code='12345', validity_start_date=datetime(2019, 1, 10, 0, 0), validity_end_date=datetime(2019, 1, 20, 0, 0)) second_measure = get_measure(commodity_code='12345', validity_start_date=datetime( 2019, 1, 21, 0, 0), validity_end_date=datetime(2019, 1, 31, 0, 0)) commodity.measure_list.append(measure) commodity.measure_list.append(second_measure) commodity.compare_measures() assert commodity.measure_list == [measure] assert commodity.measure_list[0].period_end == '31/01' assert commodity.measure_list[0].period == '10/01 to 31/01' assert commodity.measure_list[ 0].validity_end_date == second_measure.validity_end_date assert commodity.measure_list[0].extent == 22
def test_combine_duties(mock_combine_duties, measure_list, expected_combine_duties_call_count): mock_combine_duties.return_value = None application = mock.MagicMock(country_name='spain') document = Document(application) document.measure_list = [ get_measure(measure_sid=measure_sid) for measure_sid in measure_list ] document.combine_duties() assert mock_combine_duties.call_count == expected_combine_duties_call_count
def test_get_duty_string_when_measure_is_not_suppressed( is_seasonal, suppress_measure_1, suppress_measure_2, expected_result, ): first_combined_duty_text = 'Combined duty 1' second_combined_duty_text = 'Combined duty 2' commodity = QuotaCommodity(None, None) first_measure = get_measure() first_measure.combined_duty = first_combined_duty_text first_measure.suppress = suppress_measure_1 second_measure = get_measure() second_measure.combined_duty = second_combined_duty_text second_measure.suppress = suppress_measure_2 commodity.measure_list.extend([first_measure, second_measure]) assert commodity.get_duty_string( is_seasonal=is_seasonal) == expected_result
def test_resolve_measure_with_one_measure(): commodity = Commodity(None) first_measure = get_measure(commodity_code='12345', validity_start_date=datetime( 2018, 1, 10, 0, 0), validity_end_date=datetime(2019, 1, 9, 0, 0)) first_measure.suppress = False first_measure.extent = 365 first_measure.combined_duty = 'Combined duty 1' commodity.measure_list.extend([first_measure]) commodity.resolve_measures() assert '<w:r><w:t>Combined duty 1</w:t></w:r>' in commodity.duty_string
def test_resolve_measure(): commodity = Commodity(None) first_measure = get_measure(commodity_code='12345', validity_start_date=datetime( 2019, 1, 10, 0, 0), validity_end_date=datetime(2019, 1, 20, 0, 0)) first_measure.suppress = False first_measure.extent = 265 first_measure.combined_duty = 'Combined duty 1' second_measure = get_measure(commodity_code='12345', validity_start_date=datetime( 2019, 1, 21, 0, 0), validity_end_date=datetime(2019, 1, 31, 0, 0)) second_measure.suppress = False second_measure.extent = 100 second_measure.combined_duty = 'Combined duty 2' commodity.measure_list.extend([first_measure, second_measure]) commodity.resolve_measures() assert '<w:r><w:t>21/01 to 31/01</w:t></w:r>' in commodity.duty_string assert '<w:r><w:t>10/01 to 20/01</w:t></w:r>' in commodity.duty_string
def test_is_any_infinite_returns_false_when_all_validate_end_dates_set(): commodity = Commodity(None) commodity.measure_list.append( get_measure(validity_start_date=datetime.now(), validity_end_date=datetime(2020, 1, 1, 0, 0)), ) assert not commodity.is_any_infinite()
def test_is_all_full_year_when_one_measure_has_an_end_date_of_a_year(): commodity = Commodity(None) commodity.measure_list.append( get_measure(validity_start_date=datetime.now(), validity_end_date=datetime(2020, 2, 1, 0, 0)), ) assert commodity.is_all_full_year()
def test_is_entry_price_when_combined_duty_not_set(): commodity = QuotaCommodity(None, None) commodity.measure_list.extend([get_measure(), get_measure()]) assert not commodity.is_entry_price()
def test_compare_measures_with_one_measures(): commodity = Commodity(None) measure = get_measure() commodity.measure_list.append(measure) commodity.compare_measures() assert commodity.measure_list == [measure]