Exemplo n.º 1
0
    class Hero(ar.Document):
        name = ar.Field(ar.StringValueType(), indexed=True)
        publisher = ar.Field(ar.LazyDocRefValueType(Publisher))

        async def get_movies(self):
            return await Movie.from_query(Movie.cq().filter(
                r.row["heroes"].contains(self.pkey)))

        async def get_movies_as_list(self):
            iterator = await self.get_movies()
            return await iterator.as_list()
Exemplo n.º 2
0
def test_fieldalias():
    f = ar.Field(ar.IntValueType())
    f.name = "f"
    fa = ar.FieldAlias(f)

    for attr in [
            "name", "dbname", "indexed", "required", "default", "validate"
    ]:
        assert getattr(fa, attr) == getattr(f, attr)

    assert "fld_name=f" in repr(fa)
Exemplo n.º 3
0
def test_basic_field():
    f = ar.Field()

    assert isinstance(f.val_type, ar.AnyValueType)

    assert f.name == None
    assert f.dbname == None  # this is never the case when the field is inside a FieldContainer
    f.name = "f"  # because this is done by FieldContainer
    assert f.name == "f"
    assert f.dbname == "f"

    assert not f.indexed
    assert not f.required
    assert not f.primary_key
    assert f.default == None

    assert f.validate(None) == f
    assert f.validate(1) == f
    assert f.validate("hello") == f
Exemplo n.º 4
0
def test_field_properties():
    f = ar.Field(default="hello")
    assert f.default == "hello"

    f = ar.Field(indexed=True)
    assert f.indexed == True

    f = ar.Field(required=True)
    with pytest.raises(ar.ValidationError):
        f.validate(None)
    assert f.validate(10) == f

    f = ar.Field(primary_key=True)
    assert f.primary_key == True

    with pytest.raises(ar.IllegalSpecError):
        f = ar.Field(indexed=True, primary_key=True)

    f = ar.Field(name="dbf")
    assert f.dbname == "dbf"
    f.name = "f"  # this is what FieldContainer does
    assert f.name == "f"
    assert f.dbname == "dbf"
Exemplo n.º 5
0
 class Movie(ar.Document):
     name = ar.Field(ar.StringValueType(), indexed=True)
     year = ar.Field(ar.IntValueType(), indexed=True)
     studio = ar.Field(ar.LazyDocRefValueType(Studio))
     heroes = ar.Field(ar.ListValueType(HeroRef))
Exemplo n.º 6
0
 class Doc(ar.Document):
     f1 = ar.Field()
     f2 = ar.Field()
Exemplo n.º 7
0
def test_field_with_type():
    f = ar.Field(ar.IntValueType())

    assert f.validate(1) == f
    with pytest.raises(ar.ValidationError):
        f.validate("hello")
Exemplo n.º 8
0
 class FC(ar.FieldContainer):
     f = ar.Field(default=10)
Exemplo n.º 9
0
 class FCWithSpecialDBFieldNames(ar.FieldContainer):
     f1 = ar.Field(name="field1")
Exemplo n.º 10
0
 class MyDoc(ar.Document):
     f1 = ar.Field(primary_key=True)
Exemplo n.º 11
0
 class MyDoc(ar.Document):
     id = ar.Field()
Exemplo n.º 12
0
 class MyDoc(ar.Document):
     pkey = ar.Field()
Exemplo n.º 13
0
 class SpecializedDoc(GeneralDoc):
     f2 = ar.Field()
Exemplo n.º 14
0
 class GeneralDoc(ar.Document):
     f1 = ar.Field()
Exemplo n.º 15
0
 class DocCustomPkey(ar.Document):
     f1 = ar.Field(primary_key=True)
     f2 = ar.Field()
Exemplo n.º 16
0
 class FC(ar.FieldContainer):
     f1 = ar.Field()
     f1a = ar.FieldAlias(f1)
Exemplo n.º 17
0
 class FCWithSpecialDBReprField(FCWithSpecialDBFieldNames):
     f_swapcase = ar.Field(SwapCaseValueType(), default="")
Exemplo n.º 18
0
 class FCWithFields(ar.FieldContainer):
     f1 = ar.Field()
     f2 = ar.Field()
Exemplo n.º 19
0
 class FC(ar.FieldContainer):
     f1 = ar.Field()
Exemplo n.º 20
0
 class MyFC(ar.FieldContainer):
     items = ar.Field()
Exemplo n.º 21
0
def test_field_with_type_and_default():
    with pytest.raises(ar.IllegalSpecError):
        f = ar.Field(ar.IntValueType(), default="hello")

    f = ar.Field(ar.StringValueType(), default="hello")
Exemplo n.º 22
0
 class Publisher(ar.Document):
     name = ar.Field(ar.StringValueType(), indexed=True)
Exemplo n.º 23
0
def test_repr():
    f = ar.Field()
    assert "dbname" in repr(f)
Exemplo n.º 24
0
 class Studio(ar.Document):
     name = ar.Field(ar.StringValueType(), indexed=True)
Exemplo n.º 25
0
 class FC(ar.FieldContainer):
     f = ar.Field()
     fa = ar.FieldAlias(f)
Exemplo n.º 26
0
 class SecIndex(ar.Document):
     f1 = ar.Field(indexed=True)