Skip to content

Commit

Permalink
Fix Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KoalaSat committed Jun 25, 2024
1 parent 773ff83 commit 030663b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 48 deletions.
50 changes: 3 additions & 47 deletions tests/test_trade_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,16 +447,7 @@ def test_make_and_take_order(self):
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
self.assertEqual(
notifications_data[0]["title"],
f"✅ Hey {str(data['maker_nick'])}, your order was taken by {str(data['taker_nick'])}!🥳",
)
taker_headers = trade.get_robot_auth(trade.taker_index)
response = self.client.get(reverse("notifications"), **taker_headers)
self.assertResponse(response)
notifications_data = list(response.json())
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
self.assertEqual(
notifications_data[0]["title"],
f"✅ Hey {str(data['taker_nick'])}, you just took the order with ID {str(trade.order_id)}.",
f"✅ Hey {str(data['maker_nick'])}, your order with ID {trade.order_id} is public in the order book.",
)

# Cancel order to avoid leaving pending HTLCs after a successful test
Expand Down Expand Up @@ -553,25 +544,6 @@ def test_trade_to_locked_escrow(self):
self.assertTrue(data["taker_locked"])
self.assertTrue(data["escrow_locked"])

maker_headers = trade.get_robot_auth(trade.maker_index)
response = self.client.get(reverse("notifications"), **maker_headers)
self.assertResponse(response)
notifications_data = list(response.json())
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
self.assertEqual(
notifications_data[0]["title"],
f"✅ Hey {data['maker_nick']}, your order was taken by {data['taker_nick']}!🥳",
)
taker_headers = trade.get_robot_auth(trade.taker_index)
response = self.client.get(reverse("notifications"), **taker_headers)
self.assertResponse(response)
notifications_data = list(response.json())
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
self.assertEqual(
notifications_data[0]["title"],
f"✅ Hey {data['maker_nick']}, your order was taken by {data['taker_nick']}!🥳",
)

# Cancel order to avoid leaving pending HTLCs after a successful test
trade.cancel_order(trade.taker_index)

Expand Down Expand Up @@ -685,16 +657,6 @@ def test_trade_to_confirm_fiat_sent_LN(self):
self.assertEqual(data["status_message"], Order.Status(Order.Status.FSE).label)
self.assertTrue(data["is_fiat_sent"])

maker_headers = trade.get_robot_auth(trade.maker_index)
response = self.client.get(reverse("notifications"), **maker_headers)
self.assertResponse(response)
notifications_data = list(response.json())
self.assertEqual(notifications_data[0]["order_id"], trade.order_id)
self.assertEqual(
notifications_data[0]["title"],
f"✅ Hey {data['maker_nick']}, your order w",
)

# Cancel order to avoid leaving pending HTLCs after a successful test
trade.undo_confirm_sent(trade.maker_index)
data = trade.response.json()
Expand Down Expand Up @@ -911,11 +873,7 @@ def test_public_order_expires(self):
"""
trade = Trade(self.client)
trade.publish_order()

# Change order expiry to now
order = Order.objects.get(id=trade.response.json()["id"])
order.expires_at = datetime.now()
order.save()
trade.expire_order()

# Make orders expire
trade.clean_orders()
Expand Down Expand Up @@ -958,9 +916,7 @@ def test_taken_order_expires(self):
trade.lock_taker_bond()

# Change order expiry to now
order = Order.objects.get(id=trade.response.json()["id"])
order.expires_at = datetime.now()
order.save()
trade.expire_order()

# Make orders expire
trade.clean_orders()
Expand Down
10 changes: 9 additions & 1 deletion tests/utils/trade.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from unittest.mock import patch

from datetime import datetime
from django.urls import reverse

from api.management.commands.clean_orders import Command as CleanOrders
Expand Down Expand Up @@ -140,6 +140,7 @@ def follow_hold_invoices(self):
follower = FollowInvoices()
follower.follow_hold_invoices()

@patch("api.tasks.send_notification.delay", send_notification)
def clean_orders(self):
# A background thread checks every 5 second order expirations. We invoke directly during test.
cleaner = CleanOrders()
Expand Down Expand Up @@ -263,3 +264,10 @@ def undo_confirm_sent(self, robot_index=1):
headers = self.get_robot_auth(robot_index)
body = {"action": "undo_confirm"}
self.response = self.client.post(path + params, body, **headers)

@patch("api.tasks.send_notification.delay", send_notification)
def expire_order(self):
# Change order expiry to now
order = Order.objects.get(id=self.order_id)
order.expires_at = datetime.now()
order.save()

0 comments on commit 030663b

Please sign in to comment.