def test_b_001_02_02_ProductUpdate(self): toValidate = {"code": 789456611} try: product = ProductUpdate(**toValidate) self.assertEqual(True, False) except Exception as e: #print(json.loads(e.json())) self.assertEqual(json.loads(e.json()), [{ 'loc': ['id'], 'msg': 'field required', 'type': 'value_error.missing' }, { 'loc': ['name'], 'msg': 'field required', 'type': 'value_error.missing' }, { 'loc': ['price'], 'msg': 'field required', 'type': 'value_error.missing' }, { 'loc': ['quantity'], 'msg': 'field required', 'type': 'value_error.missing' }]) print("Test b_1_2_2:ProductUpdate:Fail:all missing required")
def test_b_001_02_01_ProductUpdate(self): toValidate = { "id": 1, "name": " abcdef ", "price": 123.1, "quantity": 400.12, "code": 798 } product = ProductUpdate(**toValidate) self.assertEqual( product.dict(), { "id": 1, "name": "abcdef", "price": 123.1, "quantity": 400.12, "code": 798 }) print("Test b_1_2_1:ProductUpdate Successful")
def put_products(request, id, product: ProductBasic): product = product.dict() product["id"] = id try: product = ProductUpdate(**product) except Exception as e: return jsoinify_error(e) product_record = Product.query().get(product.id) product_record.update(**product.dict()) return {"suucess": True, "product": product_record.deep()}
def test_b_001_02_08_ProductUpdate(self): # id did not succeed, code will just be passed toValidate = { "id": 1, "name": "abacdegfgh", "price": 100, "quantity": 10, "code": "789456611" } product = ProductUpdate(**toValidate) self.assertEqual( product.dict(), { "id": 1, "name": "abacdegfgh", "price": 100, "quantity": 10, "code": 789456611 }) print("Test b_1_2_8:ProductUpdate:same code, same product")
def test_b_001_02_07_ProductUpdate(self): # id did not succeed, code will just be passed toValidate = { "id": 1, "name": "abacdegfgh", "price": 100, "quantity": 10, "code": "8754653216576" } product = ProductUpdate(**toValidate) self.assertEqual( product.dict(), { "id": 1, "name": "abacdegfgh", "price": 100, "quantity": 10, "code": 8754653216576 }) print("Test b_1_2_7:ProductUpdate:new code")
def test_b_001_02_05_ProductUpdate(self): # id: nonexistent # name : long # price : very expensive # quantity : very big # code: very big toValidate = { "id": 1000000, "name": "a" * 700000, "price": 10000000000000000000, "quantity": 1000000000, "code": 1000000000000000000000000000000000 } try: product = ProductUpdate(**toValidate) self.assertEqual(True, False) except Exception as e: #print(json.loads(e.json())) self.assertEqual(json.loads(e.json()), [{ 'loc': ['id'], 'msg': 'there is no Product with this id: 1000000', 'type': 'value_error' }, { 'loc': ['name'], 'msg': 'ensure this value has at most 300 characters', 'type': 'value_error.any_str.max_length', 'ctx': { 'limit_value': 300 } }, { 'loc': ['price'], 'msg': 'ensure this value is less than or equal to 1000000', 'type': 'value_error.number.not_le', 'ctx': { 'limit_value': 1000000 } }, { 'loc': ['quantity'], 'msg': 'ensure this value is less than or equal to 100000000', 'type': 'value_error.number.not_le', 'ctx': { 'limit_value': 100000000 } }, { 'loc': ['code'], 'msg': 'ensure this value is less than or equal to' + ' 100000000000000000000000000', 'type': 'value_error.number.not_le', 'ctx': { 'limit_value': 100000000000000000000000000 } }]) print("Test b_1_2_5:ProductUpdate:Fail:big data")
def test_b_001_02_04_ProductUpdate(self): # id: very small # name : short # price : very cheap # quantity : very small # code: very small toValidate = { "id": 0, "name": " a ", "price": .00000000000001, "quantity": .000000001, "code": 1 } try: product = ProductUpdate(**toValidate) self.assertEqual(True, False) except Exception as e: #print(json.loads(e.json())) self.assertEqual(json.loads(e.json()), [{ 'loc': ['id'], 'msg': 'ensure this value is greater than 0', 'type': 'value_error.number.not_gt', 'ctx': { 'limit_value': 0 } }, { 'loc': ['name'], 'msg': 'ensure this value has at least 3 characters', 'type': 'value_error.any_str.min_length', 'ctx': { 'limit_value': 3 } }, { 'loc': ['price'], 'msg': 'ensure this value is greater than or equal to 0.1', 'type': 'value_error.number.not_ge', 'ctx': { 'limit_value': 0.1 } }, { 'loc': ['quantity'], 'msg': 'ensure this value is greater than or equal to 0.001', 'type': 'value_error.number.not_ge', 'ctx': { 'limit_value': 0.001 } }, { 'loc': ['code'], 'msg': 'ensure this value is greater than or equal to 2', 'type': 'value_error.number.not_ge', 'ctx': { 'limit_value': 2 } }]) print("Test b_1_2_4:ProductUpdate:Fail:short data")
def test_b_001_02_09_ProductUpdate(self): # id did not succeed, code will just be passed toValidate = { "id": 1, "name": "abacdegfgh", "price": 100, "quantity": 10, "code": "8444441" } try: product = ProductUpdate(**toValidate) self.assertEqual(True, False) except Exception as e: #print(json.loads(e.json())) self.assertEqual(json.loads(e.json()), [{ 'loc': ['code'], 'msg': 'this code is already related to another product', 'type': 'value_error' }]) print("Test b_1_2_9:ProductUpdate: id did not succeed, " + "code will just be passed")
def test_b_001_02_06_ProductUpdate(self): # id did not succeed, code will just be passed toValidate = { "id": 1000000000000, "name": "abacdegfgh", "price": 100, "quantity": 10, "code": "123456" } try: product = ProductUpdate(**toValidate) self.assertEqual(True, False) except Exception as e: #print(json.loads(e.json())) self.assertEqual(json.loads(e.json()), [{ 'loc': ['id'], 'msg': 'there is no Product with this id: 1000000000000', 'type': 'value_error' }]) print("Test b_1_2_6:ProductUpdate: id did not succeed, " + "code will just be passed")
def test_b_001_02_03_ProductUpdate(self): toValidate = { "id": {}, "name": {}, "price": {}, "quantity": {}, "code": {} } try: product = ProductUpdate(**toValidate) self.assertEqual(True, False) except Exception as e: #print(json.loads(e.json())) self.assertEqual(json.loads(e.json()), [{ 'loc': ['id'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer' }, { 'loc': ['name'], 'msg': 'str type expected', 'type': 'type_error.str' }, { 'loc': ['price'], 'msg': 'value is not a valid float', 'type': 'type_error.float' }, { 'loc': ['quantity'], 'msg': 'value is not a valid float', 'type': 'type_error.float' }, { 'loc': ['code'], 'msg': 'value is not a valid integer', 'type': 'type_error.integer' }]) print("Test b_1_2_3:ProductUpdate:Fail:not string")