Exemple #1
0
class CustomSearchModelA(tests.IntAutoModel):
    foo = sheraf.SimpleAttribute().index(
        unique=True,
        values=lambda string: {string.lower()},
        search=lambda string: [string.lower()[::-1], string.lower()],
    )
    bar = sheraf.SimpleAttribute().index()
Exemple #2
0
    class Model(tests.IntAutoModel):
        foo = sheraf.SimpleAttribute()
        bar = sheraf.SimpleAttribute()
        theindex = sheraf.Index(foo, bar)

        @theindex.values
        def values(self, value):
            return {value.lower(), value.upper()}
Exemple #3
0
class CommonValuesComputedTogetherModelB(tests.IntAutoModel):
    foo = sheraf.SimpleAttribute()
    bar = sheraf.SimpleAttribute()
    theindex = sheraf.Index(foo, bar)

    @theindex.values(foo, bar)
    def theindex_values(self, foo_, bar_):
        return {f"{foo_} {bar_}"}
Exemple #4
0
class CommonValuesComputedSeparatelyModelA(tests.IntAutoModel):
    foo = sheraf.SimpleAttribute()
    bar = sheraf.SimpleAttribute()
    theindex = sheraf.Index(foo, bar)

    @theindex.values(foo)
    @theindex.values(bar)
    def values(self, x):
        return {x.upper()}
Exemple #5
0
class CustomIndexationModelF(tests.IntAutoModel):
    foo = sheraf.SimpleAttribute()
    bar = sheraf.SimpleAttribute()

    fooindex = sheraf.Index(foo, key="foo", unique=True)
    barindex = sheraf.Index(bar, key="bar")

    @fooindex.values
    def fooindex_values(self, value):
        return value.lower() if value else None
Exemple #6
0
class CustomIndexationModelB(tests.IntAutoModel):
    foo = sheraf.SimpleAttribute()
    bar = sheraf.SimpleAttribute()

    fooindex = sheraf.Index(
        "foo",
        key="foo",
        unique=True,
        values=lambda string: {string.lower() if string else None},
    )
    barindex = sheraf.Index("bar", key="bar")
Exemple #7
0
class CustomSearchModelB(tests.IntAutoModel):
    foo = sheraf.SimpleAttribute()
    bar = sheraf.SimpleAttribute()

    fooindex = sheraf.Index(
        "foo",
        key="foo",
        unique=True,
        values=lambda string: {string.lower()},
        search=lambda string: [string.lower()[::-1], string.lower()],
    )

    barindex = sheraf.Index("bar", key="bar")
Exemple #8
0
class Model1(sheraf.Model):
    table = "model1_table"

    simple = sheraf.SimpleAttribute(lazy=False)
    my_inline_model = sheraf.InlineModelAttribute(InlineModel, lazy=False)
    my_blob = sheraf.BlobAttribute(lazy=False)
    counter = sheraf.CounterAttribute(lazy=False)
Exemple #9
0
class Model(tests.UUIDAutoModel):
    counter = sheraf.CounterAttribute(default=0)
    useless = sheraf.InlineModelAttribute(
        sheraf.InlineModel(foo=sheraf.SimpleAttribute(default="bar",
                                                      lazy=False), ),
        lazy=False,
    )
Exemple #10
0
class CustomSearchModelE(tests.IntAutoModel):
    foo = sheraf.SimpleAttribute()
    bar = sheraf.SimpleAttribute()

    fooindex = sheraf.Index(
        foo,
        key="foo",
        unique=True,
        values=lambda string: {string.lower()},
    )

    barindex = sheraf.Index(bar, key="bar")

    @fooindex.search
    def search_foo(self, value):
        return [value.lower()[::-1], value.lower()]
Exemple #11
0
    class Model(tests.IntAutoModel):
        deleted = False
        foo = sheraf.SimpleAttribute()

        @foo.on_deletion
        def foo_deletion(self, old):
            self.deleted = True
Exemple #12
0
    class Model(tests.IntAutoModel):
        edited = False
        foo = sheraf.SimpleAttribute()

        @foo.on_edition
        def foo_update(self, new, old):
            if new == "whatever":
                self.edited = True
