Exemple #1
0
def test_model_instances_can_be_equal():
    person = Person()
    assert person == person
    assert Person(key=Key("Person", 1)) == Person(key=Key("Person", 1))
    assert Person(key=Key("Person", 1),
                  first_name="John") == Person(key=Key("Person", 1),
                                               first_name="John")
Exemple #2
0
def test_keys_are_hashable():
    entities = {}
    for i in range(10):
        entities[Key("Person", i)] = i

    for i in range(10):
        assert entities[Key("Person", i)] == i
Exemple #3
0
def test_keys_can_be_equal():
    key = Key("Foo")
    assert key == key
    assert Key("Foo") == Key("Foo")
    assert Key("Foo", 123) == Key("Foo", 123)
    assert Key("Foo", 123, parent=Key("Bar", 1)) == Key("Foo",
                                                        123,
                                                        parent=Key("Bar", 1))
Exemple #4
0
def test_restricted_key_properties_can_only_be_assigned_keys_of_that_kind(
        person):
    entity = models.ModelWithRestrictedKeyProperty()
    entity.k = person.key

    with pytest.raises(ValueError):
        entity.k = Key("Foo", 1)
Exemple #5
0
def person_in_ns(adapter):
    person = Person(email="*****@*****.**",
                    first_name="Namespaced",
                    last_name="Person")
    person.key = Key(Person, namespace="a-namespace")
    person.put()
    yield person
    person.delete()
Exemple #6
0
def person_with_ancestor(person):
    child = Person(
        email="*****@*****.**",
        first_name="Child",
        last_name="Person",
    )
    child.key = Key(Person, parent=person.key, namespace=person.key.namespace)
    child.put()
    yield child
    child.delete()
Exemple #7
0
def people(adapter):
    people = put_multi([
        Person(key=Key(Person, i),
               email=f"{i}@example.com",
               first_name="Person",
               last_name=str(i)) for i in range(1, 21)
    ])

    yield people

    delete_multi([person.key for person in people])
Exemple #8
0
def people(adapter):
    people = []
    for i in range(1, 21):
        person = Person(email=f"{i}@example.com",
                        first_name="Person",
                        last_name=str(i))
        person.key = Key(Person, i)
        people.append(person.put())

    yield people

    delete_multi([person.key for person in people])
Exemple #9
0
def test_keys_can_fail_to_get_single_entities(adapter):
    assert Key(models.Person, "nonexistent").get() is None
Exemple #10
0
def test_keys_can_be_not_equal():
    assert Key("Foo") != Key("Bar")
    assert Key("Foo", 123) != Key("Foo", 124)
    assert Key("Foo", 123, parent=Key("Bar", 1)) != Key(
        "Foo", 123, parent=Key("Bar", 2))
    assert Key("Foo", 123, namespace="foos") != Key(
        "Foo", 123, parent=Key("Bar", 1))
Exemple #11
0
def test_key_delete_deletes_nonexistent_entities(adapter):
    assert Key("Person", 123).delete() is None
Exemple #12
0
def test_keys_can_be_full():
    assert not Key("Person", 123).is_partial
Exemple #13
0
def test_keys_can_be_partial():
    assert Key("Person").is_partial
Exemple #14
0
 def create(cls, user):
     session = cls(user=user)
     session.key = Key(Session, str(uuid4()))
     return session.put()
Exemple #15
0
def test_partial_keys_dont_have_an_id():
    assert Key("Person").id_or_name is None
    assert Key("Person").int_id is None
    assert Key("Person").str_id is None
Exemple #16
0
def test_keys_get_multi_fails_unknown_kind():
    with pytest.raises(RuntimeError):
        get_multi([Key("UnknownKind")])
Exemple #17
0
def test_keys_can_lookup_models_by_kind():
    assert Key("Person").get_model()
Exemple #18
0
def test_keys_namespace_must_match_parent_namespace():
    parent = Key("Organization", 123, namespace="a")
    with pytest.raises(ValueError):
        Key("Person", 123, parent=parent, namespace="b")
Exemple #19
0
def test_keys_can_be_assigned_full_keys():
    assert props.Key().validate(Key("Person", 12))
Exemple #20
0
def test_key_inherits_parents_namespace():
    parent = Key("Organization", 123, namespace="a")
    assert Key("Person", 123, parent=parent).namespace == parent.namespace
Exemple #21
0
def test_keys_parents_must_not_be_partial():
    with pytest.raises(ValueError):
        Key("Person", 123, parent=Key("Organization"))
Exemple #22
0
def test_keys_are_hierarchical():
    assert Key("Person", 123,
               parent=Key("Organization",
                          1)).path == ("Organization", 1, "Person", 123)
Exemple #23
0
def test_keys_get_multi_fails_given_partial_keys():
    with pytest.raises(RuntimeError):
        get_multi([Key("Person")])
Exemple #24
0
def test_keys_can_fail_to_lookup_models_by_kind():
    with pytest.raises(RuntimeError):
        Key("UnknownKind").get_model()
Exemple #25
0
def test_model_instances_can_not_be_equal():
    assert Person() != {}
    assert Person(key=Key("Person", 1)) != Person(key=Key("Person", 2))
    assert Person(key=Key("Person", 1), first_name="John") != Person(
        key=Key("Person", 1), first_name="Jane")
Exemple #26
0
def test_keys_reprs_can_be_used_to_rebuild_them():
    assert repr(Key("Foo",
                    123)) == "Key('Foo', 123, parent=None, namespace='')"
Exemple #27
0
def test_keys_can_have_numeric_ids():
    assert Key("Person", 123).int_id == 123
    assert Key("Person", 123).str_id is None
Exemple #28
0
def test_keys_can_be_constructed_from_models():
    assert Key(models.Person) == Key("Person")
Exemple #29
0
def test_keys_cannot_be_assigned_partial_keys():
    with pytest.raises(ValueError):
        key = props.Key()
        key.validate(Key("Person"))
Exemple #30
0
def test_keys_can_have_string_ids():
    assert Key("Person", "Jim").str_id == "Jim"
    assert Key("Person", "Jim").int_id is None