Пример #1
0
        deferred.deferred_put_attachment("deferred", "att")
        self.assertFalse(hasattr(noblobs, "blobs"))
        docs = [self.obj, noblobs, deferred]
        self.assertNotIn("name", self.obj.blobs)
        with mod.bulk_atomic_blobs(docs):
            self.obj.put_attachment("data", "name")
            self.assertIn("name", self.obj.blobs)
            self.assertIn("att", deferred.external_blobs)
        self.assertFalse(any(d.saved for d in docs))
        self.assertEqual(self.obj.fetch_attachment("name"), b"data")
        key = deferred.blobs["att"].key
        with self.get_blob(key).open() as fh:
            self.assertEqual(fh.read(), b"deferred")


_abc_digest = mod.sha1(b"abc").hexdigest()


@generate_cases([
    ("abc-def", "abc-def"),
    ("{abc-def}", "{abc-def}"),
    ("uuid:def", "sha1-d7ceb3d1678b9986f89e88780094a571a226c8b5"),
    ("sha1-def", "sha1-def"),
    ("sha1-" + _abc_digest + "0", "sha1-" + _abc_digest + "0"),
    ("sha1-" + _abc_digest, ValueError),
])
def test_safe_id(self, value, result):
    if isinstance(result, type):
        with self.assertRaises(result):
            mod.safe_id(value)
    else:
Пример #2
0
        deferred.deferred_put_attachment("deferred", "att")
        self.assertFalse(hasattr(noblobs, "blobs"))
        docs = [self.obj, noblobs, deferred]
        self.assertNotIn("name", self.obj.blobs)
        with mod.bulk_atomic_blobs(docs):
            self.obj.put_attachment("data", "name")
            self.assertIn("name", self.obj.blobs)
            self.assertIn("att", deferred.external_blobs)
        self.assertFalse(any(d.saved for d in docs))
        self.assertEqual(self.obj.fetch_attachment("name"), "data")
        key = deferred.blobs["att"].key
        with self.get_blob(key).open() as fh:
            self.assertEqual(fh.read(), "deferred")


_abc_digest = mod.sha1("abc".encode('utf-8')).hexdigest()


@generate_cases([
    ("abc-def", "abc-def"),
    ("{abc-def}", "{abc-def}"),
    ("uuid:def", "sha1-d7ceb3d1678b9986f89e88780094a571a226c8b5"),
    ("sha1-def", "sha1-def"),
    ("sha1-" + _abc_digest + "0", "sha1-" + _abc_digest + "0"),
    ("sha1-" + _abc_digest, ValueError),
])
def test_safe_id(self, value, result):
    if isinstance(result, type):
        with self.assertRaises(result):
            mod.safe_id(value)
    else:
Пример #3
0
        deferred.deferred_put_attachment("deferred", "att")
        self.assertFalse(hasattr(noblobs, "blobs"))
        docs = [self.obj, noblobs, deferred]
        self.assertNotIn("name", self.obj.blobs)
        with mod.bulk_atomic_blobs(docs):
            self.obj.put_attachment("data", "name")
            self.assertIn("name", self.obj.blobs)
            self.assertIn("att", deferred.external_blobs)
        self.assertFalse(any(d.saved for d in docs))
        self.assertEqual(self.obj.fetch_attachment("name"), "data")
        ident = deferred.blobs["att"].id
        with self.get_blob(ident, deferred._blobdb_bucket()).open() as fh:
            self.assertEqual(fh.read(), "deferred")


_abc_digest = mod.sha1("abc").hexdigest()


@generate_cases([
    ("abc-def", "abc-def"),
    ("{abc-def}", "{abc-def}"),
    ("uuid:def", "sha1-d7ceb3d1678b9986f89e88780094a571a226c8b5"),
    ("sha1-def", "sha1-def"),
    ("sha1-" + _abc_digest + "0", "sha1-" + _abc_digest + "0"),
    ("sha1-" + _abc_digest, ValueError),
])
def test_safe_id(self, value, result):
    if isinstance(result, type):
        with self.assertRaises(result):
            mod.safe_id(value)
    else:
Пример #4
0
        deferred.deferred_put_attachment("deferred", "att")
        self.assertFalse(hasattr(noblobs, "blobs"))
        docs = [self.obj, noblobs, deferred]
        self.assertNotIn("name", self.obj.blobs)
        with mod.bulk_atomic_blobs(docs):
            self.obj.put_attachment("data", "name")
            self.assertIn("name", self.obj.blobs)
            self.assertIn("att", deferred.external_blobs)
        self.assertFalse(any(d.saved for d in docs))
        self.assertEqual(self.obj.fetch_attachment("name"), "data")
        key = deferred.blobs["att"].key
        with self.get_blob(key).open() as fh:
            self.assertEqual(fh.read(), b"deferred")


_abc_digest = mod.sha1("abc".encode('utf-8')).hexdigest()


@generate_cases([
    ("abc-def", "abc-def"),
    ("{abc-def}", "{abc-def}"),
    ("uuid:def", "sha1-d7ceb3d1678b9986f89e88780094a571a226c8b5"),
    ("sha1-def", "sha1-def"),
    ("sha1-" + _abc_digest + "0", "sha1-" + _abc_digest + "0"),
    ("sha1-" + _abc_digest, ValueError),
])
def test_safe_id(self, value, result):
    if isinstance(result, type):
        with self.assertRaises(result):
            mod.safe_id(value)
    else: