Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix unittests and run them in gh-actions #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
per-file-ignores = __init__.py:F401
max-line-length = 127
34 changes: 34 additions & 0 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
@@ -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*
20 changes: 10 additions & 10 deletions pyvat/registries.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ def check_vat_number(self, vat_number, country_code):
result = VatNumberCheckResult()

request_data = (
u'<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope'
u' xmlns:ns0="urn:ec.europa.eu:taxud:vies:services:checkVa'
u't:types" xmlns:ns1="http://schemas.xmlsoap.org/soap/enve'
u'lope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-insta'
u'nce" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/env'
u'elope/"><SOAP-ENV:Header/><ns1:Body><ns0:checkVat><ns0:c'
u'ountryCode>%s</ns0:countryCode><ns0:vatNumber>%s</ns0:va'
u'tNumber></ns0:checkVat></ns1:Body></SOAP-ENV:Envelope>' %
(country_code, vat_number)
u'<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope'
u' xmlns:ns0="urn:ec.europa.eu:taxud:vies:services:checkVa'
u't:types" xmlns:ns1="http://schemas.xmlsoap.org/soap/enve'
u'lope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-insta'
u'nce" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/env'
u'elope/"><SOAP-ENV:Header/><ns1:Body><ns0:checkVat><ns0:c'
u'ountryCode>%s</ns0:countryCode><ns0:vatNumber>%s</ns0:va'
u'tNumber></ns0:checkVat></ns1:Body></SOAP-ENV:Envelope>' %
(country_code, vat_number)
)

result.log_lines += [
Expand Down Expand Up @@ -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 \
Expand Down
12 changes: 5 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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',
),
)
16 changes: 8 additions & 8 deletions tests/test_sale_vat_charge.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
VatChargeAction,
)
from pyvat.countries import EU_COUNTRY_CODES
from unittest2 import TestCase
from unittest import TestCase


EXPECTED_VAT_RATES = {
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)

Expand Down
11 changes: 7 additions & 4 deletions tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
is_vat_number_format_valid,
VatNumberCheckResult,
)
from unittest2 import TestCase

from unittest import TestCase
import time

VAT_NUMBER_FORMAT_CASES = {
'': [
Expand Down Expand Up @@ -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'
)),
],
Expand Down Expand Up @@ -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.25)
verbal_expected_result = \
'valid' if expected_result else 'invalid'

Expand Down Expand Up @@ -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.25)
self.assert_result_equals(
expected,
check_vat_number('%s%s' % (country_code, vat_number))
Expand All @@ -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.25)
self.assert_result_equals(
expected,
check_vat_number(vat_number, country_code)
)
time.sleep(0.25)
self.assert_result_equals(
expected,
check_vat_number('%s%s' % (country_code, vat_number),
Expand Down