Exemplo n.º 1
0
 def test_root_top_level():
     key = key_module.Key("This", "key")
     assert key.root() is key
Exemplo n.º 2
0
 def test_constructor_with_parent_bad_type(self):
     parent = unittest.mock.sentinel.parent
     with pytest.raises(exceptions.BadValueError):
         key_module.Key("Zip", 10, parent=parent)
Exemplo n.º 3
0
 def test_invalid_argument_combination():
     with pytest.raises(TypeError):
         key_module.Key(flat=["a", "b"], urlsafe=b"foo")
Exemplo n.º 4
0
 def test_to_old_key():
     key = key_module.Key("a", "b")
     with pytest.raises(NotImplementedError):
         key.to_old_key()
Exemplo n.º 5
0
 def test_constructor_with_flat_and_pairs():
     with pytest.raises(TypeError):
         key_module.Key(pairs=[("Kind", 1)], flat=["Kind", 1])
Exemplo n.º 6
0
 def test_urlsafe():
     key = key_module.Key("d", None, app="f")
     assert key.urlsafe() == b"agFmcgULEgFkDA"
Exemplo n.º 7
0
 def test_to_legacy_urlsafe_name():
     key = key_module.Key("d", "x", app="f")
     assert (
         key.to_legacy_urlsafe(location_prefix="s~")
         == b"agNzfmZyCAsSAWQiAXgM"
     )
Exemplo n.º 8
0
 def test_pairs():
     key = key_module.Key("a", "b")
     assert key.pairs() == (("a", "b"),)
Exemplo n.º 9
0
 def test_pairs_partial_key():
     key = key_module.Key("This", "key", "that", None)
     assert key.pairs() == (("This", "key"), ("that", None))
Exemplo n.º 10
0
 def test_string_id():
     pairs = (("x", "x"), (11, None), (None, None))
     for id_or_name, expected in pairs:
         key = key_module.Key("Kind", id_or_name)
         assert key.string_id() == expected
Exemplo n.º 11
0
 def test_integer_id():
     pairs = (("x", None), (11, 11), (None, None))
     for id_or_name, expected in pairs:
         key = key_module.Key("Kind", id_or_name)
         assert key.integer_id() == expected
Exemplo n.º 12
0
 def test_id():
     for id_or_name in ("x", 11, None):
         key = key_module.Key("Kind", id_or_name)
         assert key.id() == id_or_name
Exemplo n.º 13
0
 def test_app():
     app = "s~example"
     key = key_module.Key("X", 100, app=app)
     assert key.app() != app
     assert key.app() == app[2:]
Exemplo n.º 14
0
 def test_namespace():
     namespace = "my-space"
     key = key_module.Key("abc", 1, namespace=namespace)
     assert key.namespace() == namespace
Exemplo n.º 15
0
 def test_reference_bad_integer_id():
     for id_ in (-10, 0, 2 ** 64):
         key = key_module.Key("kind", id_, app="app")
         with pytest.raises(ValueError):
             key.reference()
Exemplo n.º 16
0
 def test_flat():
     key = key_module.Key("This", "key")
     assert key.flat() == ("This", "key")
Exemplo n.º 17
0
 def test_serialized():
     key = key_module.Key("a", 108, app="c")
     assert key.serialized() == b"j\x01cr\x07\x0b\x12\x01a\x18l\x0c"
Exemplo n.º 18
0
 def test_flat_partial_key():
     key = key_module.Key("Kind", None)
     assert key.flat() == ("Kind", None)
Exemplo n.º 19
0
 def test_to_legacy_urlsafe():
     key = key_module.Key("d", 123, app="f")
     assert (
         key.to_legacy_urlsafe(location_prefix="s~")
         == b"agNzfmZyBwsSAWQYeww"
     )
Exemplo n.º 20
0
 def test_kind():
     key = key_module.Key("This", "key")
     assert key.kind() == "This"
     key = key_module.Key("a", "b", "c", "d")
     assert key.kind() == "c"
Exemplo n.º 21
0
 def test_constructor_empty_path():
     with pytest.raises(TypeError):
         key_module.Key(pairs=())
Exemplo n.º 22
0
 def test_reference():
     key = key_module.Key("This", "key", app="fire")
     assert key.reference() == make_reference(
         path=({"type": "This", "name": "key"},), app="fire", namespace=None
     )
Exemplo n.º 23
0
 def test_constructor_invalid_id_type():
     with pytest.raises(TypeError):
         key_module.Key("Kind", object())
     with pytest.raises(exceptions.BadArgumentError):
         key_module.Key("Kind", None, "Also", 10)
Exemplo n.º 24
0
 def test_reference_cached():
     key = key_module.Key("This", "key")
     key._reference = mock.sentinel.reference
     assert key.reference() is mock.sentinel.reference
Exemplo n.º 25
0
 def test_constructor_with_project_and_app():
     with pytest.raises(TypeError):
         key_module.Key("Kind", 10, project="foo", app="bar")
Exemplo n.º 26
0
 def test_reference_bad_kind():
     too_long = "a" * (key_module._MAX_KEYPART_BYTES + 1)
     for kind in ("", too_long):
         key = key_module.Key(kind, "key", app="app")
         with pytest.raises(ValueError):
             key.reference()
Exemplo n.º 27
0
 def test_constructor_insufficient_args():
     with pytest.raises(TypeError):
         key_module.Key(app="foo")
Exemplo n.º 28
0
 def test_reference_bad_string_id():
     too_long = "a" * (key_module._MAX_KEYPART_BYTES + 1)
     for id_ in ("", too_long):
         key = key_module.Key("kind", id_, app="app")
         with pytest.raises(ValueError):
             key.reference()
Exemplo n.º 29
0
 def test___repr__defaults():
     key = key_module.Key("a", "b")
     assert repr(key) == "Key('a', 'b')"
     assert str(key) == "Key('a', 'b')"
Exemplo n.º 30
0
 def test_root():
     key = key_module.Key("a", "b", "c", "d")
     root = key.root()
     assert root._key == key._key.parent
     assert root._reference is None