예제 #1
0
 def test_root_top_level():
     key = key_module.Key("This", "key")
     assert key.root() is key
예제 #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)
예제 #3
0
 def test_invalid_argument_combination():
     with pytest.raises(TypeError):
         key_module.Key(flat=["a", "b"], urlsafe=b"foo")
예제 #4
0
 def test_to_old_key():
     key = key_module.Key("a", "b")
     with pytest.raises(NotImplementedError):
         key.to_old_key()
예제 #5
0
 def test_constructor_with_flat_and_pairs():
     with pytest.raises(TypeError):
         key_module.Key(pairs=[("Kind", 1)], flat=["Kind", 1])
예제 #6
0
 def test_urlsafe():
     key = key_module.Key("d", None, app="f")
     assert key.urlsafe() == b"agFmcgULEgFkDA"
예제 #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"
     )
예제 #8
0
 def test_pairs():
     key = key_module.Key("a", "b")
     assert key.pairs() == (("a", "b"),)
예제 #9
0
 def test_pairs_partial_key():
     key = key_module.Key("This", "key", "that", None)
     assert key.pairs() == (("This", "key"), ("that", None))
예제 #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
예제 #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
예제 #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
예제 #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:]
예제 #14
0
 def test_namespace():
     namespace = "my-space"
     key = key_module.Key("abc", 1, namespace=namespace)
     assert key.namespace() == namespace
예제 #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()
예제 #16
0
 def test_flat():
     key = key_module.Key("This", "key")
     assert key.flat() == ("This", "key")
예제 #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"
예제 #18
0
 def test_flat_partial_key():
     key = key_module.Key("Kind", None)
     assert key.flat() == ("Kind", None)
예제 #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"
     )
예제 #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"
예제 #21
0
 def test_constructor_empty_path():
     with pytest.raises(TypeError):
         key_module.Key(pairs=())
예제 #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
     )
예제 #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)
예제 #24
0
 def test_reference_cached():
     key = key_module.Key("This", "key")
     key._reference = mock.sentinel.reference
     assert key.reference() is mock.sentinel.reference
예제 #25
0
 def test_constructor_with_project_and_app():
     with pytest.raises(TypeError):
         key_module.Key("Kind", 10, project="foo", app="bar")
예제 #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()
예제 #27
0
 def test_constructor_insufficient_args():
     with pytest.raises(TypeError):
         key_module.Key(app="foo")
예제 #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()
예제 #29
0
 def test___repr__defaults():
     key = key_module.Key("a", "b")
     assert repr(key) == "Key('a', 'b')"
     assert str(key) == "Key('a', 'b')"
예제 #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