def get_role(self, role): """ helper for creating roles """ roles = { ROLE_ADMIN: RoleEntity(name=ROLE_ADMIN, description='role'), ROLE_TECHNICIAN: RoleEntity(name=ROLE_TECHNICIAN, description='role'), } return roles[role]
def test_role(self): """ verify save and find operations """ role_admin = self.get_role(ROLE_ADMIN) role_tech = self.get_role(ROLE_TECHNICIAN) db.session.add(role_admin) # before commit the primary key does not exist self.assertIsNone(role_admin.id) # after commit the primary key is generated db.session.commit() assert 1 == role_admin.id roles = RoleEntity.query.all() assert len(roles) == 1 # test usage of CRUDMixin.get_by_id() and create() role_tech = RoleEntity.save(role_tech) assert 2 == role_tech.id ordered = RoleEntity.query.order_by(RoleEntity.name).all() # verify that we have two rows now assert 2 == len(ordered) # verify that the attribute is saved first = ordered[0] assert ROLE_ADMIN == first.name # verify that sorting worked first = RoleEntity.query.order_by(db.desc(RoleEntity.name)).first() assert ROLE_TECHNICIAN == first.name
def create_sample_data(self): """ Add some data """ # == Create users added_date = datetime.today() access_end_date = utils.get_expiration_date(180) user = UserEntity.create(email="*****@*****.**", first="First", last="Last", minitial="M", added_at=added_date, modified_at=added_date, email_confirmed_at=added_date, access_expires_at=access_end_date) # == Create roles role_admin = RoleEntity.create(name=ROLE_ADMIN, description='role') role_tech = RoleEntity.create(name=ROLE_TECHNICIAN, description='role')