Пример #1
0
 def test_store_relationship(self):
     with self.app_context():
         store = StoreModel("seed store")
         item = ItemModel("beans", 2.00, 1)
         store.save_to_db()
         item.save_to_db()
         self.assertEqual(item.store.name, "seed store")
         self.assertEqual(store.id, 1)
Пример #2
0
    def test_store_relationship(self):

        with self.app_context():
            store = StoreModel('My store')
            item = ItemModel('dress', 19.99, 1)
            store.save_to_db()
            item.save_to_db()
            self.assertEqual(store.items.count(), 1)
            self.assertEqual(store.items.first().name, 'dress')
            self.assertEqual(store.json(), {
                'items': [{
                    'name': 'dress',
                    'price': 19.99
                }],
                'name': 'My store'
            })
Пример #3
0
 def test_delete_store(self):
     with self.app as client:
         with self.app_context():
             StoreModel('test1').save_to_db()
             resp = client.delete('/store/test1')
             self.assertEqual(resp.status_code, 200)
             self.assertDictEqual({'message': 'Store deleted'},
                                  json.loads(resp.data))
Пример #4
0
    def test_crud_store(self):

        with self.app_context():

            store = StoreModel("my store")
            self.assertIsNone(store.find_by_name('my store'))

            store.save_to_db()
            self.assertIsNotNone(store.find_by_name('my store'))

            #self.assertEqual(store.json(),{'items':[{'name':'dress','price':19.99}],'name':'my store'})

            store.delete_from_db()
            self.assertIsNone(store.find_by_name('my store'))
Пример #5
0
 def test_create_store(self):
     with self.app as client:
         with self.app_context():
             resp = client.post('/store/test')
             self.assertEqual(resp.status_code, 201)
             self.assertIsNotNone(StoreModel.find_by_name('test'))
             self.assertDictEqual({
                 'name': 'test',
                 'items': []
             }, json.loads(resp.data))
Пример #6
0
 def test_store_with_store_list(self):
     with self.app as client:
         with self.app_context():
             StoreModel('test').save_to_db()
             response = client.get('/stores')
             self.assertDictEqual(
                 {'stores': [{
                     'name': 'test',
                     'items': []
                 }]}, json.loads(response.data))
Пример #7
0
    def test_crud(self):

        with self.app_context():
            StoreModel("seeds").save_to_db()
            item = ItemModel("beans", 2.00, 1)
            self.assertIsNone(ItemModel.find_by_name("beans"))

            item.save_to_db()
            self.assertIsNotNone(ItemModel.find_by_name("beans"))

            item.delete_from_db()
            self.assertIsNone(ItemModel.find_by_name("seeds"))
Пример #8
0
 def test_store_found_with_items(self):
     with self.app as client:
         with self.app_context():
             StoreModel('test').save_to_db()
             ItemModel('dress', 19.99, 1).save_to_db()
             response = client.get('/store/test', data={'name': 'dress'})
             self.assertEqual(
                 {
                     'items': [{
                         'name': 'dress',
                         'price': 19.99
                     }],
                     'name': 'test'
                 }, json.loads(response.data))
Пример #9
0
    def post(self, name):
        if StoreModel.find_by_name(name):
            return {
                'message':
                "A store with name '{}' already exists.".format(name)
            }, 400

        store = StoreModel(name)
        try:
            store.save_to_db()
        except:
            return {"message": "An error occurred creating the store."}, 500

        return store.json(), 201
Пример #10
0
    def test_store_json(self):
        with self.app_context():
            store = StoreModel('My Store')
            item = ItemModel('Dress', 19.90, 1)
            expected = {'name': 'My Store', 'items': []}
            self.assertDictEqual(store.json(), expected)

            store.save_to_db()
            item.save_to_db()
            expected = expected = {
                'name': 'My Store',
                'items': [{
                    'name': 'Dress',
                    'price': 19.90
                }]
            }
            self.assertDictEqual(store.json(), expected)
Пример #11
0
 def get(self, name):
     store = StoreModel.find_by_name(name)
     if store:
         return store.json()
     return {'message': 'Store not found'}, 404
Пример #12
0
    def delete(self, name):
        store = StoreModel.find_by_name(name)
        if store:
            store.delete_from_db()

        return {'message': 'Store deleted'}
Пример #13
0
 def test_item_model_empty(self):
     with self.app_context():
         store = StoreModel("my store")
         item = ItemModel("dress", 19.99, 1)
         self.assertEqual(store.json(), {'name': 'my store', 'items': []})
         self.assertListEqual(store.items.all(), [])