class User(FullName, Model): email = props.String(indexed=True) password = props.String() first_name = props.String(optional=True) last_name = props.String(optional=True) created_at = props.DateTime(auto_now_add=True) updated_at = props.DateTime(auto_now=True)
class ModelWithComputedProperty(Model): s = props.String() def compute(self): return self.s.upper() if self.s else None c = props.Computed(compute)
def test_repeated_properties_validate_their_data_types(): string = props.String(repeated=True) assert string.validate([]) == [] assert string.validate(["a", "b", "c"]) with pytest.raises(TypeError): string.validate([1])
class Post(Model): author = props.Key(indexed=True, kind=User) title = props.String() def __compute_slug(self): if self.title is None: return None return slugify(self.title) def __compute_body(self): if self.body is None: return None return markdown(self.body) slug = props.Computed(__compute_slug) body = props.Text() body_markdown = props.Computed(__compute_body) tags = props.String(indexed=True, repeated=True) created_at = props.DateTime(indexed=True, auto_now_add=True) updated_at = props.DateTime(indexed=True, auto_now=True)
class User(Model, poly=True): username = props.String(indexed=True) password = Password() created_at = props.DateTime(indexed=True, auto_now_add=True) updated_at = props.DateTime(indexed=True, auto_now=True) @classmethod def login(cls, username, password): user = User.query().where(User.username == username).get() if user is None: return None if not ctx.verify(password, user.password): return None if ctx.needs_update(user.password): user.password = password return user.put() return user @property def permissions(self): return ()
class Place(Model): name = props.String() points = props.Embed(kind=Point, optional=True, repeated=True)
class SplitTest(Model): name = props.String(indexed=True) slug = props.String(indexed=True) variations = props.Embed(kind=Variation, repeated=True)
class Mammal(Animal): hair_color = props.String(default="black") name = props.String()
class Mutant(Person): power = props.String(indexed=True)
class Person(FullName, Model): email = props.String(indexed=True) first_name = props.String(indexed=True) last_name = props.String(optional=True) parent = props.Key(optional=True) created_at = props.DateTime(auto_now_add=True, indexed=True)
class ConditionsModelIsEmpty(Model): s = props.String(indexed_if=conditions.is_empty)
class ConditionsModelIsNotDefault(Model): s = props.String(default="hello", indexed_if=conditions.is_not_default)
def test_strings_that_are_indexed_cannot_be_assigned_values_longer_than_the_max( ): with pytest.raises(ValueError): string = props.String(indexed=True) string.validate(" " * 1501)
def test_strings_that_are_not_indexed_can_be_assigned_arbitrarily_long_values( ): string = props.String() assert string.validate(" " * 1501)
class Tag(Model): name = props.String()
class GuestbookEntry(Model): author = props.String(optional=True) message = props.Text() created_at = props.DateTime(indexed=True, auto_now_add=True)