Skip to content

Commit

Permalink
Merge 0e99e7b into 4f9f27a
Browse files Browse the repository at this point in the history
  • Loading branch information
myslak71 committed Nov 12, 2019
2 parents 4f9f27a + 0e99e7b commit cf201f8
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 65 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ script:
- make lint
- make safety
- make unittests
- make integration
after_success: coveralls
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ coverage: ## create html coverage report and open it in the default browser
xdg-open htmlcov/index.html

flake8: ## run flake8
flake8 src
flake8 .

integration: ## run integration tests
pytest tests/integration_tests.py -s -vv

isort: ## run isort
isort . -rc
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def search_regons(
```
def search_account(
self, account: str, *, date: Optional[datetime.date] = None, raw: bool = False
) -> Tuple[Subject, str]:
) -> Tuple[List[Subject], str]:
```
```
def search_accounts(
Expand All @@ -151,8 +151,8 @@ def search_accounts(
def check_nip(
self,
nip: str,
*,
account: str,
*,
date: Optional[datetime.date] = None,
raw: bool = False,
) -> Tuple[bool, str]:
Expand All @@ -161,8 +161,8 @@ def check_nip(
def check_regon(
self,
regon: str,
*,
account: str,
*,
date: Optional[datetime.date] = None,
raw: bool = False,
) -> Tuple[bool, str]:
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Sphinx configuration module."""
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
Expand Down
2 changes: 1 addition & 1 deletion src/vater/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
__version__ = "0.1.0"
__author__ = "myslak71"
__author_email__ = "myslak@protonmail.com"
__url__ = ""
__url__ = "https://github.com/myslak71/vater"
__license__ = "MIT"
__copyright__ = "Copyright 2019 myslak71"
__keywords__ = "vat", "client", "api"
Expand Down
32 changes: 16 additions & 16 deletions src/vater/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def search_regons(
)
def search_account(
self, account: str, *, date: Optional[datetime.date] = None, raw: bool = False
) -> Tuple[Subject, str]:
) -> Tuple[List[Subject], str]:
"""
Get detailed vat payer information for given bank account.
Expand Down Expand Up @@ -153,53 +153,53 @@ def search_accounts(
"""

@api_request(
"/api/check/nip/{nip}/bank-account/{account}?date={date}",
"/api/check/regon/{regon}/bank-account/{account}?date={date}",
CheckRequest,
validators={
"date": [date_validator],
"nip": [nip_validator],
"account": [account_validator],
"regon": [regon_validator],
},
)
def check_nip(
def check_regon(
self,
nip: str,
*,
regon: str,
account: str,
*,
date: Optional[datetime.date] = None,
raw: bool = False,
) -> Tuple[bool, str]:
"""
Check if given account is assigned to the subject with given nip.
Check if given account is assigned to the subject with given regon.
:param nip: nip number of the subject to check
:param account: accountat number of the subject to check
:param regon: regon number of the subject to check
:param account: account number of the subject to check
:param date: date data is acquired from
:param raw: flag indicating if raw json from the server is returned
or python object representation
"""

@api_request(
"/api/check/regon/{regon}/bank-account/{account}?date={date}",
"/api/check/nip/{nip}/bank-account/{account}?date={date}",
CheckRequest,
validators={
"date": [date_validator],
"nip": [nip_validator],
"account": [account_validator],
"regon": [regon_validator],
},
)
def check_regon(
def check_nip(
self,
regon: str,
*,
nip: str,
account: str,
*,
date: Optional[datetime.date] = None,
raw: bool = False,
) -> Tuple[bool, str]:
"""
Check if given account is assigned to the subject with given regon.
Check if given account is assigned to the subject with given nip.
:param regon: regon number of the subject to check
:param nip: nip number of the subject to check
:param account: account number of the subject to check
:param date: date data is acquired from
:param raw: flag indicating if raw json from the server is returned
Expand Down
19 changes: 13 additions & 6 deletions src/vater/request_types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""This module contains logic for different API request types."""
import datetime
from abc import ABC, abstractmethod
from typing import Any, Dict, List, Tuple, Union
from typing import Any, Dict, List, Optional, Tuple, Union

import requests
from requests import Response
Expand Down Expand Up @@ -110,7 +110,9 @@ def validate(self) -> None:
if len(self.params[param]) > self.PARAM_LIMIT: # type: ignore
raise MaximumParameterNumberExceeded(param, self.PARAM_LIMIT)

def result(self) -> Union[dict, Tuple[Union[List[Subject], Subject], str]]:
def result(
self
) -> Union[dict, Tuple[Union[List[Subject], Optional[Subject]], str]]:
"""Return subject/subjects mapped to the specific parameter and request id."""
self.validate()
response = self.send_request()
Expand All @@ -119,8 +121,13 @@ def result(self) -> Union[dict, Tuple[Union[List[Subject], Subject], str]]:
return response.json()

result = response.json()["result"]
subjects = SubjectSchema().load(
result["subjects" if self.many else "subject"], many=self.many
)

return subjects, result["requestId"]
if not self.many and result["subject"] is None:
return None, result["requestId"]

return (
SubjectSchema().load(
result["subjects" if self.many else "subject"], many=self.many
),
result["requestId"],
)
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

@pytest.fixture
def client() -> Client:
"""Yield vat register API client."""
return Client(base_url="https://test-api.no")
"""Yield vat register API client. Client connects to test API client."""
return Client(base_url="https://wl-test.mf.gov.pl")
74 changes: 74 additions & 0 deletions tests/integration_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""
Module containing integration tests with API.
Data is taken from the test API data available here:
https://www.gov.pl/attachment/5e7f6a61-d6de-4841-891b-ef8122353445
"""


def test_search_nip(client):
"""Test that subject and request identifier are returned for valid test nip."""
subject, request_id = client.search_nip("3245174504")

assert subject is not None


def test_search_nips(client):
"""Test that subjects and request identifier are returned for valid test nips."""
subjects, request_id = client.search_nips(
["3245174504", "1854510877", "7250018312"]
)

assert len(subjects) == 3


def test_search_regon(client):
"""Test that subject and request identifier are returned for valid test regon."""
subject, request_id = client.search_regon("887012068")

assert subject is not None


def test_search_regons(client):
"""Test that subject and request identifier are returned for valid test regon."""
subjects, request_id = client.search_regons(["755016841", "216973362", "862391869"])

assert len(subjects) == 3


def test_search_account(client):
"""Test that subjects and request identifier are returned for valid test account."""
subjects, request_id = client.search_account("70506405335016096312945164")

assert len(subjects) != 0


def test_search_accounts(client):
"""Test that subjects and request identifier are returned for valid test accounts."""
subjects, request_id = client.search_accounts(
[
"70506405335016096312945164",
"20028681823250598006154766",
"31872831997646186715413833",
]
)

assert len(subjects) == 3


def test_check_nip(client):
"""Test that account is assigned to the nip."""
is_assigned, request_id = client.check_nip(
"8655104670", "41146786026458860703735932"
)

assert is_assigned


def test_check_regon(client):
"""Test that account is assigned to the nip."""
is_assigned, request_id = client.check_regon(
"730371613", "41146786026458860703735932"
)

assert is_assigned

0 comments on commit cf201f8

Please sign in to comment.