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_store_json_with_item(self): with self.app_context(): store = StoreModel("test_store") item = ItemModel("test_item", 12.99, 1) store.save_to_db() item.save_to_db() expected = { "id": 1, "name": "test_store", "items": [{ "name": "test_item", "price": 12.99 }] } self.assertDictEqual(expected, store.json())
def test_store_json(self): store = StoreModel("test_store") expected = {"id": None, "name": "test_store", "items": []} self.assertDictEqual(expected, store.json())