Ejemplo n.º 1
0
def test_single_department(_app):
    response_p = _app.get(DEP_VIEW_URL + '/1')
    response_m = _app.get(DEP_VIEW_URL + '/2')
    response_empl_p = _app.get('/api/search/employees/?&department=1')
    response_empl_m = _app.get('/api/search/employees/?&department=2')
    assert response_p.status_code == 200
    assert response_m.status_code == 200
    assert response_empl_p.status_code == 200
    assert response_empl_m.status_code == 200
    assert response_empl_m.get_json() == []
Ejemplo n.º 2
0
def test_employee_get(_app):
    url_present_object = EMP_API_URL + '1'
    url_missing_object = EMP_API_URL + '2'

    response_p = _app.get(url_present_object)
    response_m = _app.get(url_missing_object)

    assert response_p.status_code == 200
    assert response_m.status_code == 404
    assert 'name' in response_p.get_json()
Ejemplo n.º 3
0
def test_department_get(_app):
    """
    GIVEN a url
    WHEN id is passed
    THEN check response from server
    results:
    - id not in db(return not found)
    - id found(return json)
    - 'name' in response json
    """

    url_present_object = DEP_API_URL + '1'
    url_missing_object = DEP_API_URL + '2'

    response_p = _app.get(url_present_object)
    response_m = _app.get(url_missing_object)

    assert response_p.status_code == 200
    assert response_m.status_code == 404
    assert 'name' in response_p.get_json()
Ejemplo n.º 4
0
def test_employees(_app):
    url = '/api/employees/'
    url_filter = url + '?'
    name = 'name=Albert Mayer'
    single_date = "&date1=2020-12-23"
    double_date = "&date1=2020-12-01&date2=2020-12-30"
    formatted_date1 = datetime.strptime('2020-12-01', "%Y-%m-%d")
    formatted_date2 = datetime.strptime('2020-12-30', "%Y-%m-%d")
    department = "&department=0"
    all_one_date = name + single_date + department
    all_two_dates = name + double_date + department
    nonsense = 'XDXDXDXDXD'

    response_bare = _app.get(url)
    response_name = _app.get(url_filter + name)
    response_single_date = _app.get(url_filter + single_date)
    response_double_date = _app.get(url_filter + double_date)
    response_department = _app.get(url_filter + department)
    response_all_one_date = _app.get(url_filter + all_one_date)
    response_all_two_dates = _app.get(url_filter + all_two_dates)
    response_nonsense = _app.get(url_filter + nonsense)

    assert response_bare.get_json() == [{
        "department_id": 1,
        "dob": "2020-12-12",
        "id": 1,
        "name": "TEST0",
        "salary": 1000.0
    }]
    for employee in response_name.get_json():
        assert employee['name'] == 'Albert Mayer'
    for employee in response_single_date.get_json():
        assert employee['dob'] == '2020-12-23'
    for employee in response_double_date.get_json():
        res_date_formatted = datetime.strptime(employee['dob'], "%Y-%m-%d")
        assert formatted_date1 < res_date_formatted < formatted_date2
    for employee in response_department.get_json():
        assert employee['department_id'] == 0
    for employee in response_all_one_date.get_json():
        assert employee['name'] == 'Albert Mayer'
        assert employee['dob'] == '2020-12-23'
        assert employee['department_id'] == 0
    for employee in response_all_two_dates.get_json():
        assert employee['name'] == 'Albert Mayer'
        res_date_formatted = datetime.strptime(employee['dob'], "%Y-%m-%d")
        assert formatted_date1 < res_date_formatted < formatted_date2
        assert employee['department_id'] == 0
    assert response_nonsense.status_code == 404
Ejemplo n.º 5
0
def test_all_departments(_app):
    response = _app.get(DEP_VIEW_URL + 's')
    response_post = _app.post(DEP_API_URL + 'new', json={'name': 'TEST1'})
    response_empty_post = _app.post(DEP_API_URL + 'new')
    assert response.status_code == 200
    assert response_post.status_code == 200
    assert response_post.get_json() == {
        "average_salary": 0.0,
        "id": 2,
        "name": "TEST1",
        "num_of_employees": 0
    }
    assert response_empty_post.status_code == 400
    assert redirect(
        url_for('display_departments')).location == DEP_VIEW_URL + 's'
Ejemplo n.º 6
0
def test_departments(_app):
    """
        GIVEN a url
        WHEN id is passed
        THEN check response from server
        if it is deleted or exists

        results:
        if existing name then delete
        if not then not found
        """

    url_plural = '/api/departments/'

    response = _app.get(url_plural)

    assert response.status_code == 200
Ejemplo n.º 7
0
def test_home(_app):
    response = _app.get('/')
    assert response.status_code == 200
Ejemplo n.º 8
0
def test_create_employee(_app):
    response = _app.get('/new' + EMP_VIEW_URL + '/')
    assert response.status_code == 200
Ejemplo n.º 9
0
def test_single_employee(_app):
    response_p = _app.get(EMP_VIEW_URL + '/1')
    response_m = _app.get(EMP_VIEW_URL + '/22')

    assert response_p.status_code == 200
    assert response_m.status_code == 200
Ejemplo n.º 10
0
def test_all_employees(_app):
    response = _app.get(EMP_VIEW_URL + 's')
    assert response.status_code == 200