예제 #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")
예제 #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
예제 #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))
예제 #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)
예제 #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()
예제 #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()
예제 #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])
예제 #8
0
파일: conftest.py 프로젝트: aisola/anom-py
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])
예제 #9
0
def test_keys_can_fail_to_get_single_entities(adapter):
    assert Key(models.Person, "nonexistent").get() is None
예제 #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))
예제 #11
0
def test_key_delete_deletes_nonexistent_entities(adapter):
    assert Key("Person", 123).delete() is None
예제 #12
0
def test_keys_can_be_full():
    assert not Key("Person", 123).is_partial
예제 #13
0
def test_keys_can_be_partial():
    assert Key("Person").is_partial
예제 #14
0
 def create(cls, user):
     session = cls(user=user)
     session.key = Key(Session, str(uuid4()))
     return session.put()
예제 #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
예제 #16
0
def test_keys_get_multi_fails_unknown_kind():
    with pytest.raises(RuntimeError):
        get_multi([Key("UnknownKind")])
예제 #17
0
def test_keys_can_lookup_models_by_kind():
    assert Key("Person").get_model()
예제 #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")
예제 #19
0
def test_keys_can_be_assigned_full_keys():
    assert props.Key().validate(Key("Person", 12))
예제 #20
0
def test_key_inherits_parents_namespace():
    parent = Key("Organization", 123, namespace="a")
    assert Key("Person", 123, parent=parent).namespace == parent.namespace
예제 #21
0
def test_keys_parents_must_not_be_partial():
    with pytest.raises(ValueError):
        Key("Person", 123, parent=Key("Organization"))
예제 #22
0
def test_keys_are_hierarchical():
    assert Key("Person", 123,
               parent=Key("Organization",
                          1)).path == ("Organization", 1, "Person", 123)
예제 #23
0
def test_keys_get_multi_fails_given_partial_keys():
    with pytest.raises(RuntimeError):
        get_multi([Key("Person")])
예제 #24
0
def test_keys_can_fail_to_lookup_models_by_kind():
    with pytest.raises(RuntimeError):
        Key("UnknownKind").get_model()
예제 #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")
예제 #26
0
def test_keys_reprs_can_be_used_to_rebuild_them():
    assert repr(Key("Foo",
                    123)) == "Key('Foo', 123, parent=None, namespace='')"
예제 #27
0
def test_keys_can_have_numeric_ids():
    assert Key("Person", 123).int_id == 123
    assert Key("Person", 123).str_id is None
예제 #28
0
def test_keys_can_be_constructed_from_models():
    assert Key(models.Person) == Key("Person")
예제 #29
0
def test_keys_cannot_be_assigned_partial_keys():
    with pytest.raises(ValueError):
        key = props.Key()
        key.validate(Key("Person"))
예제 #30
0
def test_keys_can_have_string_ids():
    assert Key("Person", "Jim").str_id == "Jim"
    assert Key("Person", "Jim").int_id is None