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