|
1 |
| -from models.store import StoreModel |
2 | 1 | from models.item import ItemModel
|
| 2 | +from models.store import StoreModel |
3 | 3 | from tests.base_test import BaseTest
|
| 4 | +import json |
4 | 5 |
|
5 | 6 |
|
6 | 7 | class StoreTest(BaseTest):
|
7 |
| - pass |
| 8 | + def test_store_not_found(self): |
| 9 | + with self.app() as c: |
| 10 | + r = c.get('/store/test') |
| 11 | + self.assertEqual(r.status_code, 404) |
| 12 | + |
| 13 | + def test_store_found(self): |
| 14 | + with self.app() as c: |
| 15 | + with self.app_context(): |
| 16 | + StoreModel('test').save_to_db() |
| 17 | + r = c.get('/store/test') |
| 18 | + |
| 19 | + self.assertEqual(r.status_code, 200) |
| 20 | + self.assertDictEqual(d1={'name': 'test', 'items': []}, |
| 21 | + d2=json.loads(r.data)) |
| 22 | + |
| 23 | + def test_store_with_items_found(self): |
| 24 | + with self.app() as c: |
| 25 | + with self.app_context(): |
| 26 | + StoreModel('test').save_to_db() |
| 27 | + ItemModel('test', 2.99, 1).save_to_db() |
| 28 | + r = c.get('/store/test') |
| 29 | + |
| 30 | + self.assertEqual(r.status_code, 200) |
| 31 | + self.assertDictEqual(d1={'name': 'test', 'items': [{'name': 'test', 'price': 2.99}]}, |
| 32 | + d2=json.loads(r.data)) |
| 33 | + |
| 34 | + def test_delete_store(self): |
| 35 | + with self.app() as c: |
| 36 | + with self.app_context(): |
| 37 | + StoreModel('test').save_to_db() |
| 38 | + r = c.delete('/store/test') |
| 39 | + |
| 40 | + self.assertEqual(r.status_code, 200) |
| 41 | + self.assertDictEqual(d1={'message': 'Store deleted'}, |
| 42 | + d2=json.loads(r.data)) |
| 43 | + |
| 44 | + def test_create_store(self): |
| 45 | + with self.app() as c: |
| 46 | + with self.app_context(): |
| 47 | + r = c.post('/store/test') |
| 48 | + |
| 49 | + self.assertEqual(r.status_code, 201) |
| 50 | + self.assertIsNotNone(StoreModel.find_by_name('test')) |
| 51 | + self.assertDictEqual(d1={'name': 'test', 'items': []}, |
| 52 | + d2=json.loads(r.data)) |
| 53 | + |
| 54 | + def test_create_duplicate_store(self): |
| 55 | + with self.app() as c: |
| 56 | + with self.app_context(): |
| 57 | + c.post('/store/test') |
| 58 | + r = c.post('/store/test') |
| 59 | + |
| 60 | + self.assertEqual(r.status_code, 400) |
| 61 | + |
| 62 | + def test_store_list(self): |
| 63 | + with self.app() as c: |
| 64 | + with self.app_context(): |
| 65 | + StoreModel('test').save_to_db() |
| 66 | + r = c
EDBE
span>.get('/stores') |
| 67 | + |
| 68 | + self.assertDictEqual(d1={'stores': [{'name': 'test', 'items': []}]}, |
| 69 | + d2=json.loads(r.data)) |
| 70 | + |
| 71 | + def test_store_with_items_list(self): |
| 72 | + with self.app() as c: |
| 73 | + with self.app_context(): |
| 74 | + StoreModel('test').save_to_db() |
| 75 | + ItemModel('test', 17.99, 1).save_to_db() |
| 76 | + r = c.get('/stores') |
| 77 | + |
| 78 | + self.assertDictEqual(d1={'stores': [{'name': 'test', 'items': [{'name': 'test', 'price': 17.99}]}]}, |
| 79 | + d2=json.loads(r.data)) |
0 commit comments