mirror of
https://github.com/RoboSats/robosats.git
synced 2025-09-06 21:04:16 +00:00
Tests
This commit is contained in:
@ -284,6 +284,30 @@ paths:
|
|||||||
type: string
|
type: string
|
||||||
description: Reason for the failure
|
description: Reason for the failure
|
||||||
description: ''
|
description: ''
|
||||||
|
/api/notifications/:
|
||||||
|
get:
|
||||||
|
operationId: notifications_list
|
||||||
|
description: Get a list of notifications sent to the robot.
|
||||||
|
summary: Get robot notifications
|
||||||
|
parameters:
|
||||||
|
- in: query
|
||||||
|
name: created_at
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
description: Shows notifications created AFTER this date.
|
||||||
|
tags:
|
||||||
|
- notifications
|
||||||
|
security:
|
||||||
|
- tokenAuth: []
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/Notification'
|
||||||
|
description: ''
|
||||||
/api/order/:
|
/api/order/:
|
||||||
get:
|
get:
|
||||||
operationId: order_retrieve
|
operationId: order_retrieve
|
||||||
@ -1262,6 +1286,19 @@ components:
|
|||||||
* `success` - success
|
* `success` - success
|
||||||
* `error` - error
|
* `error` - error
|
||||||
* `info` - info
|
* `info` - info
|
||||||
|
Notification:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
title:
|
||||||
|
type: string
|
||||||
|
description:
|
||||||
|
type: string
|
||||||
|
order_id:
|
||||||
|
type: integer
|
||||||
|
readOnly: true
|
||||||
|
required:
|
||||||
|
- order_id
|
||||||
|
- title
|
||||||
NullEnum:
|
NullEnum:
|
||||||
enum:
|
enum:
|
||||||
- null
|
- null
|
||||||
|
@ -239,6 +239,16 @@ class TradeTest(BaseAPITestCase):
|
|||||||
self.assertIsNone(data["taker"], "New order's taker is not null")
|
self.assertIsNone(data["taker"], "New order's taker is not null")
|
||||||
self.assert_order_logs(data["id"])
|
self.assert_order_logs(data["id"])
|
||||||
|
|
||||||
|
trade.get_notifications()
|
||||||
|
# Checks
|
||||||
|
self.assertResponse(trade.response)
|
||||||
|
notifications_data = trade.response.json()
|
||||||
|
self.assertEqual(
|
||||||
|
notifications_data.count,
|
||||||
|
0,
|
||||||
|
"There is only one notification",
|
||||||
|
)
|
||||||
|
|
||||||
def test_make_order_on_blocked_country(self):
|
def test_make_order_on_blocked_country(self):
|
||||||
"""
|
"""
|
||||||
Test the creation of an F2F order on a geoblocked location
|
Test the creation of an F2F order on a geoblocked location
|
||||||
@ -347,6 +357,17 @@ class TradeTest(BaseAPITestCase):
|
|||||||
|
|
||||||
self.assert_order_logs(data["id"])
|
self.assert_order_logs(data["id"])
|
||||||
|
|
||||||
|
trade.get_notifications()
|
||||||
|
# Checks
|
||||||
|
self.assertResponse(trade.response)
|
||||||
|
notifications_data = trade.response.json()
|
||||||
|
self.assertEqual(
|
||||||
|
notifications_data.count,
|
||||||
|
1,
|
||||||
|
"There is only one notification",
|
||||||
|
)
|
||||||
|
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
|
||||||
|
|
||||||
def test_pause_unpause_order(self):
|
def test_pause_unpause_order(self):
|
||||||
"""
|
"""
|
||||||
Tests pausing and unpausing a public order
|
Tests pausing and unpausing a public order
|
||||||
@ -369,6 +390,17 @@ class TradeTest(BaseAPITestCase):
|
|||||||
self.assertResponse(trade.response)
|
self.assertResponse(trade.response)
|
||||||
self.assertEqual(data["status_message"], Order.Status(Order.Status.PUB).label)
|
self.assertEqual(data["status_message"], Order.Status(Order.Status.PUB).label)
|
||||||
|
|
||||||
|
trade.get_notifications()
|
||||||
|
# Checks
|
||||||
|
self.assertResponse(trade.response)
|
||||||
|
notifications_data = trade.response.json()
|
||||||
|
self.assertEqual(
|
||||||
|
notifications_data.count,
|
||||||
|
2,
|
||||||
|
"There is only one notification",
|
||||||
|
)
|
||||||
|
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
|
||||||
|
|
||||||
# Cancel order to avoid leaving pending HTLCs after a successful test
|
# Cancel order to avoid leaving pending HTLCs after a successful test
|
||||||
trade.cancel_order()
|
trade.cancel_order()
|
||||||
|
|
||||||
@ -415,6 +447,17 @@ class TradeTest(BaseAPITestCase):
|
|||||||
|
|
||||||
self.assert_order_logs(data["id"])
|
self.assert_order_logs(data["id"])
|
||||||
|
|
||||||
|
trade.get_notifications()
|
||||||
|
# Checks
|
||||||
|
self.assertResponse(trade.response)
|
||||||
|
notifications_data = trade.response.json()
|
||||||
|
self.assertEqual(
|
||||||
|
notifications_data.count,
|
||||||
|
2,
|
||||||
|
"There is only one notification",
|
||||||
|
)
|
||||||
|
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
|
||||||
|
|
||||||
def test_make_and_lock_contract(self):
|
def test_make_and_lock_contract(self):
|
||||||
"""
|
"""
|
||||||
Tests a trade from order creation to taker bond locked.
|
Tests a trade from order creation to taker bond locked.
|
||||||
@ -437,6 +480,17 @@ class TradeTest(BaseAPITestCase):
|
|||||||
self.assertTrue(data["taker_locked"])
|
self.assertTrue(data["taker_locked"])
|
||||||
self.assertFalse(data["escrow_locked"])
|
self.assertFalse(data["escrow_locked"])
|
||||||
|
|
||||||
|
trade.get_notifications()
|
||||||
|
# Checks
|
||||||
|
self.assertResponse(trade.response)
|
||||||
|
notifications_data = trade.response.json()
|
||||||
|
self.assertEqual(
|
||||||
|
notifications_data.count,
|
||||||
|
2,
|
||||||
|
"There is only one notification",
|
||||||
|
)
|
||||||
|
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
|
||||||
|
|
||||||
# Maker GET
|
# Maker GET
|
||||||
trade.get_order(trade.maker_index)
|
trade.get_order(trade.maker_index)
|
||||||
data = trade.response.json()
|
data = trade.response.json()
|
||||||
@ -457,6 +511,17 @@ class TradeTest(BaseAPITestCase):
|
|||||||
self.assertTrue(data["taker_locked"])
|
self.assertTrue(data["taker_locked"])
|
||||||
self.assertFalse(data["escrow_locked"])
|
self.assertFalse(data["escrow_locked"])
|
||||||
|
|
||||||
|
trade.get_notifications()
|
||||||
|
# Checks
|
||||||
|
self.assertResponse(trade.response)
|
||||||
|
notifications_data = trade.response.json()
|
||||||
|
self.assertEqual(
|
||||||
|
notifications_data.count,
|
||||||
|
2,
|
||||||
|
"There is only one notification",
|
||||||
|
)
|
||||||
|
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
|
||||||
|
|
||||||
# Maker cancels order to avoid leaving pending HTLCs after a successful test
|
# Maker cancels order to avoid leaving pending HTLCs after a successful test
|
||||||
trade.cancel_order()
|
trade.cancel_order()
|
||||||
|
|
||||||
@ -483,6 +548,17 @@ class TradeTest(BaseAPITestCase):
|
|||||||
self.assertTrue(data["taker_locked"])
|
self.assertTrue(data["taker_locked"])
|
||||||
self.assertTrue(data["escrow_locked"])
|
self.assertTrue(data["escrow_locked"])
|
||||||
|
|
||||||
|
trade.get_notifications()
|
||||||
|
# Checks
|
||||||
|
self.assertResponse(trade.response)
|
||||||
|
notifications_data = trade.response.json()
|
||||||
|
self.assertEqual(
|
||||||
|
notifications_data.count,
|
||||||
|
3,
|
||||||
|
"There is only one notification",
|
||||||
|
)
|
||||||
|
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
|
||||||
|
|
||||||
# Cancel order to avoid leaving pending HTLCs after a successful test
|
# Cancel order to avoid leaving pending HTLCs after a successful test
|
||||||
trade.cancel_order(trade.taker_index)
|
trade.cancel_order(trade.taker_index)
|
||||||
|
|
||||||
@ -506,6 +582,17 @@ class TradeTest(BaseAPITestCase):
|
|||||||
self.assertEqual(data["status_message"], Order.Status(Order.Status.CHA).label)
|
self.assertEqual(data["status_message"], Order.Status(Order.Status.CHA).label)
|
||||||
self.assertFalse(data["is_fiat_sent"])
|
self.assertFalse(data["is_fiat_sent"])
|
||||||
|
|
||||||
|
trade.get_notifications()
|
||||||
|
# Checks
|
||||||
|
self.assertResponse(trade.response)
|
||||||
|
notifications_data = trade.response.json()
|
||||||
|
self.assertEqual(
|
||||||
|
notifications_data.count,
|
||||||
|
4,
|
||||||
|
"There is only one notification",
|
||||||
|
)
|
||||||
|
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
|
||||||
|
|
||||||
# Cancel order to avoid leaving pending HTLCs after a successful test
|
# Cancel order to avoid leaving pending HTLCs after a successful test
|
||||||
trade.cancel_order(trade.maker_index)
|
trade.cancel_order(trade.maker_index)
|
||||||
trade.cancel_order(trade.taker_index)
|
trade.cancel_order(trade.taker_index)
|
||||||
@ -532,6 +619,17 @@ class TradeTest(BaseAPITestCase):
|
|||||||
self.assertEqual(data["status_message"], Order.Status(Order.Status.CHA).label)
|
self.assertEqual(data["status_message"], Order.Status(Order.Status.CHA).label)
|
||||||
self.assertFalse(data["is_fiat_sent"])
|
self.assertFalse(data["is_fiat_sent"])
|
||||||
|
|
||||||
|
trade.get_notifications()
|
||||||
|
# Checks
|
||||||
|
self.assertResponse(trade.response)
|
||||||
|
notifications_data = trade.response.json()
|
||||||
|
self.assertEqual(
|
||||||
|
notifications_data.count,
|
||||||
|
5,
|
||||||
|
"There is only one notification",
|
||||||
|
)
|
||||||
|
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
|
||||||
|
|
||||||
# Cancel order to avoid leaving pending HTLCs after a successful test
|
# Cancel order to avoid leaving pending HTLCs after a successful test
|
||||||
trade.cancel_order(trade.maker_index)
|
trade.cancel_order(trade.maker_index)
|
||||||
trade.cancel_order(trade.taker_index)
|
trade.cancel_order(trade.taker_index)
|
||||||
@ -556,6 +654,17 @@ class TradeTest(BaseAPITestCase):
|
|||||||
self.assertEqual(data["status_message"], Order.Status(Order.Status.FSE).label)
|
self.assertEqual(data["status_message"], Order.Status(Order.Status.FSE).label)
|
||||||
self.assertTrue(data["is_fiat_sent"])
|
self.assertTrue(data["is_fiat_sent"])
|
||||||
|
|
||||||
|
trade.get_notifications()
|
||||||
|
# Checks
|
||||||
|
self.assertResponse(trade.response)
|
||||||
|
notifications_data = trade.response.json()
|
||||||
|
self.assertEqual(
|
||||||
|
notifications_data.count,
|
||||||
|
6,
|
||||||
|
"There is only one notification",
|
||||||
|
)
|
||||||
|
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
|
||||||
|
|
||||||
# Cancel order to avoid leaving pending HTLCs after a successful test
|
# Cancel order to avoid leaving pending HTLCs after a successful test
|
||||||
trade.undo_confirm_sent(trade.maker_index)
|
trade.undo_confirm_sent(trade.maker_index)
|
||||||
data = trade.response.json()
|
data = trade.response.json()
|
||||||
@ -595,6 +704,17 @@ class TradeTest(BaseAPITestCase):
|
|||||||
|
|
||||||
self.assert_order_logs(data["id"])
|
self.assert_order_logs(data["id"])
|
||||||
|
|
||||||
|
trade.get_notifications()
|
||||||
|
# Checks
|
||||||
|
self.assertResponse(trade.response)
|
||||||
|
notifications_data = trade.response.json()
|
||||||
|
self.assertEqual(
|
||||||
|
notifications_data.count,
|
||||||
|
7,
|
||||||
|
"There is only one notification",
|
||||||
|
)
|
||||||
|
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
|
||||||
|
|
||||||
def test_successful_LN(self):
|
def test_successful_LN(self):
|
||||||
"""
|
"""
|
||||||
Tests a trade from order creation until Sats sent to buyer
|
Tests a trade from order creation until Sats sent to buyer
|
||||||
@ -702,6 +822,17 @@ class TradeTest(BaseAPITestCase):
|
|||||||
"This order has been cancelled collaborativelly",
|
"This order has been cancelled collaborativelly",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
trade.get_notifications()
|
||||||
|
# Checks
|
||||||
|
self.assertResponse(trade.response)
|
||||||
|
notifications_data = trade.response.json()
|
||||||
|
self.assertEqual(
|
||||||
|
notifications_data.count,
|
||||||
|
6,
|
||||||
|
"There is only one notification",
|
||||||
|
)
|
||||||
|
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
|
||||||
|
|
||||||
def test_created_order_expires(self):
|
def test_created_order_expires(self):
|
||||||
"""
|
"""
|
||||||
Tests the expiration of a public order
|
Tests the expiration of a public order
|
||||||
@ -734,6 +865,17 @@ class TradeTest(BaseAPITestCase):
|
|||||||
|
|
||||||
self.assert_order_logs(data["id"])
|
self.assert_order_logs(data["id"])
|
||||||
|
|
||||||
|
trade.get_notifications()
|
||||||
|
# Checks
|
||||||
|
self.assertResponse(trade.response)
|
||||||
|
notifications_data = trade.response.json()
|
||||||
|
self.assertEqual(
|
||||||
|
notifications_data.count,
|
||||||
|
6,
|
||||||
|
"There is only one notification",
|
||||||
|
)
|
||||||
|
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
|
||||||
|
|
||||||
def test_public_order_expires(self):
|
def test_public_order_expires(self):
|
||||||
"""
|
"""
|
||||||
Tests the expiration of a public order
|
Tests the expiration of a public order
|
||||||
@ -767,6 +909,17 @@ class TradeTest(BaseAPITestCase):
|
|||||||
|
|
||||||
self.assert_order_logs(data["id"])
|
self.assert_order_logs(data["id"])
|
||||||
|
|
||||||
|
trade.get_notifications()
|
||||||
|
# Checks
|
||||||
|
self.assertResponse(trade.response)
|
||||||
|
notifications_data = trade.response.json()
|
||||||
|
self.assertEqual(
|
||||||
|
notifications_data.count,
|
||||||
|
6,
|
||||||
|
"There is only one notification",
|
||||||
|
)
|
||||||
|
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
|
||||||
|
|
||||||
def test_taken_order_expires(self):
|
def test_taken_order_expires(self):
|
||||||
"""
|
"""
|
||||||
Tests the expiration of a public order
|
Tests the expiration of a public order
|
||||||
@ -802,6 +955,17 @@ class TradeTest(BaseAPITestCase):
|
|||||||
|
|
||||||
self.assert_order_logs(data["id"])
|
self.assert_order_logs(data["id"])
|
||||||
|
|
||||||
|
trade.get_notifications()
|
||||||
|
# Checks
|
||||||
|
self.assertResponse(trade.response)
|
||||||
|
notifications_data = trade.response.json()
|
||||||
|
self.assertEqual(
|
||||||
|
notifications_data.count,
|
||||||
|
6,
|
||||||
|
"There is only one notification",
|
||||||
|
)
|
||||||
|
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
|
||||||
|
|
||||||
def test_escrow_locked_expires(self):
|
def test_escrow_locked_expires(self):
|
||||||
"""
|
"""
|
||||||
Tests the expiration of a public order
|
Tests the expiration of a public order
|
||||||
@ -890,6 +1054,17 @@ class TradeTest(BaseAPITestCase):
|
|||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(response.json(), {}) # Nothing in the response
|
self.assertEqual(response.json(), {}) # Nothing in the response
|
||||||
|
|
||||||
|
trade.get_notifications()
|
||||||
|
# Checks
|
||||||
|
self.assertResponse(trade.response)
|
||||||
|
notifications_data = trade.response.json()
|
||||||
|
self.assertEqual(
|
||||||
|
notifications_data.count,
|
||||||
|
8,
|
||||||
|
"There is only one notification",
|
||||||
|
)
|
||||||
|
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
|
||||||
|
|
||||||
# Get the two chatroom messages as maker
|
# Get the two chatroom messages as maker
|
||||||
response = self.client.get(path + params, **maker_headers)
|
response = self.client.get(path + params, **maker_headers)
|
||||||
self.assertResponse(response)
|
self.assertResponse(response)
|
||||||
|
@ -111,6 +111,15 @@ class Trade:
|
|||||||
headers = self.get_robot_auth(robot_index, first_encounter)
|
headers = self.get_robot_auth(robot_index, first_encounter)
|
||||||
self.response = self.client.get(path + params, **headers)
|
self.response = self.client.get(path + params, **headers)
|
||||||
|
|
||||||
|
def get_notifications(self, created_at=0, robot_index=1, first_encounter=False):
|
||||||
|
"""
|
||||||
|
Fetch the latest state of the order
|
||||||
|
"""
|
||||||
|
path = reverse("notifications")
|
||||||
|
params = f"?created_at={created_at}"
|
||||||
|
headers = self.get_robot_auth(robot_index, first_encounter)
|
||||||
|
self.response = self.client.get(path + params, **headers)
|
||||||
|
|
||||||
@patch("api.tasks.send_notification.delay", send_notification)
|
@patch("api.tasks.send_notification.delay", send_notification)
|
||||||
def cancel_order(self, robot_index=1):
|
def cancel_order(self, robot_index=1):
|
||||||
path = reverse("order")
|
path = reverse("order")
|
||||||
|
Reference in New Issue
Block a user