Add historical api tests

This commit is contained in:
Reckless_Satoshi 2023-11-19 13:44:48 +00:00 committed by Reckless_Satoshi
parent dd7534d64a
commit 6abb84ff5d
3 changed files with 34 additions and 13 deletions

View File

@ -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={
"<date>": {
"code": "USD",
"price": "42069.69",
"min_amount": "4.2",
"max_amount": "420.69",
"volume": 0.69,
"num_contracts": 69,
},
},
status_codes=[200],

View File

@ -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:
- <date>:
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/:

View File

@ -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