コード例 #1
0
 def test_get_staff_info(self):
     api = staff_management_api.StaffManagementApi()
     admin_token = get_admin_token()
     api.api_client.set_default_header("Authorization",
                                       "Bearer " + admin_token)
     res = api.staffs_info_get()
     assert res.account == ADMIN_ACCOUNT
     assert isinstance(res.phone_number, str)
     assert isinstance(res.real_name, str)
     assert isinstance(res.id, str)
     assert isinstance(res.resource, list)
コード例 #2
0
 def test_no_login_create_staff(self):
     api = staff_management_api.StaffManagementApi()
     faker = Faker()
     account = faker.user_name()
     real_name = faker.name()
     phone = faker.phone_number()
     email = faker.email()
     try:
         api.staffs_post(body={
                           "account": account,
                           "realName": real_name,
                           "phoneNumber": phone,
                           "emailAddress": email}
                         )
     except ApiException as e:
         assert e.status == 403
     else:
         assert False, "未登录创建新职员, java接口异常"
コード例 #3
0
 def test_error_create_staff(self):
     """测试不填写电话和邮箱创建职员"""
     api = staff_management_api.StaffManagementApi()
     admin_token = get_admin_token()
     api.api_client.set_default_header("Authorization",
                                       "Bearer " + admin_token)
     faker = Faker()
     account = faker.user_name()
     real_name = faker.name()
     try:
         api.staffs_post(body={
             "account": account,
             "realName": real_name}
         )
     except ApiException as e:
         assert e.status == 400
     else:
         assert False, "未填写电话和邮箱进行创建职员, java接口异常"
コード例 #4
0
 def test_normal_login_create_staff(self):
     api = staff_management_api.StaffManagementApi()
     admin_token = get_admin_token()
     api.api_client.set_default_header("Authorization",
                                       "Bearer " + admin_token)
     faker = Faker("zh-CN")
     account = faker.user_name()
     real_name = faker.name()
     phone = faker.phone_number()
     email = faker.email()
     api.staffs_post(body={
         "account": account,
         "realName": real_name,
         "phoneNumber": phone,
         "emailAddress": email}
     )
     # 重复创建职员
     try:
         api.staffs_post(body={
             "account": account,
             "realName": real_name,
             "phoneNumber": phone,
             "emailAddress": email}
         )
     except ApiException as e:
         assert e.status == 400
     else:
         assert False, "重复创建职员, java接口异常"
     
     # 获取职员列表判断创建职员成功
     res = api.get_staff_list(page=1, email_address=email)
     assert res.meta.requested_page == 1
     assert res.meta.total_page == 1
     assert res.query.email_address == email
     assert not res.query.role_id
     staff = res.items.pop()
     assert staff.email_address == email
     assert staff.status
     assert staff.account == account
     assert staff.real_name == real_name
     assert staff.phone_number == phone
     staff_id = staff.id
     
     # 禁用不存在的职员
     try:
         api.staffs_put(body={"id": "50000", "status": False})
     except ApiException as e:
         assert e.status == 404
     else:
         assert False, "禁用不存在的账户时, java接口异常"
     
     # 禁用测试账户
     api.staffs_put(body={"id": staff_id, "status": False})
     res = api.get_staff_list(page=1, email_address=email)
     staff = res.items.pop()
     assert not staff.status
     
     # 启用测试账户
     api.staffs_put(body={"id": staff_id, "status": True})
     res = api.get_staff_list(page=1, email_address=email)
     staff = res.items.pop()
     assert staff.status
     
     # 重置不存在的职员密码
     try:
         api.staffs_id_reset_password_post(id="50000000")
     except ApiException as e:
         assert e.status == 404
     else:
         assert False, "重置不存在的职员密码, java接口异常"
         
     # 正常重置职员密码
     api.staffs_id_reset_password_post(id=staff_id)
     
     # 获取不存在的职员角色信息
     try:
         api.staffs_id_roles_get(id="500000")
     except ApiException as e:
         assert e.status == 404
     else:
         assert False, "获取不存在的职员角色信息时, java接口异常"
     # 正常获取职员角色信息
     role_resp = api.staffs_id_roles_get(id=staff_id)
     assert not role_resp
