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
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
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
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
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]
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"
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()