Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
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']
Ejemplo n.º 9
0
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
Ejemplo n.º 10
0
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
Ejemplo n.º 11
0
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
Ejemplo n.º 12
0
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