Example #1
0
    def post(self, name):
        if StoreModel.find_by_name(name):
            return {
                'Message': 'Store name {} already exists.'.format(name)
            }, 400

        store = StoreModel(name)
        try:
            store.save_db()
        except:
            return {'Message': 'An Error Occuured While creating store'}
        return store.json(), 201
    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
Example #3
0
    def post(self, name):
        store = StoreModel.find_by_name(name)
        if store:
            return {'message': 'Store already exists.'}, 400  # Bad Request

        store = StoreModel(name)
        try:
            store.save_to_db()
        except:
            return {
                'message':
                'An error occurred attempting to save the store to the database'
            }, 500  # Internal Server Error

        return store.json(), 201  # Created
Example #4
0
    def test_json_with_item(self):
        with self.app_context():
            store = StoreModel("Costco")
            item = ItemModel("ham", 20.11, 1)

            store.save_to_db()
            item.save_to_db()

            expected = {
                "name": "Costco",
                "item_list": [{
                    "name": "ham",
                    "price": 20.11
                }]
            }

            self.assertDictEqual(store.json(), expected)
Example #5
0
    def post(self):
        """
        Create a new Store
        POST /store
        """
        parser = reqparse.RequestParser()
        parser.add_argument('store_name',
                            type=str,
                            required=True,
                            help="Store Name couldn't be blank")
        data = parser.parse_args()

        name = data['store_name']

        exist = StoreModel.find_by_name(name)

        if exist:
            return {"message": "Store already exist!"}, 409

        store = StoreModel(name)
        store.save_to_db()

        return store.json(), 201
Example #6
0
    def test_json(self):
        store = StoreModel('Costco')
        expected = {"name": "Costco", "item_list": []}

        self.assertDictEqual(store.json(), expected)