コード例 #1
0
 def test_get_product_by_id(self):
     """Test for the get product by id endpoint."""
     login = self.autheniticate()
     token = json.loads(login.data.decode()).get('token')
     self.app.post(p_url,
                   data=json.dumps(self.data),
                   headers=dict(Authorization="Bearer " + token),
                   content_type='application/json')
     p = Db.get_product('monster')
     res = self.app.get("/api/v1/products/{}".format(p.id),
                        headers=dict(Authorization="Bearer " + token))
     res1 = json.loads(res.data.decode())
     self.assertEqual(res1['status'], 'Success')
     self.assertEqual(res.status_code, 200)
コード例 #2
0
 def test_make_sale_with_no_num(self):
     """Test for the make sale endpoint."""
     login = self.autheniticate()
     token = json.loads(login.data.decode()).get('token')
     self.app.post(p_url,
                   data=json.dumps(self.p_data),
                   headers=dict(Authorization="Bearer " + token),
                   content_type='application/json')
     p = Db.get_product('monster')
     res = self.app.post("/api/v1/products/{}".format(p.id),
                         data=json.dumps(self.no_data),
                         headers=dict(Authorization="Bearer " + token),
                         content_type='application/json')
     res1 = json.loads(res.data.decode())
     self.assertEqual(res1['message'], 'Please provide the number field')
     self.assertEqual(res.status_code, 406)
コード例 #3
0
 def test_make_sale_with_morenum_than_available(self):
     """Test for the make sale endpoint."""
     login = self.autheniticate()
     token = json.loads(login.data.decode()).get('token')
     self.app.post(p_url,
                   data=json.dumps(self.p_data),
                   headers=dict(Authorization="Bearer " + token),
                   content_type='application/json')
     p = Db.get_product('monster')
     res = self.app.post("/api/v1/products/{}".format(p.id),
                         data=json.dumps(self.m_data),
                         headers=dict(Authorization="Bearer " + token),
                         content_type='application/json')
     res1 = json.loads(res.data.decode())
     self.assertEqual(res1['message'],
                      'There are only 24 monster available')
     self.assertEqual(res.status_code, 400)
コード例 #4
0
 def test_product_update_with_empty_name(self):
     """Test for the add product endpoint."""
     login = self.autheniticate()
     token = json.loads(login.data.decode()).get('token')
     self.app.post(p_url,
                   data=json.dumps(self.data),
                   headers=dict(Authorization="Bearer " + token),
                   content_type='application/json')
     p = Db.get_product('monster')
     url = "/api/v1/products/{}".format(p.id)
     res = self.app.put(url,
                        data=json.dumps(self.e_name),
                        headers=dict(Authorization="Bearer " + token),
                        content_type='application/json')
     res1 = json.loads(res.data.decode())
     self.assertEqual(res1['message'], 'The name can not be empty')
     self.assertEqual(res.status_code, 406)
コード例 #5
0
 def post(self):
     """
     Add a product to the manager
     """
     json_data = request.get_json(force=True)
     product_validator(json_data)
     p = Db.get_product(json_data['name'])
     if p:
         msg = 'Product already exists.Update product inventory instead'
         abort(406, msg)
     email = get_jwt_identity()
     user = Db.get_user(email=email)
     store_id = user.store_id
     new_product = Product(store_id, json_data['name'],
                           json_data['inventory'], json_data['price'])
     Db.products.append(new_product)
     res = new_product.json_dump()
     return {"status": "Success!", "data": res}, 201
コード例 #6
0
 def test_product_update_with_str_inventory(self):
     """Test for the product update endpoint."""
     login = self.autheniticate()
     token = json.loads(login.data.decode()).get('token')
     self.app.post(p_url,
                   data=json.dumps(self.data),
                   headers=dict(Authorization="Bearer " + token),
                   content_type='application/json')
     p = Db.get_product('monster')
     url = "/api/v1/products/{}".format(p.id)
     res = self.app.put(url,
                        data=json.dumps(self.str_data),
                        headers=dict(Authorization="Bearer " + token),
                        content_type='application/json')
     res1 = json.loads(res.data.decode())
     self.assertEqual(res1['message'],
                      'Please make sure the inventory is a number')
     self.assertEqual(res.status_code, 406)