From 797167ab64f06956d32fcff4696f3e0e81de9a1f Mon Sep 17 00:00:00 2001 From: hiaselhans Date: Thu, 18 Nov 2021 17:23:48 +0000 Subject: [PATCH] fix unittests and run them in gh-actions --- .flake8 | 3 +++ .github/workflows/unittest.yml | 34 ++++++++++++++++++++++++++++++++++ pyvat/registries.py | 20 ++++++++++---------- setup.py | 12 +++++------- tests/test_sale_vat_charge.py | 16 ++++++++-------- tests/test_validators.py | 11 +++++++---- 6 files changed, 67 insertions(+), 29 deletions(-) create mode 100644 .flake8 create mode 100644 .github/workflows/unittest.yml diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..b37054b --- /dev/null +++ b/.flake8 @@ -0,0 +1,3 @@ +[flake8] +per-file-ignores = __init__.py:F401 +max-line-length = 127 diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml new file mode 100644 index 0000000..6796c8b --- /dev/null +++ b/.github/workflows/unittest.yml @@ -0,0 +1,34 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Unittest + +on: + push: + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + strategy: + max-parallel: 1 # avoid conflicts with vies rate-limiting + matrix: + python-version: ["3.5", "3.6", "3.7", "3.8", "3.9", "3.10"] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install flake8 + pip install . + - name: Lint with flake8 + run: | + flake8 pyvat + - name: Run tests + run: | + python -m unittest tests/test* diff --git a/pyvat/registries.py b/pyvat/registries.py index b5a1f24..b5101f3 100644 --- a/pyvat/registries.py +++ b/pyvat/registries.py @@ -48,15 +48,15 @@ def check_vat_number(self, vat_number, country_code): result = VatNumberCheckResult() request_data = ( - u'%s%s' % - (country_code, vat_number) + u'%s%s' % + (country_code, vat_number) ) result.log_lines += [ @@ -88,7 +88,7 @@ def check_vat_number(self, vat_number, country_code): u'< Response with status %d of content type %s:' % (response.status_code, response.headers['Content-Type']), response.text, - ] + ] # Do not completely fail problematic requests. if response.status_code != 200 or \ diff --git a/setup.py b/setup.py index 46e0774..e81a3d4 100644 --- a/setup.py +++ b/setup.py @@ -13,15 +13,13 @@ requires = [ 'requests>=1.0.0,<3.0', - 'pycountry', - 'enum34; python_version < "3.4"', + 'pycountry' ] tests_require = [ 'nose', 'rednose', - 'flake8', - 'unittest2', + 'flake8' ] setup( @@ -44,10 +42,10 @@ 'Natural Language :: English', 'License :: OSI Approved :: Apache Software License', 'Programming Language :: Python', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3.3', - 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', ), ) diff --git a/tests/test_sale_vat_charge.py b/tests/test_sale_vat_charge.py index 2c0cd52..3e324eb 100644 --- a/tests/test_sale_vat_charge.py +++ b/tests/test_sale_vat_charge.py @@ -8,7 +8,7 @@ VatChargeAction, ) from pyvat.countries import EU_COUNTRY_CODES -from unittest2 import TestCase +from unittest import TestCase EXPECTED_VAT_RATES = { @@ -148,13 +148,13 @@ ItemType.enewspaper: Decimal(27), }, 'IE': { - ItemType.generic_physical_good: Decimal(21), - ItemType.generic_electronic_service: Decimal(21), - ItemType.generic_telecommunications_service: Decimal(21), - ItemType.generic_broadcasting_service: Decimal(21), - ItemType.prepaid_broadcasting_service: Decimal(21), + ItemType.generic_physical_good: Decimal(23), + ItemType.generic_electronic_service: Decimal(23), + ItemType.generic_telecommunications_service: Decimal(23), + ItemType.generic_broadcasting_service: Decimal(23), + ItemType.prepaid_broadcasting_service: Decimal(23), ItemType.ebook: Decimal(9), - ItemType.enewspaper: Decimal(21), + ItemType.enewspaper: Decimal(23), }, 'IT': { ItemType.generic_physical_good: Decimal(22), @@ -301,7 +301,7 @@ def test_get_sale_vat_charge(self): VatChargeAction.charge) self.assertEqual(vat_charge.rate, - EXPECTED_VAT_RATES[seller_cc][it]) + EXPECTED_VAT_RATES[seller_cc][it], "wrong rate: {}/{}".format(it, seller_cc), ) self.assertEqual(vat_charge.country_code, seller_cc) diff --git a/tests/test_validators.py b/tests/test_validators.py index 5010a95..eeafd64 100644 --- a/tests/test_validators.py +++ b/tests/test_validators.py @@ -3,8 +3,8 @@ is_vat_number_format_valid, VatNumberCheckResult, ) -from unittest2 import TestCase - +from unittest import TestCase +import time VAT_NUMBER_FORMAT_CASES = { '': [ @@ -129,8 +129,7 @@ ('0438390312', VatNumberCheckResult( True, - business_name=u'NV UNILEVER BELGIUM - UNILEVER BELGIQUE - ' - u'UNILEVER BELGIE', + business_name=u'NV UNILEVER BELGIUM', business_address=u'Industrielaan 9\n1070 Anderlecht' )), ], @@ -176,6 +175,7 @@ def test_no_country_code(self): for country_code, cases in VAT_NUMBER_FORMAT_CASES.items(): for vat_number, expected_result in cases: + time.sleep(0.1) verbal_expected_result = \ 'valid' if expected_result else 'invalid' @@ -241,6 +241,7 @@ def test_no_country_code(self): for country_code, cases in VAT_NUMBER_CHECK_CASES.items(): for vat_number, expected in cases: + time.sleep(0.1) self.assert_result_equals( expected, check_vat_number('%s%s' % (country_code, vat_number)) @@ -252,10 +253,12 @@ def test_dk__country_code(self): for country_code, cases in VAT_NUMBER_CHECK_CASES.items(): for vat_number, expected in cases: + time.sleep(0.1) self.assert_result_equals( expected, check_vat_number(vat_number, country_code) ) + time.sleep(0.1) self.assert_result_equals( expected, check_vat_number('%s%s' % (country_code, vat_number),