-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_queries.py
More file actions
229 lines (154 loc) · 6.45 KB
/
test_queries.py
File metadata and controls
229 lines (154 loc) · 6.45 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import sys
import unittest
import os
import rethinkdb as r
from rethinkdb.errors import RqlRuntimeError, RqlDriverError
import sure
import pprint
pp = pprint.PrettyPrinter(indent=2, width=1).pprint
# pp(unittest)
db_name = 'sbf_flask_research'
products_table = 'products'
conn = r.connect(host='localhost', port=28015, db=db_name)
# conn = r.connect(host='localhost', port=28015)
from snowboard_test_data import test_products
from products_service import ProductsService
# pp(products_service)
class PlayQueries(unittest.TestCase):
def setUp(self):
reseed()
self.products_service = ProductsService(conn)
def test_all_products(self):
expected = len(test_products)
results = self.products_service.List()
# pp(results)
len(results).should.equal(expected)
def test_snowboards(self):
product_type = 'snowboards'
expected_length = len([x for x in test_products if (x['product_type'] == 'snowboards')])
results = self.products_service.List(product_type=product_type)
len(results).should.equal(expected_length)
for product in results:
product['product_type'].should.equal(product_type)
def test_mens_snowboards(self):
product_type = 'snowboards'
gender = 'mens'
results = self.products_service.List(product_type=product_type, gender=gender)
len(results).should.be.greater_than(0)
for p in results:
p['product_type'].should.equal(product_type)
p['gender'].should.equal(gender)
def test_womens_snowboards(self):
product_type = 'snowboards'
gender = 'womens'
results = self.products_service.List(product_type=product_type, gender=gender)
len(results).should.be.greater_than(0)
for p in results:
p['product_type'].should.equal(product_type)
p['gender'].should.equal(gender)
def test_snowboards_with_size_157(self):
product_type = 'snowboards'
sizes = [157]
results = self.products_service.List(product_type=product_type, sizes=sizes)
len(results).should.be.greater_than(0)
for product in results:
product['product_type'].should.equal(product_type)
any(x in sizes for x in product['sizes']).should.be.ok
def test_snowboards_mens_with_sizes_160_152(self):
product_type = 'snowboards'
sizes = [160, 152]
gender = 'mens'
results = self.products_service.List(product_type=product_type,
sizes=sizes, gender=gender)
len(results).should.be.greater_than(0)
for product in results:
product['product_type'].should.equal(product_type)
any(x in sizes for x in product['sizes']).should.be.ok
def test_snowboards_with_sizes_160_152(self):
product_type = 'snowboards'
sizes = [160, 152]
results = self.products_service.List(product_type=product_type,
sizes=sizes)
for product in results:
product['product_type'].should.equal(product_type)
any(x in sizes for x in product['sizes']).should.be.ok
def test_snowboards_price_of_102_using_between(self):
product_type = 'snowboards'
price_from = 102.00
price_to = 102.00
results = self.products_service.List(product_type=product_type,
price_range=[price_from, price_to])
for p in results:
p['product_type'].should.equal('snowboards')
p['price'].should.equal(price_from)
p['price'].should.equal(price_to)
def test_snowboards_price_between_100_and_103(self):
product_type = 'snowboards'
price_from = 100.00
price_to = 103.00
results = self.products_service.List(product_type=product_type,
price_range=[price_from, price_to])
for p in results:
p['product_type'].should.equal('snowboards')
p['price'].should.be.greater_than_or_equal_to(price_from)
p['price'].should.be.lower_than_or_equal_to(price_to)
def test_snowboards_price_between_105_33_and_105_99_to_confirm_decimal_usage(self):
# to test decimal stuff
product_type = 'snowboards'
price_from = 105.98
price_to = 105.99
results = self.products_service.List(product_type=product_type,
price_range=[price_from, price_to])
len(results).should_not.equal(0)
for p in results:
p['product_type'].should.equal(product_type)
p['price'].should.be.greater_than_or_equal_to(price_from)
p['price'].should.be.lower_than_or_equal_to(price_to)
def test_snowboards_price_between_105_33_and_105_99_to_confirm_decimal_usage(self):
# to test decimal stuff
product_type = 'snowboards'
price_range = [100.00]
self.products_service.List.when.called_with(
product_type=product_type,
price_range=price_range
).should.throw(
ValueError,
"invalid price_range format. should be like this: [2.33, 4.99]"
)
def test_snowboards_brand_is_libtech(self):
product_type = 'snowboards'
brand_name = 'libtech'
results = self.products_service.List(
product_type=product_type, brand_name=brand_name)
# pp(results)
len(results).should.be.greater_than(0)
for p in results:
p['product_type'].should.equal(product_type)
p['brand']['name'].should.equal(brand_name)
def test_snowboards_page_1_with_page_size_3(self):
pass
def test_snowboards_page_2_with_page_size_3(self):
pass
def test_snowboards_last_page_with_less_results_than_page_size_of_3(self):
pass
def test_snowboards_with_board_feature_reverse_camber(self):
pass
# todo
product_type = 'snowboards'
board_features = ['reverse-camber']
results = self.products_service.List(
product_type=product_type,
board_features=board_features)
# pp(results)
def reseed():
db_list = r.db_list().run(conn)
if db_name not in db_list:
r.db_create(db_name).run(conn)
table_list = r.table_list().run(conn)
if products_table in table_list:
r.table_drop(products_table).run(conn)
r.table_create(products_table).run(conn)
r.table(products_table).insert(test_products).run(conn)
if __name__ == '__main__':
unittest.main()
# reseed()