Skip to content

Commit

Permalink
Add historical api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Reckless-Satoshi committed Nov 19, 2023
1 parent 467a839 commit 8aa487e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
10 changes: 4 additions & 6 deletions api/oas_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
Expand All @@ -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],
Expand Down
10 changes: 4 additions & 6 deletions docs/assets/schemas/api-latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/:
Expand Down
27 changes: 26 additions & 1 deletion tests/test_trade_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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,
Expand Down Expand Up @@ -927,6 +927,31 @@ def test_ticks(self):
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
Expand Down

0 comments on commit 8aa487e

Please sign in to comment.