def test_construction(self, dto): schema = Schema(Bike) entity = schema.construct(dto) assert isinstance(entity, Bike) assert entity.id == 17 assert entity.frame_type == 'gravel' assert entity.wheel_type == 'road'
class InvitationRepo(Repository): schema: Schema = Schema(entity=entities.Invitation) q_inviter_from_same_organization = where('inviter.organization') == where( 'organization') q_valid_inviter = q_inviter_from_same_organization | \ where('inviter.is_staff') == True # noqa: E712 def get_by_email(self, email: entities.Email, organization: entities.Organization): data = self.dao.filter((where('email') == email) & (where('organization') == organization)).one() return self.create(**data) def get_by_token(self, token: entities.InvitationToken): data = self.dao.filter(where('token') == token).one() return self.create(**data)
class UserRepo(Repository): schema: Schema = Schema(entity=entities.User) authentication: AuthenticationService = Inject() @property def is_from_my_organization(self): organization = self.authentication.user.organization return where('organization.id') == organization.id def get_by_email(self, email): data = self.dao.filter( where('email') == email & entities.User.is_active & self.is_from_my_organization).one() return self.create(**data) def is_email_taken(self, email): return self.dao.filter(where('email') == email).exists()
def test_deconstruction_with_fields(self, entity, dto): schema = Schema(Bike, fields=('wheel_type',)) result = schema.deconstruct(entity) assert result == {'wheel_type': 'road'} assert result.id == entity.id
def test_deconstruction(self, entity, data): schema = Schema(Bike) result = schema.deconstruct(entity) assert result == data assert result.id == entity.id
def test_deconstruction_with_fields(self, entity, dto): schema = Schema(Bike, fields=('wheel_type', )) result = schema.deconstruct(entity) assert result == {'wheel_type': 'road'} assert result.id == entity.id
def schema(): return Schema(Bike)