def post(self, name): if StoreModel.find_by_username(name): return {'message': 'Store already exits'}, 400 store = StoreModel(name) try: store.save_to_db() except: return {'message': "error"}
def test_create_store(self): with self.app() as client: with self.app_context(): response = client.post('/store/test_store') self.assertEqual(response.status_code, 201) self.assertIsNotNone(StoreModel.find_by_username('test_store')) self.assertDictEqual({ 'name': 'test', 'items': [] }, json.loads(response.data))
def delete(self, name): store = StoreModel.find_by_username(name) if store: store.delete_from_db() return {'message':'store deleted'}