コード例 #1
0
def test_unit_search_with_multi_parameters():
    """
    Test function "find_employees" with multiples parameters.
    :return:
    """
    company = 'Google'
    age_min = 22
    age_max = 56
    gender = 'female'
    join_date_start = datetime.strptime("2005-01-01 00:00:00",
                                        '%Y-%m-%d %H:%M:%S')
    join_date_stop = datetime.strptime("2005-12-31 23:59:59",
                                       '%Y-%m-%d %H:%M:%S')
    job_title = 'driver'
    salary_min = 1600
    salary_max = 6600

    result = find_employees(company=company,
                            age_min=age_min,
                            gender=gender,
                            join_date_start=join_date_start,
                            join_date_stop=join_date_stop,
                            job_title=job_title,
                            salary_min=salary_min,
                            salary_max=salary_max)

    assert len(result) == 2

    for i in result:
        assert age_min <= i['age'] <= age_max
        assert i['company'] == company
        assert join_date_start <= i['join_date'] <= join_date_stop
        assert i['gender'] == gender
        assert i['job_title'] == job_title
        assert salary_min <= i['salary'] <= salary_max
コード例 #2
0
def test_unit_search_with_default_param():
    """
    Test function "find_employees" without any parameters (default parameters).
    :return:
    """

    result = find_employees()
    assert len(result) == 600
コード例 #3
0
def test_unit_search_by_email():
    """
    Test function "find_employees" with "email" parameter.
    :return:
    """
    email = '*****@*****.**'
    result = find_employees(email=email)

    assert len(result) == 1
    assert result[0]['email'] == email
コード例 #4
0
def test_unit_search_by_company():
    """
    Test function "find_employees" with "company" parameter.
    :return:
    """
    company = 'Yandex'
    result = find_employees(company=company)

    assert len(result) == 84
    for i in result:
        assert i['company'] == company
コード例 #5
0
def test_unit_search_by_name():
    """
    Test function "find_employees" with "name" parameter.
    :return:
    """
    name = 'Sawyer Robbins'

    result = find_employees(name=name)

    assert len(result) == 1
    assert result[0]['name'] == name
コード例 #6
0
def test_unit_search_by_gender():
    """
    Test function "find_employees" with "gender" parameter.
    :return:
    """
    gender = 'male'
    result = find_employees(gender=gender)

    assert len(result) == 203
    for i in result:
        assert i['gender'] == gender
コード例 #7
0
def test_unit_search_by_job_title():
    """
    Test function "find_employees" with "job_title" parameter.
    :return:
    """
    job_title = 'developer'
    result = find_employees(job_title=job_title)

    assert len(result) == 102
    for i in result:
        assert i['job_title'] == job_title
コード例 #8
0
def search_employees(
        name: Optional[str] = Query(None, max_length=100),
        email: Optional[EmailStr] = Query(None),
        age_min: Optional[int] = Query(1, ge=1, le=100),
        age_max: Optional[int] = Query(99, ge=0, le=100),
        company: Optional[str] = Query(None, max_length=100),
        join_date_start: Optional[datetime] = Query(
            datetime.strptime('1900-01-01', '%Y-%m-%d')),
        join_date_stop: Optional[datetime] = Query(datetime.today()),
        job_title: Optional[str] = Query(None, max_length=100),
        gender: Optional[str] = Query(None, max_length=100),
        salary_min: Optional[int] = Query(0, ge=0, le=99999999999),
        salary_max: Optional[int] = Query(99999999999, ge=0, le=99999999999),
):
    """
    Searching employees by parameters.
    :param name:
    :param email:
    :param age_min:
    :param age_max:
    :param company:
    :param join_date_start:
    :param join_date_stop:
    :param job_title:
    :param gender:
    :param salary_min:
    :param salary_max:
    :return:
    """
    if age_min > age_max:
        raise HTTPException(status_code=HTTP_422_UNPROCESSABLE_ENTITY,
                            detail='age_min can not more than age_max')

    if salary_min > salary_max:
        raise HTTPException(status_code=HTTP_422_UNPROCESSABLE_ENTITY,
                            detail='salary_min can not more than salary_max')

    if join_date_start > join_date_stop:
        raise HTTPException(
            status_code=HTTP_422_UNPROCESSABLE_ENTITY,
            detail='join_date_start can not later than join_date_stop')

    return find_employees(name=name,
                          email=email,
                          age_min=age_min,
                          age_max=age_max,
                          company=company,
                          join_date_start=join_date_start,
                          join_date_stop=join_date_stop,
                          job_title=job_title,
                          gender=gender,
                          salary_min=salary_min,
                          salary_max=salary_max)
コード例 #9
0
def test_unit_search_by_one_age():
    """
    Test function "find_employees" with "age" parameters.
    age_min == age_max
    :return:
    """
    age = 36
    result = find_employees(age_min=age, age_max=age)

    assert len(result) == 10
    for i in result:
        assert i['age'] == age
コード例 #10
0
def test_unit_search_by_one_salary():
    """
    Test function "find_employees" with "salary" parameters.
    salary_min == salary_max
    :return:
    """
    salary = 4944
    result = find_employees(salary_min=salary, salary_max=salary)

    assert len(result) == 1
    for i in result:
        assert i['salary'] == salary
コード例 #11
0
def test_unit_search_by_diff_age():
    """
    Test function "find_employees" with "age" parameters.
    age_min != age_max
    :return:
    """
    age_min = 36
    age_max = 46
    result = find_employees(age_min=age_min, age_max=age_max)

    assert len(result) == 117
    for i in result:
        assert age_min <= i['age'] <= age_max
コード例 #12
0
def test_unit_search_by_diff_salary():
    """
    Test function "find_employees" with "salary" parameters.
    salary_min != salary_max
    :return:
    """
    salary_min = 3600
    salary_max = 4600
    result = find_employees(salary_min=salary_min, salary_max=salary_max)

    assert len(result) == 62
    for i in result:
        assert salary_min <= i['salary'] <= salary_max
コード例 #13
0
def test_unit_search_by_one_join_date():
    """
    Test function "find_employees" with "join_date" parameters.
    join_date_start == join_date_stop
    :return:
    """
    join_date = datetime.strptime("2012-12-29 03:00:10", '%Y-%m-%d %H:%M:%S')

    result = find_employees(join_date_start=join_date,
                            join_date_stop=join_date)

    assert len(result) == 1
    for i in result:
        assert i['join_date'] == join_date
コード例 #14
0
def test_unit_search_by_diff_join_date():
    """
    Test function "find_employees" with "join_date" parameters.
    join_date_start != join_date_stop
    :return:
    """
    join_date_start = datetime.strptime("2012-12-29 03:00:10",
                                        '%Y-%m-%d %H:%M:%S')
    join_date_stop = datetime.strptime("2013-12-29 03:00:10",
                                       '%Y-%m-%d %H:%M:%S')

    result = find_employees(join_date_start=join_date_start,
                            join_date_stop=join_date_stop)

    assert len(result) == 41
    for i in result:
        assert join_date_start <= i['join_date'] <= join_date_stop