Ejemplo n.º 1
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
Ejemplo n.º 2
0
    def test_item_json(self):

        with self.app_context():
            store = StoreModel('test store')
            item = ItemModel('test item', 19.99, 1)

            store.save_to_db()
            item.save_to_db()

            item_json = item.json()

            expected = {'name': 'test item', 'price': 19.99}

            self.assertDictEqual(expected, item_json)