Example #1
0
 def check(self, item, operation, response):
     for key in self.prototype:
         value = self.prototype[key]
         cv = CalculatedValue.check(value)
         if cv:
             if cv.operation == operation:
                 item[key] = cv.value
             elif cv.operation == "update" and operation == "create":
                 item[key] = cv.value
         else:
             # a Python object was provided as the prototype value
             # so if the item has a value for that attribute name
             # check to see if it is the right type
             if key in item:
                 if type(item[key]) != type(value):
                     response.status = "error"
                     response.error_type = "InvalidType"
                     msg = "Attribute {} must be of type {}".format(key, type(value))
                     response.error_message = msg
                     return False
             else:
                 item[key] = value
     return True
Example #2
0
 def check(self, item, operation, response):
     for key in self.prototype:
         value = self.prototype[key]
         cv = CalculatedValue.check(value)
         if cv:
             if cv.operation == operation:
                 item[key] = cv.value
             elif cv.operation == 'update' and operation == 'create':
                 item[key] = cv.value
         else:
             # a Python object was provided as the prototype value
             # so if the item has a value for that attribute name
             # check to see if it is the right type
             if key in item:
                 if type(item[key]) != type(value):
                     response.status = 'error'
                     response.error_type = 'InvalidType'
                     msg = 'Attribute {} must be of type {}'.format(
                         key, type(value))
                     response.error_message = msg
                     return False
             else:
                 item[key] = value
     return True
Example #3
0
 def test_bad_token(self):
     cv = CalculatedValue.check('<on-create:foobar>')
     self.assertIsNone(cv)
Example #4
0
 def test_bad_operation(self):
     cv = CalculatedValue.check('<on-foobar:uuid>')
     self.assertIsNone(cv)
Example #5
0
 def test_ts_create(self):
     cv = CalculatedValue.check('<on-create:timestamp>')
     before = int(time.time() * 1000)
     self.assertEqual(cv.operation, 'create')
     self.assertGreaterEqual(cv.value, before)
     self.assertLessEqual(cv.value, int(time.time() * 1000))
Example #6
0
 def test_uuid_update(self):
     cv = CalculatedValue.check('<on-update:uuid>')
     self.assertEqual(cv.operation, 'update')
     self.assertTrue(self.uuid_re.match(cv.value))
 def test_bad_token(self):
     cv = CalculatedValue.check("<on-create:foobar>")
     self.assertIsNone(cv)
 def test_bad_operation(self):
     cv = CalculatedValue.check("<on-foobar:uuid>")
     self.assertIsNone(cv)
 def test_ts_create(self):
     cv = CalculatedValue.check("<on-create:timestamp>")
     before = int(time.time() * 1000)
     self.assertEqual(cv.operation, "create")
     self.assertGreaterEqual(cv.value, before)
     self.assertLessEqual(cv.value, int(time.time() * 1000))
 def test_uuid_update(self):
     cv = CalculatedValue.check("<on-update:uuid>")
     self.assertEqual(cv.operation, "update")
     self.assertTrue(self.uuid_re.match(cv.value))