Esempio n. 1
0
class DataBaseIntegrationTests(BaseTest):
    def test_user_model_crud(self):
        self.user_model = UserModel(6, 'TestUser', '*****@*****.**')
        self.assertIsNone(self.user_model.find_by_name('TestUser'))
        self.user_model.insert_into_table(self.user_model.username,
                                          self.user_model.password)
        self.assertIsNotNone(self.user_model.find_by_name('TestUser'))

    def test_store_model_crud(self):
        self.store_model = StoreModel(6, 'TestProduct', 19.99)
        self.assertIsNone(self.store_model.find_by_product('TestProduct'))
        self.assertIsNotNone(self.store_model.find_by_product('car_1'))
Esempio n. 2
0
    def post(self, product):
        product = StoreModel.find_by_product(product)
        if product:
            return {'message': 'Product already in database!'}
        else:
            parser = reqparse.RequestParser()
            parser.add_argument('product',
                                type=str,
                                required=True,
                                help='This field is mandatory!')
            parser.add_argument('price',
                                type=float,
                                required=True,
                                help='This field is mandatory!')

            data_payload = parser.parse_args()

            StoreModel.add_product(data_payload['product'],
                                   data_payload['price'])
            return {'message': 'Product successfully added to database!'}, 201
Esempio n. 3
0
 def get(self, product):
     products = StoreModel.find_by_product(product)
     if products:
         return {'product': [product.json() for product in products]}, 200
     else:
         return {'message': 'Product not found!'}, 404