コード例 #1
0
def generate_digest(content):
  """Create a Digest from content (in a given namespace) for preupload.

  Arguments:
    content: the content to be hashed

  Returns:
    a Digest corresponding to the namespace pair
  """
  return handlers_endpoints_v1.Digest(
      digest=hash_content(content), size=len(content))
コード例 #2
0
 def test_pre_upload_invalid_hash(self):
   """Assert that status 400 is returned when the digest is invalid."""
   bad_collection = handlers_endpoints_v1.DigestCollection(
       namespace=handlers_endpoints_v1.Namespace())
   bad_digest = hash_content('some stuff')
   bad_digest = 'g' + bad_digest[1:]  # that's not hexadecimal!
   bad_collection.items.append(
       handlers_endpoints_v1.Digest(digest=bad_digest, size=10))
   with self.call_should_fail('400'):
     self.call_api(
         'preupload', self.message_to_dict(bad_collection), 200)