Skip to content
Snippets Groups Projects
Commit 84134244 authored by rha104's avatar rha104
Browse files

Fixed dataformat. Moved transactions list onto voucher.

And added two new tests
parent d812e386
No related branches found
No related tags found
1 merge request!5Fixed dataformat. Moved transactions list onto voucher.
Pipeline #51748 passed
......@@ -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)
```
......
......@@ -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]
......@@ -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
......
......@@ -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
}
]
}
]
}
......@@ -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
}
]
}
......@@ -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()
......
......@@ -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/"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment