def find_employee_from_list(user_id):
    employees = get_all_employee()
    flag = False
    for item in employees["data"]:
        if int(item["id"]) == user_id:
            logger.info(
                "Find an employee with id: {} from employee list".format(
                    user_id))
            flag = True
    return flag
def create_user(user_info):
    logger.info("create a new employee")
    # 这里我们可以设置user template,需要测试的数据写入input就可以了,其他的不测字段使用user template中的值
    user = {"name": "test1", "salary": "1000", "age": "25"}
    input = json.loads(user_info)
    for k in input:
        user[k] = input[k]
    response = request().post("http://dummy.restapiexample.com/api/v1/create",
                              headers=endPoint.HEADERS,
                              json=user).json()
    return response
Exemple #3
0
    def test_create_user(self, case):
        logger.info("Start running test case: {}".format(case["Title"]))

        # Create a new employee and verify the new employeed's information is right
        new_user = create_user(case["Input"])
        assert new_user["status"] == "success"
        assert compare_result(case["Output"], new_user["data"])

        # Verify the new employee could be find from all employee list
        new_user_id = new_user["data"]["id"]
        logger.info("the new empolyee id is {}".format(new_user_id))
        assert find_employee_from_list(
            new_user_id), "new user does not exist in the employee list"

        # Delete the new employee and verify the deleted employee could not be found from employee list
        delete_employee(new_user_id)
        assert not (find_employee_from_list(new_user_id)
                    ), "new user does not be deleted from the employee list"
def delete_employee(id):
    logger.info("Delete an employee with id: {}".format(id))
    url = cfg.domain + endPoint.DELETE_USER + "{}".format(id)
    request().delete(url=url, headers=endPoint.HEADERS)
Exemple #5
0
 def test_delete_user(self):
     logger.info("delete user")
Exemple #6
0
 def teardown_method(self):
     logger.info("teardown_method()")
Exemple #7
0
 def setup_method(self, method):
     logger.info('setup_method()')
Exemple #8
0
 def teardown_class(cls):
     logger.info("teardown_class()")
Exemple #9
0
 def setup_class(cls):
     logger.info('setup_class()')
Exemple #10
0
def teardown_module(module):
    logger.info("teardown_module()")
Exemple #11
0
def setup_module(module):
    logger.info("setup_module()")