def generate_role(): role = Role( id=str(uuid4()), name=faker.word() ) return role
def generate_roles(amount=5): roles = [] for _ in range(amount): roles.append( Role( id=str(uuid4()), name=faker.word() ) ) return roles
def test_can_add_permission_to_role(): permission = Permission( id=str(uuid4()), route="test:test_route", description="Test description" ).save() role = Role( id=str(uuid4()), name="Test" ).save() data = {} data["permissionId"] = permission.id data["roleId"] = role.id role: Role = _role_repo.add_permission_to_role(data) assert role is not None
def seed_some_users(amount=50) -> None: me = User(id=str(uuid4()), email="*****@*****.**", password=_auth_service.hash_password("FunkyP455")).save() super_user = Role.objects(name="SuperUser").first() me.roles.append(super_user) me.save() for _ in range(amount): User(id=str(uuid4()), email=fake.ascii_company_email(), password=_auth_service.hash_password( fake.password(length=10, digits=True, upper_case=True, lower_case=True))).save()
def seed_roles_and_permissions(all_permissions: dict, amount=5): for data in all_permissions: permissions[data] = Permission( id=str(uuid4()), route=all_permissions[data]["route"], description=all_permissions[data]["description"]).save() for data in all_permissions: permissions_list.append( Permission( id=str(uuid4()), route=all_permissions[data]["route"], description=all_permissions[data]["description"]).save()) super_user = Role(id=str(uuid4()), name="SuperUser").save() super_user.update(permissions=permissions_list) super_user.save()
def test_we_can_add_a_new_role(): role = _role_repo.create_new_role("Testing") result = Role.objects(name=role.name).first() assert result is not None
def drop_all_collections(): User.drop_collection() Role.drop_collection() Permission.drop_collection()
def register_test_db(): connect(alias='default', host="mongodb://localhost/maintesoft_test") User.drop_collection() Role.drop_collection() Permission.drop_collection()
def seed_all(all_permissions: dict) -> None: User.drop_collection() Role.drop_collection() Permission.drop_collection() seed_roles_and_permissions(all_permissions) seed_some_users()