コード例 #5
0
    def test_set_staff_for_role(self):
        staff_api = staff_management_api.StaffManagementApi()
        admin_token = get_admin_token()
        staff_api.api_client.set_default_header("Authorization",
                                                "Bearer " + admin_token)
        faker = Faker('zh_CN')
        account = get_random_name(2, 25)
        real_name = get_random_name(2, 16)
        phone = faker.phone_number()
        email = faker.email()
        # 正常创建一个职员
        staff_api.staffs_post(
            body={
                "account": account,
                "realName": real_name,
                "phoneNumber": phone,
                "emailAddress": email
            })
        res = staff_api.get_staff_list(page=1, email_address=email)
        staff = res.items.pop()
        staff_id = staff.id

        # 正常创建一个角色
        role_api = security_management_api.SecurityManagementApi()
        role_api.api_client.set_default_header("Authorization",
                                               "Bearer " + admin_token)
        role_name = faker.name()
        role_description = "this is description of role"
        resp = role_api.roles_post(body={
            "name": role_name,
            "description": role_description
        })
        role_id = resp.role_id

        # 获取角色列表(无分页)
        res = role_api.roles_list_get()
        for i in res:
            if i["id"] == role_id:
                break
        else:
            assert False

        # 正常将职员分配给角色
        role_api.roles_set_staff_post(role_assignment_staff={
            "roleId": role_id,
            "ids": [staff_id]
        })

        # 查看该角色下的职员信息
        res = role_api.roles_get_staffs_get(role_id=role_id, page=1)
        assert res.meta.total_page == 1
        assert len(res.items) == 1
        item = res.items.pop()
        assert item.id == staff_id
        assert item.phone_number == phone
        assert item.email_address == email
        assert item.account == account
        assert item.real_name == real_name
        assert item.status
        assert len(item.roles) == 1
        role_item = item.roles.pop()
        assert role_item.role_id == role_id
        assert role_item.role_name == role_name

        # 获取职员的角色信息
        res = staff_api.staffs_id_roles_get(id=staff_id)
        assert len(res) == 1
        item = res.pop()
        assert item["id"] == role_id
        assert item["name"] == role_name
        assert item["description"] == role_description
コード例 #6
0
    def test_set_role_for_staff(self):
        staff_api = staff_management_api.StaffManagementApi()
        admin_token = get_admin_token()
        staff_api.api_client.set_default_header("Authorization",
                                                "Bearer " + admin_token)
        faker = Faker('zh_CN')
        account = get_random_name(2, 25)
        real_name = get_random_name(2, 16)
        phone = faker.phone_number()
        email = faker.email()
        # 正常创建一个职员
        staff_api.staffs_post(
            body={
                "account": account,
                "realName": real_name,
                "phoneNumber": phone,
                "emailAddress": email
            })
        res = staff_api.get_staff_list(page=1, email_address=email)
        staff = res.items.pop()
        staff_id = staff.id

        # 分配个该职员不存在的角色
        try:
            staff_api.staffs_set_role_post(body={
                "staffId": staff_id,
                "ids": ["999999"]
            })
        except ApiException as e:
            assert e.status == 400
        else:
            assert False, "分配给给职员不存在的角色, java接口异常"

        # 正常创建一个角色
        role_api = security_management_api.SecurityManagementApi()
        role_api.api_client.set_default_header("Authorization",
                                               "Bearer " + admin_token)
        role_name = faker.name()
        role_description = "this is description of role"
        resp = role_api.roles_post(body={
            "name": role_name,
            "description": role_description
        })
        role_id = resp.role_id

        # 查看不存在角色下的职员信息
        try:
            role_api.roles_get_staffs_get(role_id="999999", page=1)
        except ApiException as e:
            assert e.status == 404

        # 移除该角色下未绑定的职员
        try:
            role_api.roles_remove_staff_post(role_remove_staff={
                "roleId": role_id,
                "staffId": staff_id
            })
        except ApiException as e:
            assert e.status == 404
        else:
            assert False, "移除角色下未绑定的职员, java接口异常"

        # 正常将角色分配给职员
        staff_api.staffs_set_role_post(body={
            "staffId": staff_id,
            "ids": [role_id]
        })

        # 查看该角色下的职员信息
        res = role_api.roles_get_staffs_get(role_id=role_id, page=1)
        assert res.meta.total_page == 1
        assert len(res.items) == 1
        item = res.items.pop()
        assert item.id == staff_id
        assert item.phone_number == phone
        assert item.email_address == email
        assert item.account == account
        assert item.real_name == real_name
        assert item.status
        assert len(item.roles) == 1
        role_item = item.roles.pop()
        assert role_item.role_id == role_id
        assert role_item.role_name == role_name

        # 获取职员的角色信息
        res = staff_api.staffs_id_roles_get(id=staff_id)
        assert len(res) == 1
        item = res.pop()
        assert item["id"] == role_id
        assert item["name"] == role_name
        assert item["description"] == role_description

        # 移除该角色下不存在的职员
        try:
            role_api.roles_remove_staff_post(role_remove_staff={
                "roleId": role_id,
                "staffId": "999999"
            })
        except ApiException as e:
            assert e.status == 404
        else:
            assert False, "移除角色下不存在的职员, java接口异常"

        # 移除不存在的角色下的职员
        try:
            role_api.roles_remove_staff_post(role_remove_staff={
                "roleId": "9999999",
                "staffId": staff_id
            })
        except ApiException as e:
            assert e.status == 404
        else:
            assert False, "移除不存在的角色下的职员, java接口异常"

        # 正常移除角色下职员
        role_api.roles_remove_staff_post(role_remove_staff={
            "roleId": role_id,
            "staffId": staff_id
        })

        # 查看该角色下的职员信息
        res = role_api.roles_get_staffs_get(role_id=role_id, page=1)
        assert res.meta.total_page == 0
        assert not len(res.items)

        # 获取职员的角色信息
        res = staff_api.staffs_id_roles_get(id=staff_id)
        assert not len(res)