updating example env with some common settings and adding bid tests

pull/3/head
lance 5 years ago
parent 34de34f07a
commit 5172433857

@ -14,3 +14,8 @@ WALLET_PORT=38083
WALLET_USER=xxxxxxxxxx WALLET_USER=xxxxxxxxxx
WALLET_PASS=xxxxxxxxxx WALLET_PASS=xxxxxxxxxx
DEBUG=true DEBUG=true
AWS_STORAGE_BUCKET_NAME=xxxxxxxxxx
AWS_S3_CUSTOM_DOMAIN=xxxxxxxxxxxxxxxxx.s3.amazonaws.com
DEBUG=true
GRAFANA_PASSWORD=xxxxxxxxxx
GRAFANA_URL=http://localhost:3000/

@ -8,6 +8,7 @@ from django.test.client import Client
from items.models import Item from items.models import Item
from bids.models import ItemBid from bids.models import ItemBid
from bids.forms import CreateItemBidForm from bids.forms import CreateItemBidForm
from sales.models import ItemSale
class ItemBidViewsTestCase(TestCase): class ItemBidViewsTestCase(TestCase):
@ -169,6 +170,17 @@ class ItemBidViewsTestCase(TestCase):
##### Edit Bid ##### Edit Bid
def test_edit_bid_requires_auth(self):
new_bid = ItemBid.objects.create(
item=self.test_item,
bidder=self.buyer,
bid_price_xmr=0.2,
return_address=self.return_address
)
response = self.client.get(reverse('edit_bid', args=[new_bid.id])) # anon
self.assertTrue(response.url.startswith(reverse('login')))
self.assertEqual(response.status_code, 302)
def test_edit_bid_redirect_home_if_bid_id_missing(self): def test_edit_bid_redirect_home_if_bid_id_missing(self):
self.client.login(username=self.buyer.username, password=self.buyer_password) self.client.login(username=self.buyer.username, password=self.buyer_password)
response = self.client.get(reverse('edit_bid', args=[9999])) response = self.client.get(reverse('edit_bid', args=[9999]))
@ -315,3 +327,88 @@ class ItemBidViewsTestCase(TestCase):
self.assertEqual(response.url, reverse('get_item', args=[self.test_item.id])) self.assertEqual(response.url, reverse('get_item', args=[self.test_item.id]))
self.assertEqual(response.status_code, 302) self.assertEqual(response.status_code, 302)
self.assertIsNone(buyer_bid) self.assertIsNone(buyer_bid)
##### Accept Bid
def test_accept_bid_requires_auth(self):
new_bid = ItemBid.objects.create(
item=self.test_item,
bidder=self.buyer,
bid_price_xmr=0.2,
return_address=self.return_address
)
response = self.client.get(reverse('accept_bid', args=[new_bid.id])) # anon
self.assertTrue(response.url.startswith(reverse('login')))
self.assertEqual(response.status_code, 302)
self.assertFalse(new_bid.accepted)
def test_accept_bid_redirect_item_if_user_not_seller(self):
new_bid = ItemBid.objects.create(
item=self.test_item,
bidder=self.buyer,
bid_price_xmr=0.1,
return_address=self.return_address
)
self.client.login(username=self.buyer.username, password=self.buyer_password)
response = self.client.get(reverse('accept_bid', args=[new_bid.id]))
self.assertEqual(response.url, reverse('get_item', args=[self.test_item.id]))
self.assertEqual(response.status_code, 302)
self.assertFalse(new_bid.accepted)
def test_accept_bid_redirect_item_if_item_not_available(self):
new_bid = ItemBid.objects.create(
item=self.test_item,
bidder=self.buyer,
bid_price_xmr=0.1,
return_address=self.return_address
)
self.test_item.available = False
self.test_item.save()
self.client.login(username=self.seller.username, password=self.seller_password)
response = self.client.get(reverse('accept_bid', args=[new_bid.id]))
self.assertEqual(response.url, reverse('get_item', args=[self.test_item.id]))
self.assertEqual(response.status_code, 302)
self.assertFalse(new_bid.accepted)
def test_accept_bid_redirect_item_if_bid_accepted_already(self):
new_bid = ItemBid.objects.create(
item=self.test_item,
bidder=self.buyer,
bid_price_xmr=0.1,
return_address=self.return_address,
accepted=True
)
self.client.login(username=self.seller.username, password=self.seller_password)
response = self.client.get(reverse('accept_bid', args=[new_bid.id]))
self.assertEqual(response.url, reverse('get_item', args=[self.test_item.id]))
self.assertEqual(response.status_code, 302)
# def test_accept_bid_redirect_item_if_wallet_not_connected(self):
# new_bid = ItemBid.objects.create(
# item=self.test_item,
# bidder=self.buyer,
# bid_price_xmr=0.1,
# return_address=self.return_address
# )
# self.client.login(username=self.seller.username, password=self.seller_password)
# response = self.client.get(reverse('accept_bid', args=[new_bid.id]))
# self.assertEqual(response.url, reverse('get_item', args=[self.test_item.id]))
# self.assertEqual(response.status_code, 302)
# self.assertFalse(aw.connected)
def test_accept_bid_updates_item_attributes(self):
new_bid = ItemBid.objects.create(
item=self.test_item,
bidder=self.buyer,
bid_price_xmr=0.1,
return_address=self.return_address
)
self.client.login(username=self.seller.username, password=self.seller_password)
response = self.client.get(reverse('accept_bid', args=[new_bid.id]))
item_sale = ItemSale.objects.filter(item=self.test_item, bid=new_bid).first()
updated_bid = ItemBid.objects.get(id=new_bid.id)
self.assertTrue(item_sale)
self.assertTrue(updated_bid.accepted)
self.assertFalse(updated_bid.item.available)
self.assertEqual(response.url, reverse('get_sale', args=[item_sale.id]))
self.assertEqual(response.status_code, 302)

@ -120,11 +120,6 @@ def accept_bid(request, bid_id):
expected_payment_xmr = bid.bid_price_xmr + platform_fee_xmr expected_payment_xmr = bid.bid_price_xmr + platform_fee_xmr
account_label = f'Sale account for Item #{bid.item.id}, Bid #{bid.id}' account_label = f'Sale account for Item #{bid.item.id}, Bid #{bid.id}'
# Do not allow accepting your own bid
if request.user == bid.bidder:
messages.error(request, "You can't accept your own bid.")
return HttpResponseRedirect(reverse('get_item', args=[bid.item.id]))
# Do not allow accepting the bid unless you own the item that received the bid # Do not allow accepting the bid unless you own the item that received the bid
if request.user != bid.item.owner: if request.user != bid.item.owner:
messages.error(request, "You can't accept a bid if you don't own the item.") messages.error(request, "You can't accept a bid if you don't own the item.")

@ -65,4 +65,4 @@ def connect_rpc(rpc_type):
if rpc.connected is False: if rpc.connected is False:
logger.error(f'[ERROR] Auction {rpc_type} is not connected. Stopping task.') logger.error(f'[ERROR] Auction {rpc_type} is not connected. Stopping task.')
return False return False
return rpc return rpc