Пример #1
0
def validate_to_run_key(task_key):
    """Validates a ndb.Key to a TaskToRun entity. Raises ValueError if invalid."""
    # This also validates the key kind.
    request_key = task_to_run_key_to_request_key(task_key)
    key_id = task_key.integer_id()
    if not key_id or key_id >= 2**32:
        raise ValueError(
            'TaskToRun key id should be between 1 and 2**32, found %s' %
            task_key.id())
    task_request.validate_request_key(request_key)
Пример #2
0
def validate_to_run_key(task_key):
  """Validates a ndb.Key to a TaskToRun entity. Raises ValueError if invalid."""
  # This also validates the key kind.
  request_key = task_to_run_key_to_request_key(task_key)
  key_id = task_key.integer_id()
  if not key_id or key_id >= 2**32:
    raise ValueError(
        'TaskToRun key id should be between 1 and 2**32, found %s' %
        task_key.id())
  task_request.validate_request_key(request_key)
Пример #3
0
 def test_validate_request_key(self):
     task_request.validate_request_key(task_pack.unpack_request_key("10"))
     task_request.validate_request_key(
         ndb.Key("TaskRequestShard", "a" * task_pack.DEPRECATED_SHARDING_LEVEL, "TaskRequest", 0x100)
     )
     with self.assertRaises(ValueError):
         task_request.validate_request_key(ndb.Key("TaskRequest", 1))
     with self.assertRaises(ValueError):
         key = ndb.Key("TaskRequestShard", "a" * (task_pack.DEPRECATED_SHARDING_LEVEL + 1), "TaskRequest", 0x100)
         task_request.validate_request_key(key)
Пример #4
0
 def test_validate_request_key(self):
     task_request.validate_request_key(task_pack.unpack_request_key('10'))
     task_request.validate_request_key(
         ndb.Key('TaskRequestShard',
                 'a' * task_pack.DEPRECATED_SHARDING_LEVEL, 'TaskRequest',
                 0x100))
     with self.assertRaises(ValueError):
         task_request.validate_request_key(ndb.Key('TaskRequest', 1))
     with self.assertRaises(ValueError):
         key = ndb.Key('TaskRequestShard',
                       'a' * (task_pack.DEPRECATED_SHARDING_LEVEL + 1),
                       'TaskRequest', 0x100)
         task_request.validate_request_key(key)
Пример #5
0
 def test_validate_request_key(self):
   task_request.validate_request_key(task_pack.unpack_request_key('10'))
   task_request.validate_request_key(
       ndb.Key(
           'TaskRequestShard', 'a' * task_pack.DEPRECATED_SHARDING_LEVEL,
           'TaskRequest', 0x100))
   with self.assertRaises(ValueError):
     task_request.validate_request_key(ndb.Key('TaskRequest', 1))
   with self.assertRaises(ValueError):
     key = ndb.Key(
         'TaskRequestShard', 'a' * (task_pack.DEPRECATED_SHARDING_LEVEL + 1),
         'TaskRequest', 0x100)
     task_request.validate_request_key(key)
Пример #6
0
 def test_validate_request_key(self):
   task_request.validate_request_key(task_pack.unpack_request_key('11'))
   with self.assertRaises(ValueError):
     task_request.validate_request_key(ndb.Key('TaskRequest', 1))