Esempio n. 1
0
 def test_construction(self, dto):
     factory = Factory(Bike)
     entity = factory.construct(dto)
     assert isinstance(entity, Bike)
     assert entity.id == 17
     assert entity.frame_type == 'gravel'
     assert entity.wheel_type == 'road'
class InvitationRepo(Repository):
    factory: Factory = Factory(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):
    factory: Factory = Factory(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()
Esempio n. 4
0
 def test_deconstruction_with_fields(self, entity, dto):
     factory = Factory(Bike, fields=('wheel_type', ))
     result = factory.deconstruct(entity)
     assert result == {'wheel_type': 'road'}
     assert result.id == entity.id
Esempio n. 5
0
 def test_deconstruction(self, entity, data):
     factory = Factory(Bike)
     result = factory.deconstruct(entity)
     assert result == data
     assert result.id == entity.id
Esempio n. 6
0
def factory():
    return Factory(Bike)
 def test_deconstruction_with_fields(self, entity, dto):
     factory = Factory(Bike, fields=("wheel_type", ))
     result = factory.deconstruct(entity)
     assert result == {"wheel_type": "road"}
     assert result.id == entity.id