Coverage for src/schemas/user_schema.py : 100%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# User Schemas
2from src import ma
4from src.model import UserModel
5from src.utils import SQLAlchemyAutoSchema, DTOSchema
7# Validations with Marshmallow
8from marshmallow import fields
9from marshmallow.validate import Regexp, Length, Email
11# Validations with Marshmallow
12from marshmallow import fields
13from marshmallow.validate import Regexp, Length, Email
15from src.utils import DTOSchema
18class UserMeta:
19 model = UserModel
22class UserBase(SQLAlchemyAutoSchema):
23 role = ma.Nested("RoleBase")
25 class Meta(UserMeta):
26 fields = ("uuid", "email", "username", "preferences_defined", "role")
29class UserObject(SQLAlchemyAutoSchema):
30 groups = ma.Nested("GroupBase", many=True)
31 invitations = ma.Nested("GroupBase", many=True)
32 owned_groups = ma.Nested("GroupBase", many=True)
34 class Meta(UserMeta):
35 fields = ("uuid", "email", "username", "preferences_defined",
36 "groups", "invitations", "owned_groups")
39class UserFullObject(SQLAlchemyAutoSchema):
40 groups = ma.Nested("GroupBase", many=True)
41 invitations = ma.Nested("GroupBase", many=True)
42 owned_groups = ma.Nested("GroupBase", many=True)
44 liked_genres = ma.Nested("GenreBase", many=True)
46 linked_services = ma.Nested("ExternalBase", many=True)
48 meta_user_content = ma.Nested("MetaUserContentItem", many=True)
50 class Meta(UserMeta):
51 fields = ("uuid", "email", "username", "preferences_defined", "groups", "invitations",
52 "owned_groups", "liked_genres", "linked_services", "meta_user_content")
55class UpdateUserDataSchema(DTOSchema):
56 """ /auth/register [POST]
57 /user/update [PATCH]
59 Parameters:
60 - Email
61 - Username (Str)
62 - Password (Str)
63 """
64 email = fields.Email(validate=[Length(min=5, max=64)])
65 username = fields.Str(
66 validate=[
67 Length(min=4, max=15),
68 Regexp(
69 r"^([A-Za-z0-9_](?:(?:[A-Za-z0-9_]|(?:\.(?!\.))){0,28}(?:[A-Za-z0-9_]))?)$",
70 error="Invalid username!",
71 ),
72 ],
73 )
74 password = fields.Str(
75 validate=[
76 Length(min=8, max=128),
77 Regexp(
78 r"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}",
79 error="Password must contain at least minimum eight characters, at least one uppercase letter, one lowercase letter, one number and one special character !"
80 ),
81 ],
82 )