Exemple #13
0
    class Model(tests.IntAutoModel):
        created = False
        foo = sheraf.SimpleAttribute()

        @foo.on_creation
        def foo_creation(self, new):
            if new == "whatever":
                self.created = True
Exemple #14
0
def test_index():
    attribute = sheraf.SimpleAttribute()
    primary = Index(attribute, key="primary", primary=True)
    unique = Index(attribute, key="unique", unique=True)
    multiple = Index(attribute, key="multiple", unique=False)

    assert "<Index key=primary unique=True primary>" == repr(primary)
    assert "<Index key=unique unique=True>" == repr(unique)
    assert "<Index key=multiple unique=False>" == repr(multiple)
Exemple #15
0
class CommonModelDefaultValuesMethodsA(tests.IntAutoModel):
    def lower(self, value):
        return {value.lower()}

    foo = sheraf.StringAttribute()
    bar = sheraf.SimpleAttribute()
    theindex = sheraf.Index(foo, bar, values=lower)

    @theindex.values(bar)
    def upper(self, bar):
        return {bar.upper()}
Exemple #16
0
class CommonModelDifferentValuesMethodsB(tests.IntAutoModel):
    foo = sheraf.StringAttribute()
    bar = sheraf.SimpleAttribute()
    theindex = sheraf.Index(foo, bar)

    @theindex.values(foo)
    def lower(self, foo):
        return {foo.lower()}

    @theindex.values(bar)
    def upper(self, bar):
        return {bar.upper()}
Exemple #17
0
class Child(sheraf.InlineModel):
    nom = sheraf.SimpleAttribute()
    a1 = sheraf.SimpleAttribute()
    a2 = sheraf.SimpleAttribute()
    a3 = sheraf.SimpleAttribute()

    @classmethod
    def create(cls, val):
        model = super().create()
        model.nom = val
        model.a1 = val
        model.a2 = val
        model.a3 = val
        model.check(val)
        return model

    def check(self, key):
        assert key == self.nom == self.a1 == self.a2 == self.a3

    def __eq__(self, other):
        return (self.nom == other.nom and self.a1 == other.a1
                and self.a2 == other.a2 and self.a3 == other.a3)
Exemple #18
0
 class FileStorable(tests.UUIDAutoModel):
     attr = sheraf.SimpleAttribute()
     file = sheraf.FileAttribute()
Exemple #19
0
 class FileStorable(tests.UUIDAutoModel):
     a = sheraf.SimpleAttribute()
     b = sheraf.SimpleAttribute()
     c = sheraf.SmallListAttribute()
     d = sheraf.LargeDictAttribute()
Exemple #20
0
 class HorseWithNoName(sheraf.AttributeModel):
     foo = sheraf.SimpleAttribute()
     bar = sheraf.SimpleAttribute()
Exemple #21
0
 class BarModel(tests.UUIDAutoModel):
     my_attribute = sheraf.SimpleAttribute(default="hell yeah")
Exemple #22
0
 class M(tests.UUIDAutoModel):
     foo = sheraf.SimpleAttribute(default=lambda: None)
Exemple #23
0
 class B(A, sheraf.DatedNamedAttributesModel):
     bar = sheraf.SimpleAttribute(default="bar")
Exemple #24
0
 class A(sheraf.BaseModel):
     foo = sheraf.SimpleAttribute(default="foo")
Exemple #25
0
 class A(tests.UUIDAutoModel):
     foo = sheraf.SimpleAttribute(default="foo_A")
     bar = sheraf.SimpleAttribute(default="bar_A")
Exemple #26
0
 class Model(tests.UUIDAutoModel):
     foo = sheraf.SimpleAttribute()
     mylist = sheraf.LargeListAttribute()
Exemple #27
0
 class FoobarModel(tests.UUIDAutoModel):
     my_attribute = sheraf.SimpleAttribute(default="hell yeah", lazy=False)
Exemple #28
0
class BadParent(tests.UUIDAutoModel):
    child = sheraf.SetAttribute(sheraf.SimpleAttribute()).index()
Exemple #29
0
class Model(tests.UUIDAutoModel):
    field = sheraf.SimpleAttribute()
Exemple #30
0
class BTreesLengthModel(sheraf.Model):
    table = "model_test_simple_attribute_replacement"
    unique_table_name = False
    counter = sheraf.SimpleAttribute(default=BTrees.Length.Length)