diff --git a/README.md b/README.md index b89ff9499ec2ddc2264e5473f6aea69dff4f2329..4e2755452af9ba8af544af7ed22db71fd3adedb9 100644 --- a/README.md +++ b/README.md @@ -17,12 +17,6 @@ batch = Batch.from_dict({ "vouchertype": 5, "batchid_interface": 6 }) -vouchers = [Voucher.from_dict({ - "batchid": 1, - "voucherno_interface": 2, - "exref": 3, - "voucherno": 4 -})] transactions = [Transaction.from_dict({ "voucherid": 1, "account": 1, @@ -44,7 +38,15 @@ transactions = [Transaction.from_dict({ "extinvref": 1 })] -multi = Multi(batch=batch, vouchers=vouchers, transactions=transactions) +vouchers = [Voucher.from_dict({ + "batchid": 1, + "voucherno_interface": 2, + "exref": 3, + "voucherno": 4, + "transactions": transactions +})] + +multi = Multi(batch=batch, vouchers=vouchers) response = c.post_multi(multi) ``` diff --git a/setra_client/models.py b/setra_client/models.py index c11a0bba83c3fa3e5d47817f4fb9e6940674d6ce..6c1cba891caab68ce0993952e8389df262897898 100644 --- a/setra_client/models.py +++ b/setra_client/models.py @@ -40,12 +40,6 @@ class Batch(BaseModel): vouchertype: str -class Voucher(BaseModel): - voucherdate: Optional[datetime.date] - exref: Optional[str] - voucherno: int - - class Transaction(BaseModel): account: str amount: float @@ -66,8 +60,14 @@ class Transaction(BaseModel): extinvref: Optional[str] +class Voucher(BaseModel): + voucherdate: Optional[datetime.date] + exref: Optional[str] + voucherno: int + transactions: typing.List[Transaction] + + class Multi(BaseModel): batch: Batch vouchers: typing.List[Voucher] - transactions: typing.List[Transaction] diff --git a/tests/conftest.py b/tests/conftest.py index 1f66d2b97d07aaf99281325d934b1e61f5dbf8b8..7263375e4b8d998c163b9eff53536844ed387a66 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -49,7 +49,7 @@ def client_with_a_header(baseurl): @pytest.fixture def batch_url(baseurl): - return SetraEndpoints(baseurl).batch() # https://localhost/api/batch + return SetraEndpoints(baseurl).batch() # example: https://localhost/api/batch @pytest.fixture diff --git a/tests/fixtures/multi_fixture.json b/tests/fixtures/multi_fixture.json index 8e9d385a4708271638936e9fa5b5259d862db502..f8022fd6e3bd93fb421aec1a8a04112f1b65440a 100644 --- a/tests/fixtures/multi_fixture.json +++ b/tests/fixtures/multi_fixture.json @@ -10,51 +10,51 @@ "vouchers": [ { "exref": 1, - "voucherno": 66 - } - ], - "transactions": [ - { - "voucherno_interface": 1, - "voucherid": 66, - "account": 1, - "amount": 1, - "transdate": 1, - "curamount": 1, - "currency": 1, - "description": 1, - "dim1": 1, - "dim2": 1, - "dim3": 1, - "dim4": 1, - "dim5": 1, - "dim6": 1, - "dim7": 1, - "sequenceno": 1, - "taxcode": 1, - "transtype": 1, - "extinvref": 1 - }, - { - "voucherno_interface": 1, - "voucherid": 66, - "account": 2, - "amount": 2, - "transdate": 2, - "curamount": 2, - "currency": 2, - "description": 2, - "dim1": 2, - "dim2": 2, - "dim3": 2, - "dim4": 2, - "dim5": 2, - "dim6": 2, - "dim7": 2, - "sequenceno": 2, - "taxcode": 2, - "transtype": 2, - "extinvref": 2 + "voucherno": 66, + "transactions": [ + { + "voucherno_interface": 1, + "voucherid": 66, + "account": 1, + "amount": 1, + "transdate": 1, + "curamount": 1, + "currency": 1, + "description": 1, + "dim1": 1, + "dim2": 1, + "dim3": 1, + "dim4": 1, + "dim5": 1, + "dim6": 1, + "dim7": 1, + "sequenceno": 1, + "taxcode": 1, + "transtype": 1, + "extinvref": 1 + }, + { + "voucherno_interface": 1, + "voucherid": 66, + "account": 2, + "amount": 2, + "transdate": 2, + "curamount": 2, + "currency": 2, + "description": 2, + "dim1": 2, + "dim2": 2, + "dim3": 2, + "dim4": 2, + "dim5": 2, + "dim6": 2, + "dim7": 2, + "sequenceno": 2, + "taxcode": 2, + "transtype": 2, + "extinvref": 2 + } + ] } ] } diff --git a/tests/fixtures/voucher_fixture.json b/tests/fixtures/voucher_fixture.json index c63fb58b5736ff119133a6eae39401f06b6786bb..e4b5743be4508bf44d16bbcbfa723c8ca19c39fa 100644 --- a/tests/fixtures/voucher_fixture.json +++ b/tests/fixtures/voucher_fixture.json @@ -2,5 +2,49 @@ "batchid": 1, "voucherno_interface": 2, "exref": 3, - "voucherno": 4 + "voucherno": 4, + "transactions": [ + { + "voucherno_interface": 1, + "voucherid": 66, + "account": 1, + "amount": 1, + "transdate": 1, + "curamount": 1, + "currency": 1, + "description": 1, + "dim1": 1, + "dim2": 1, + "dim3": 1, + "dim4": 1, + "dim5": 1, + "dim6": 1, + "dim7": 1, + "sequenceno": 1, + "taxcode": 1, + "transtype": 1, + "extinvref": 1 + }, + { + "voucherno_interface": 1, + "voucherid": 66, + "account": 2, + "amount": 2, + "transdate": 2, + "curamount": 2, + "currency": 2, + "description": 2, + "dim1": 2, + "dim2": 2, + "dim3": 2, + "dim4": 2, + "dim5": 2, + "dim6": 2, + "dim7": 2, + "sequenceno": 2, + "taxcode": 2, + "transtype": 2, + "extinvref": 2 + } + ] } diff --git a/tests/test_client.py b/tests/test_client.py index 3f6f5216040ff670732bd0b66b93959024519d7a..5acc7f6cb9f48c01aae906aec649ed31a8581d0c 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -227,6 +227,28 @@ def test_successfully_getting_single_voucher(client, requests_mock, baseurl): assert response == {'foo': 'bar'} +def test_requesting_single_voucher_with_invalid_voucherid(client, requests_mock, baseurl): + """Requesting a voucher, with None as voucherid, will request get all vouchers instead """ + url = SetraEndpoints(baseurl).voucher() + requests_mock.get(url, json={'foo': 'bar'}, status_code=200) + + response = client.get_voucher(None) #using None as voucherid + assert response == {'foo': 'bar'} + + +def test_successfully_getting_single_voucher_with_alphanumeric_voucherid(client, requests_mock, baseurl): + """Requesting a voucher, with alphanumeric voucherid, will work, and not crash + + TODO: investigate if this is intentional behaviour (need spec on voucher id format) + + """ + url = SetraEndpoints(baseurl).voucher("abcd123efg") + requests_mock.get(url, json={'foo': 'bar'}, status_code=200) + + response = client.get_voucher("abcd123efg") #using alphanum string as voucherid + assert response == {'foo': 'bar'} + + def test_failing_to_get_all_vouchers(client, requests_mock, baseurl): """A failing GET all vouchers call should still return json""" url = SetraEndpoints(baseurl).voucher() diff --git a/tests/test_endpoints.py b/tests/test_endpoints.py index 8d30d7fe4b9e31f71e7b452465fa8fa39399c932..349cee77545364804b066b2bfa95156f77ab1965 100644 --- a/tests/test_endpoints.py +++ b/tests/test_endpoints.py @@ -16,6 +16,7 @@ def test_init_batch_with_value(baseurl): endpoints = SetraEndpoints(baseurl) assert endpoints.batch(batch_id="5") == baseurl + "/api/batch/5" + def test_init_batch_with_empty_value(baseurl): endpoints = SetraEndpoints(baseurl) assert endpoints.batch(batch_id="") == baseurl + "/api/batch/"