Beispiel #1
0
    def test_store_not_found(self):
        with self.app() as client:
            with self.app_context():
                resp = client.get('/store/test')

                self.assertEqual(resp.status_code, 404)
                self.assertDictEqual(json.loads(resp.data),
                                     {'message': 'Store not found'})
                self.assertIsNone(StoreModel.find_by_name('test'))
Beispiel #2
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
Beispiel #3
0
    def test_create_store(self):
        with self.app() as client:
            with self.app_context():
                response = client.post('/store/test')

                self.assertIsNotNone(StoreModel.find_by_name('test'))
                self.assertEqual(response.status_code, 201)
                self.assertDictEqual(json.loads(response.data), {
                    'name': 'test',
                    'items': []
                })
Beispiel #4
0
    def post(self, name):
        if StoreModel.find_by_name(name):
            return {"message": "Store already exists"}, 409

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

        return store.json(), 201
Beispiel #5
0
    def test_create_duplicate_store(self):
        with self.app() as client:
            with self.app_context():
                resp1 = client.post('/store/test')

                self.assertIsNotNone(StoreModel.find_by_name('test'))
                self.assertEqual(resp1.status_code, 201)
                self.assertDictEqual(json.loads(resp1.data), {
                    'name': 'test',
                    'items': []
                })

                resp2 = client.post('/store/test')

                self.assertEqual(resp2.status_code, 400)
                self.assertDictEqual(
                    json.loads(resp2.data),
                    {'message': "A store with name 'test' already exists."})
Beispiel #6
0
    def delete(self, name):
        store = StoreModel.find_by_name(name)
        if store:
            store.delete_from_db()

        return {'message': 'Store deleted'}
Beispiel #7
0
 def get(self, name):
     store = StoreModel.find_by_name(name)
     if store:
         return store.json()
     return {'message': 'Store not found'}, 404
Beispiel #8
0
 def get(self, name):
     store = StoreModel.find_by_name(name)
     if store:
         return store.json()
     return {"message": "Store not found"}, 404
Beispiel #9
0
 def delete(self, name):
     store = StoreModel.find_by_name(name)
     if store:
         store.delete()
         return {"message": "Store deleted"}
     return {"message": "Store was not found"}, 404