From 6abb84ff5dea19993a70877ea2492dc99a5829a0 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Sun, 19 Nov 2023 13:44:48 +0000 Subject: [PATCH] Add historical api tests --- api/oas_schemas.py | 10 ++++------ docs/assets/schemas/api-latest.yaml | 10 ++++------ tests/test_trade_pipeline.py | 27 ++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/api/oas_schemas.py b/api/oas_schemas.py index 569e9658..41a138e9 100644 --- a/api/oas_schemas.py +++ b/api/oas_schemas.py @@ -718,11 +718,11 @@ class HistoricalViewSchema: "type": "object", "properties": { "volume": { - "type": "integer", + "type": "number", "description": "Total Volume traded on that particular date", }, "num_contracts": { - "type": "number", + "type": "integer", "description": "Number of successful trades on that particular date", }, }, @@ -734,10 +734,8 @@ class HistoricalViewSchema: "Truncated example", value={ "": { - "code": "USD", - "price": "42069.69", - "min_amount": "4.2", - "max_amount": "420.69", + "volume": 0.69, + "num_contracts": 69, }, }, status_codes=[200], diff --git a/docs/assets/schemas/api-latest.yaml b/docs/assets/schemas/api-latest.yaml index 55ce967d..893faa54 100644 --- a/docs/assets/schemas/api-latest.yaml +++ b/docs/assets/schemas/api-latest.yaml @@ -122,20 +122,18 @@ paths: type: object properties: volume: - type: integer + type: number description: Total Volume traded on that particular date num_contracts: - type: number + type: integer description: Number of successful trades on that particular date examples: TruncatedExample: value: - : - code: USD - price: '42069.69' - min_amount: '4.2' - max_amount: '420.69' + volume: 0.69 + num_contracts: 69 summary: Truncated example description: '' /api/info/: diff --git a/tests/test_trade_pipeline.py b/tests/test_trade_pipeline.py index 803c854d..92a3caf5 100644 --- a/tests/test_trade_pipeline.py +++ b/tests/test_trade_pipeline.py @@ -11,7 +11,7 @@ from api.management.commands.follow_invoices import Command as FollowInvoices from api.models import Currency, Order from api.tasks import cache_market, follow_send_payment from control.models import BalanceLog -from control.tasks import compute_node_balance +from control.tasks import compute_node_balance, do_accounting from tests.node_utils import ( add_invoice, create_address, @@ -927,6 +927,31 @@ class TradeTest(BaseAPITestCase): self.assertIsInstance(data[0]["premium"], str) self.assertIsInstance(data[0]["fee"], str) + def test_daily_historical(self): + """ + Tests the daily history serving endpoint after creating a contract + """ + path = reverse("historical") + self.trade_to_confirm_fiat_received_LN(self.maker_form_buy_with_range) + + # Invoke the background thread that will call the celery-worker to follow_send_payment() + self.send_payments() + + # Do daily accounting to create the daily summary + do_accounting() + + response = self.client.get(path) + data = response.json() + + self.assertEqual(response.status_code, 200) + # self.assertResponse(response) # Expects an array, but response is an object + first_date = list(data.keys())[0] + self.assertIsInstance(datetime.fromisoformat(first_date), datetime) + self.assertIsInstance(data[first_date]["volume"], float) + self.assertIsInstance(data[first_date]["num_contracts"], int) + + print(data) + def test_book(self): """ Tests public book view