push
This commit is contained in:
68
tests/test_ceidg_service.py
Normal file
68
tests/test_ceidg_service.py
Normal file
@@ -0,0 +1,68 @@
|
||||
import json
|
||||
|
||||
from app.models.setting import AppSetting
|
||||
from app.services.ceidg_service import CeidgService
|
||||
|
||||
|
||||
def test_ceidg_service_parses_warehouse_payload(app):
|
||||
payload = {
|
||||
'firmy': [
|
||||
{
|
||||
'id': '9D2531B1-6DED-4538-95EA-22FF2C7D2E20',
|
||||
'nazwa': 'Adam IntegracjaMGMF',
|
||||
'adresDzialalnosci': {
|
||||
'ulica': 'ul. Zwierzyniecka',
|
||||
'budynek': '1',
|
||||
'miasto': 'Białystok',
|
||||
'kod': '15-333',
|
||||
},
|
||||
'wlasciciel': {
|
||||
'imie': 'Adam',
|
||||
'nazwa': 'IntegracjaMGMF',
|
||||
'nip': '3563457932',
|
||||
'regon': '518155359',
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
with app.app_context():
|
||||
parsed = CeidgService()._parse_payload(json.dumps(payload), '3563457932')
|
||||
|
||||
assert parsed == {
|
||||
'name': 'Adam IntegracjaMGMF',
|
||||
'regon': '518155359',
|
||||
'address': 'ul. Zwierzyniecka 1, 15-333 Białystok',
|
||||
'tax_id': '3563457932',
|
||||
}
|
||||
|
||||
|
||||
def test_ceidg_service_uses_bearer_authorization(app):
|
||||
with app.app_context():
|
||||
AppSetting.set('ceidg.api_key', 'jwt-token', encrypt=True)
|
||||
headers = CeidgService._headers()
|
||||
|
||||
assert headers['Authorization'] == 'Bearer jwt-token'
|
||||
|
||||
|
||||
def test_admin_company_fetch_from_ceidg_requires_only_nip(app, auth_client, monkeypatch):
|
||||
lookup = {'ok': True, 'name': 'Test CEIDG', 'tax_id': '1234567890', 'regon': '123456789', 'address': 'Warszawa'}
|
||||
monkeypatch.setattr('app.admin.routes.CeidgService.fetch_company', lambda self, identifier=None, **kwargs: lookup)
|
||||
|
||||
response = auth_client.post(
|
||||
'/admin/companies/new',
|
||||
data={
|
||||
'name': '',
|
||||
'tax_id': '1234567890',
|
||||
'regon': '',
|
||||
'address': '',
|
||||
'sync_interval_minutes': '60',
|
||||
'fetch_submit': '1',
|
||||
},
|
||||
follow_redirects=True,
|
||||
)
|
||||
|
||||
body = response.get_data(as_text=True)
|
||||
assert response.status_code == 200
|
||||
assert 'Pobrano dane firmy z CEIDG.' in body
|
||||
assert 'Test CEIDG' in body
|
||||
Reference in New Issue
Block a user