Esempio n. 1
0
 def test_b_002_02_06_CategoryUpdate(self):
     # id did not succeed, code will just be passed
     toValidate = {
         "id": 1000000000000,
         "name": "abacdegfgh",
         "price": 100,
         "quantity": 10,
         "code": "123456"
     }
     try:
         category = CategoryUpdate(**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 Category with this id: 1000000000000',
                 'type': 'value_error'
             }, {
                 'loc': ['parent_id'],
                 'msg': 'field required',
                 'type': 'value_error.missing'
             }])
     print("Test b_2_2_6:CategoryUpdate: id did not succeed, " +
           "code will just be passed")
Esempio n. 2
0
 def test_b_002_02_05_CategoryUpdate(self):
     # id: nonexistent
     # name : long
     # parent_id: non existent
     toValidate = {"id": 1000000, "name": "a" * 700000, "parent_id": 100000}
     try:
         category = CategoryUpdate(**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 Category 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': ['parent_id'],
             'msg': 'there is no Category with this id: 100000',
             'type': 'value_error'
         }])
     print("Test b_2_2_5:CategoryUpdate:Fail:big data")
Esempio n. 3
0
 def test_b_002_02_04_CategoryUpdate(self):
     # id: very small
     # name : short
     # parent_id : very small
     toValidate = {"id": 0, "name": "   a   ", "parent_id": -1}
     try:
         category = CategoryUpdate(**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': ['parent_id'],
             'msg': 'ensure this value is greater than or equal to 0',
             'type': 'value_error.number.not_ge',
             'ctx': {
                 'limit_value': 0
             }
         }])
     print("Test b_2_2_4:CategoryUpdate:Fail:short data")
Esempio n. 4
0
def put_categories(request, id, category: CategoryBasic):
    category = category.dict()
    category["id"] = id
    try:
        category = CategoryUpdate(**category)
    except Exception as e:
        return jsoinify_error(e)
    category_record = Category.query().get(category.id)
    category_record.update(**category.dict())
    return {"suucess": True, "category": category_record.deep()}
Esempio n. 5
0
 def test_b_002_02_08_CategoryUpdate(self):
     # name of the same category repeated, parent_id = same category
     toValidate = {"id": 1, "name": "Cars", "parent_id": 1}
     try:
         category = CategoryUpdate(**toValidate)
         self.assertEqual(True, False)
     except Exception as e:
         #print(json.loads(e.json()))
         self.assertEqual(json.loads(e.json()), [{
             'loc': ['name'],
             'msg': 'this name is already related to another category',
             'type': 'value_error'
         }, {
             'loc': ['parent_id'],
             'msg': 'a category can not be a parent to itself',
             'type': 'value_error'
         }])
     print("Test b_2_2_8:CategoryUpdate:same code, same category")
Esempio n. 6
0
 def test_b_002_02_07_CategoryUpdate(self):
     # id did not succeed, parent_id and name will just pass
     toValidate = {"id": 100000000, "name": "Electronics", "parent_id": 100}
     try:
         category = CategoryUpdate(**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 Category with this id: 100000000',
             'type': 'value_error'
         }, {
             'loc': ['parent_id'],
             'msg': 'there is no Category with this id: 100',
             'type': 'value_error'
         }])
     print("Test b_2_2_7:CategoryUpdate:new code")
Esempio n. 7
0
 def test_b_002_02_03_CategoryUpdate(self):
     toValidate = {"id": {}, "name": {}, "parent_id": {}}
     try:
         category = CategoryUpdate(**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': ['parent_id'],
                              'msg': 'value is not a valid integer',
                              'type': 'type_error.integer'
                          }])
     print("Test b_2_2_3:CategoryUpdate:Fail:not string")
Esempio n. 8
0
 def test_b_002_02_02_CategoryUpdate(self):
     toValidate = {}
     try:
         category = CategoryUpdate(**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': ['parent_id'],
                              'msg': 'field required',
                              'type': 'value_error.missing'
                          }])
     print("Test b_2_2_2:CategoryUpdate:Fail:all missing required")
Esempio n. 9
0
    def test_b_002_02_01_CategoryUpdate(self):
        toValidate = {"id": 2, "name": " abcdef ", "parent_id": 1}
        category = CategoryUpdate(**toValidate)
        self.assertEqual(category.dict(), {
            "id": 2,
            "name": "abcdef",
            "parent_id": 1
        })

        # In case of 0 => None
        toValidate = {"id": 1, "name": " abcdef ", "parent_id": 0}
        category = CategoryUpdate(**toValidate)
        self.assertEqual(category.dict(), {
            "id": 1,
            "name": "abcdef",
            "parent_id": None
        })

        print("Test b_2_2_1:CategoryUpdate Successful")