From 88f1e5db3072b668f7bbfce3e141dcdf4869e883 Mon Sep 17 00:00:00 2001 From: lance Date: Tue, 28 Jan 2020 22:31:53 -0800 Subject: [PATCH] adding tests for bids --- bids/tests/test_models.py | 8 ++++- bids/tests/test_views.py | 63 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 bids/tests/test_views.py diff --git a/bids/tests/test_models.py b/bids/tests/test_models.py index 6fe6f01..2ce40bb 100644 --- a/bids/tests/test_models.py +++ b/bids/tests/test_models.py @@ -2,12 +2,14 @@ from secrets import token_urlsafe from monero.seed import Seed from django.test import TestCase from django.contrib.auth.models import User +from django.test.client import Client from bids.models import ItemBid from items.models import Item class ItemBidModelsTestCase(TestCase): def setUp(self): + self.client = Client() self.seller_password = token_urlsafe(32) self.buyer_password = token_urlsafe(32) @@ -39,4 +41,8 @@ class ItemBidModelsTestCase(TestCase): ) obj_name = f'{test_itembid.id} - {test_itembid.item.name} - {test_itembid.bidder} > {test_itembid.item.owner}' self.assertTrue(isinstance(test_itembid, ItemBid)) - self.assertEqual(test_itembid.__str__(), obj_name) \ No newline at end of file + self.assertEqual(test_itembid.__str__(), obj_name) + + + + diff --git a/bids/tests/test_views.py b/bids/tests/test_views.py new file mode 100644 index 0000000..8a3119e --- /dev/null +++ b/bids/tests/test_views.py @@ -0,0 +1,63 @@ +from secrets import token_urlsafe +from monero.seed import Seed +from django.test import TestCase +from django.contrib.auth.models import User +from django.core.paginator import Page +from django.shortcuts import reverse +from django.test.client import Client +from items.models import Item +from bids.models import ItemBid +from bids.views import list_bids + + +class ItemBidModelsTestCase(TestCase): + def setUp(self): + self.client = Client() + self.seller_password = token_urlsafe(32) + self.buyer_password = token_urlsafe(32) + + self.seller = User.objects.create_user( + 'seller', password=self.seller_password + ) + self.buyer = User.objects.create_user( + 'buyer', password=self.buyer_password + ) + self.payout_address = Seed().public_address() + self.return_address = Seed().public_address() + self.whereabouts = 'Los Angeles, CA' + + self.test_item = Item.objects.create( + owner=self.seller, + name='Test Item', + description='Test item', + ask_price_xmr=0.3, + payout_address=self.payout_address, + whereabouts=self.whereabouts + ) + + def test_list_bids_requires_auth(self): + response = self.client.get(reverse('list_bids')) + request = response.wsgi_request + response = list_bids(request) + self.assertTrue(response.url.startswith(reverse('login'))) + self.assertEqual(response.status_code, 302) + + + def test_list_bids_returns_pagination(self): + ItemBid.objects.create( + item=self.test_item, + bidder=self.buyer, + bid_price_xmr=0.1, + return_address=self.return_address + ) + self.client.login(username='buyer', password=self.buyer_password) + response = self.client.get(reverse('list_bids')) + response_w_str_arg = self.client.get(reverse('list_bids') + "?page=bar") + response_w_empty_pg = self.client.get(reverse('list_bids') + "?page=9001") + self.client.logout() + self.assertTrue(isinstance(response.context['bids'], Page), 'Paginated object not returned') + self.assertTrue(isinstance(response_w_str_arg.context['bids'], Page), 'Paginated object not returned') + self.assertTrue(isinstance(response_w_empty_pg.context['bids'], Page), 'Paginated object not returned') + + def test_list_bids_returns_only_user_bids(self): + pass