Beispiel #1
0
def test_employee_bad_update(admin, client, employee):
    """Expect that we can't update a employee if a field is wrong."""
    token_header = get_token(client)
    data = {"preference": "truc"}
    response = client.patch(
        f"/api/work/employees/{employee.pk}/", data, "application/json", **token_header
    )
    assert response.status_code == 400
Beispiel #2
0
def test_employee_good_creation(admin, client: Client):
    """Expect that we can create a employee."""
    token_header = get_token(client)
    response = client.post(
        "/api/work/employees/",
        {"name": "john", "preference": "morning", "salary": 10},
        **token_header,
    )
    assert response.status_code == 201
Beispiel #3
0
def test_employee_bad_creation(admin, client: Client):
    """Expect that we can't create a employee if a field is wrong."""
    token_header = get_token(client)
    response = client.post(
        "/api/work/employees/",
        {"name": "john", "preference": "truc", "salary": 10},
        **token_header,
    )
    assert response.status_code == 400
Beispiel #4
0
def test_month_days_contains_alls_week_days(client, user):
    """Ensure the days from a month can contains days from last or next month."""
    create_initial_days.Command().handle()
    token_header = get_token(client, False)

    response = client.get("/api/work/month/0/", **token_header)
    days = response.json()
    last_month = now.month - 1 if now.month != 1 else 12
    next_month = now.month + 1 if now.month != 12 else 1
    months = [day["month"] for day in days]
    assert last_month in months or next_month in months
Beispiel #5
0
def test_employee_update(admin, client, employee):
    """Expect that we can update a employee."""
    token_header = get_token(client)
    assert employee.name == "john"
    data = {"name": "LoLo", "salary": 11}
    response = client.patch(
        f"/api/work/employees/{employee.pk}/", data, "application/json", **token_header
    )
    assert response.status_code == 200
    assert response.json()["name"] == "LoLo"
    employee.refresh_from_db()
    assert employee.name == "LoLo"
Beispiel #6
0
def test_work_day_not_admin_creation(user, client, employee):
    """Test fail work day creation."""
    create_initial_days.Command().handle()

    token_header = get_token(client, False)
    response = client.get("/api/work/month/0/", **token_header)
    day = response.json()[0]

    response = client.post(
        "/api/work/workdays/",
        {"day": day["id"], "employee": employee.id, "start": now, "end": now},
        **token_header,
    )
    assert response.status_code == 403
Beispiel #7
0
def test_retrieve_workday_in_month(client, admin, employee):
    """Find a spectifi workday."""
    create_initial_days.Command().handle()
    token_header = get_token(client)

    response = client.get("/api/work/month/0/", **token_header)
    day = response.json()[0]

    response = client.post(
        "/api/work/workdays/",
        {"day": day["id"], "employee": employee.id, "start": now, "end": now},
        **token_header,
    )
    assert response.status_code == 201

    response = client.get("/api/work/month/0/", **token_header)
    day = response.json()[0]
    assert day["works"][0]["employee"] == employee.id
Beispiel #8
0
def test_month_route(client, user):
    """Test the month route."""
    create_initial_days.Command().handle()
    token_header = get_token(client, False)

    response = client.get("/api/work/month/-1/", **token_header)
    assert response.status_code == 200
    assert 27 < len(response.json()) < 50

    response = client.get("/api/work/month/0/", **token_header)
    assert response.status_code == 200
    assert 27 < len(response.json()) < 50

    response = client.get("/api/work/month/1/", **token_header)
    assert response.status_code == 200
    assert 27 < len(response.json()) < 50

    response = client.get("/api/work/month/2/", **token_header)
    assert response.status_code == 200
    days = len(response.json())
    assert days == 7 or days == 0
Beispiel #9
0
def test_employee_getall(client, user, employee):
    """Expect that we can get all employees."""
    token_header = get_token(client, False)
    response = client.get("/api/work/employees/", **token_header)
    assert response.status_code == 200
    assert response.json()[0]
Beispiel #10
0
def test_employee_get(client, user, employee):
    """Expect that we can get an employee."""
    token_header = get_token(client, False)
    response = client.get(f"/api/work/employees/{employee.pk}/", **token_header)
    assert response.status_code == 200
    assert response.json()["name"] == "john"
Beispiel #11
0
def test_employee_deletion(admin, client, employee):
    """Expect that we can delete a employee."""
    token_header = get_token(client)
    response = client.delete(f"/api/work/employees/{employee.pk}/", **token_header)
    assert response.status_code == 204
Beispiel #12
0
def test_employee_cant_get_employee_if_not_superuser(client, user, employee):
    """Expect that we can get an employee."""
    token_header = get_token(client, False)
    response = client.get(f"/api/work/employees/{employee.pk}/", **token_header)
    assert response.status_code == 200
    assert "salary" not in response.json()