def test_get_department_unauthorized(): client = APIClient() department, _ = get_department() url = reverse('department', args=(department.id, )) resp = client.get(path=url) assert resp.status_code == 403
def test_patch_department_no_permissions(client): department, _ = get_department() url = reverse('department', args=(department.id, )) patch_body = {'name': 'IT Department'} resp = client.patch(url, data=patch_body, format='json') assert resp.status_code == 403
def test_put_department_unauthorized(): client = APIClient() department, valid_body = get_department() url = reverse('department', args=(department.id, )) resp = client.put(url, data=valid_body, format='json') assert resp.status_code == 403
def test_patch_department_not_valid(admin_client): department, _ = get_department() url = reverse('department', args=(department.id, )) not_valid_body = {'head_of_department': 'NOT_VALID_DATA'} resp = admin_client.patch(url, data=not_valid_body, format='json') assert resp.status_code == 400
def test_put_department_object_does_not_exist(admin_client): department_not_exist_pk = 999 _, valid_body = get_department() url = reverse('department', args=(department_not_exist_pk, )) resp = admin_client.put(url, data=valid_body, format='json') assert resp.status_code == 404
def test_put_department_not_valid(admin_client): department, body = get_department() url = reverse('department', args=(department.id, )) body['head_of_department'] = 'NOT_VALID_DATA' resp = admin_client.put(url, data=body, format='json') assert resp.status_code == 400
def test_patch_department_unauthorized(): client = APIClient() department, _ = get_department() url = reverse('department', args=(department.id, )) patch_body = {'name': 'IT Department'} resp = client.patch(url, data=patch_body, format='json') assert resp.status_code == 403
def test_patch_department_success(admin_client): department, _ = get_department() url = reverse('department', args=(department.id, )) patch_body = {'name': 'IT Department'} resp = admin_client.patch(url, data=patch_body, format='json') assert resp.status_code == 200 assert resp.data['name'] == patch_body['name']
def test_put_department_success(admin_client): department, body = get_department() url = reverse('department', args=(department.id, )) new_name = 'IT Department' body['name'] = new_name resp = admin_client.put(url, data=body, format='json') assert resp.status_code == 200 assert resp.data['name'] == new_name
def test_get_department_no_permissions(client): department, _ = get_department() url = reverse('department', args=(department.id, )) resp = client.get(path=url) assert resp.status_code == 403
def test_get_department_success(admin_client): department, _ = get_department() url = reverse('department', args=(department.id, )) resp = admin_client.get(path=url) assert 200 == resp.status_code
def test_put_department_no_permissions(client): department, valid_body = get_department() url = reverse('department', args=(department.id, )) resp = client.put(url, data=valid_body, format='json') assert resp.status_code == 403