Example #1
0
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()
Example #2
0
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
Example #3
0
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()
Example #4
0
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
Example #5
0
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
Example #6
0
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_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 == []
Example #8
0
def test_commodity_initialise():
    commodity = Commodity(None)
    assert not commodity.suppress
    assert commodity.measure_list == []
    assert commodity.duty_string == ''
    assert commodity.commodity_code == ''
    assert commodity.commodity_code_formatted == ''
Example #9
0
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
Example #10
0
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 populate_commodity_list(
     self,
     temp_commodity_list,
     commodity_code,
 ):
     if commodity_code not in temp_commodity_list:
         obj_commodity = Commodity(commodity_code)
         self.commodity_list.append(obj_commodity)
         temp_commodity_list.append(commodity_code)
def test_resolve_measures(mock_resolve_measures, commodity_list,
                          expected_resolve_measures_call_count):
    mock_resolve_measures.return_value = None
    application = mock.MagicMock(country_name='spain')
    document = Document(application)
    document.commodity_list = [
        Commodity(commodity_code) for commodity_code in commodity_list
    ]
    document.resolve_measures()
    assert mock_resolve_measures.call_count == expected_resolve_measures_call_count
Example #13
0
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
Example #14
0
def test_compare_measures_with_no_measures():
    commodity = Commodity(None)
    commodity.compare_measures()
    assert commodity.measure_list == []
Example #15
0
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()
Example #16
0
def test_get_partial_period_list_with_no_measures():
    commodity = Commodity(None)
    actual_partial_list = commodity.get_partial_period_list()
    assert actual_partial_list == []
Example #17
0
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()
Example #18
0
def test_process_single_measure_when_measure_list_empty():
    commodity = Commodity(None)
    assert commodity.process_single_measure(True) is None
    assert commodity.duty_string == ''
    assert commodity.suppress is False
Example #19
0
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]