-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_shop_models.py
97 lines (69 loc) · 2.48 KB
/
test_shop_models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import os
from unittest import TestCase
from flask_bcrypt import Bcrypt
from key import USERNAME, PASSWORD
from models import db, User, Item, Shops, Shops_Item, User_Item
os.environ['DATABASE_URL'] = f"postgresql://{USERNAME}:{PASSWORD}@localhost:5432/markettest"
from app import app
db.create_all()
###
#SETUP
###
class ShopsModelTestCase(TestCase):
def setUp(self):
db.drop_all()
db.create_all()
shop1 = Shops(owner="test_owner",
title="test_shoptitle",
map_location="prontera",
map_x="123",
map_y="321",
timestamp="2022-02-05T22:01:46Z",
req_timestamp="2022-02-06T16:44:01.91Z")
shop1id = 1
shop1.id = shop1id
db.session.add(shop1)
shop1 = Shops.query.get(shop1id)
self.shop1 = shop1
self.shop1_id = shop1id
#now add items
item1 = Item(id="504", name="White Potion")
item1id = 504
item1.id = item1id
item2 = Item(id="505", name="Blue Potion")
item2id = 505
item2.id = item2id
db.session.add(item1, item2)
db.session.commit()
item1 = Item.query.get(504)
self.item1 = item1
self.item1.id = item1id
item2 = Item.query.get(505)
self.item2 = item2
self.item2.id = item2id
#now add shops_items
stock1 = Shops_Item(shop_id="1", item_id=item1.id, price="1337")
stock2 = Shops_Item(shop_id="1", item_id=item2.id, price="42069")
db.session.add(stock1, stock2)
stock = db.session.query(Shops_Item).filter_by(shop_id=="1").all()
stock1 = stock[0]
self.stock1 = stock1
stock2 = stock[1]
self.stock2 = stock2
db.session.commit()
self.client = app.test_client()
def tearDown(self):
db.session.rollback()
###
#tests the db.relationship between Shops and Shops_Item (Shops.stock)
def test_curr_items_relationship(self):
self.assertEqual(shop1.stock, [stock1, stock2])
###
#Test class method
###
def test_search_method_works(self):
shop = Shops.check_if_in_db("test_owner", "2022-02-05T22:01:46Z")
self.assertEqual(shop.id, 1)
def test_search_method_none(self):
shop = Shops.check_if_in_db("shopthatdoesntexist", "1999-05-01")
self.assertEqual(shop.id, None)