예제 #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
예제 #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
예제 #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
예제 #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
예제 #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
예제 #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
예제 #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
예제 #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']
예제 #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
예제 #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
예제 #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
예제 #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