Example #1
0
    def test_store_relashionship(self):

        with self.app_context:
            store = StoreModel('costco')
            item = ItemModel('pc', 1500, 1)

            store.save_to_db()
            item.save_to_db()

            self.assertEqual(item.store.name, 'costco')
    def test_relationship_items(self):
        with self.app_contex():
            store = StoreModel('costco')
            item = ItemModel('pc', 1500, 1)

            store.save_to_db()
            item.save_to_db()

            self.assertEqual(store.items.count(), 1)
            self.assertEqual(store.items.first().name, 'pc')
    def test_jason(self):
        store = StoreModel('costco')
        item = ItemModel('pc', 1500, 1)

        store.save_to_db()
        item.save_to_db()

        expected = {'name': 'costco', 'items': [{'name': 'pc', 'price': 1500}]}

        self.assertEqual(store.json(), expected)
Example #4
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
    def test_crud(self):

        with self.app_contex():
            store = StoreModel('costco')
            self.assertIsNone(StoreModel.find_by_name('costco'))

            store.save_to_db()

            self.assertIsNotNone(StoreModel.find_by_name('test'))

            store.delete_from_db()
            self.assertIsNone(StoreModel.find_by_name('costco'))