diff --git a/tests/server/collab/test_all.py b/tests/server/collab/test_all.py index 660820fa2..00b39ffe0 100644 --- a/tests/server/collab/test_all.py +++ b/tests/server/collab/test_all.py @@ -1,7 +1,6 @@ import pytest -import json from functools import partial -from rest_framework import status +from rest_framework import status, test from django.db import models from collab.models import Project, File, FileVersion, Task, Instance, Vector @@ -9,6 +8,18 @@ import random +@pytest.fixture +def api_client(): + return test.APIClient() + + +@pytest.fixture +def admin_api_client(admin_user): + client = test.APIClient() + client.force_authenticate(user=admin_user) + return client + + def rand_hash(n): return ''.join(random.choice("01234567890ABCDEF") for _ in range(n)) @@ -119,49 +130,57 @@ def assert_response(response, status, data=None): @pytest.mark.django_db @pytest.mark.parametrize('model_name', collab_models.keys()) -def test_empty_lists(client, model_name): - response = client.get('/collab/{}/'.format(model_name)) +def test_empty_lists(api_client, model_name): + response = api_client.get('/collab/{}/'.format(model_name), + HTTP_ACCEPT='application/json') assert_response(response, status.HTTP_200_OK, []) @pytest.mark.django_db @pytest.mark.parametrize('model_name', collab_models.keys()) -def test_model_guest_list(client, admin_user, model_name): +def test_model_guest_list(api_client, admin_user, model_name): # setup objects obj = create_model(model_name, admin_user) obj.save() - response = client.get('/collab/{}/'.format(model_name)) + response = api_client.get('/collab/{}/'.format(model_name), + HTTP_ACCEPT="application/json") assert_response(response, status.HTTP_200_OK, [obj]) @pytest.mark.django_db @pytest.mark.parametrize('model_name', collab_models.keys()) -def test_model_guest_creation(client, admin_user, model_name): +def test_model_guest_creation(api_client, admin_user, model_name): model_data = setup_model(model_name, admin_user) - response = client.post('/collab/{}/'.format(model_name), - data=json.dumps(model_data), - content_type="application/json") + response = api_client.post('/collab/{}/'.format(model_name), + data=model_data, + HTTP_ACCEPT="application/json") assert_response(response, status.HTTP_401_UNAUTHORIZED) @pytest.mark.django_db @pytest.mark.parametrize('model_name', collab_models.keys()) -def test_model_creation(client, admin_client, admin_user, model_name): +def test_model_creation(api_client, admin_api_client, admin_user, model_name): model_data = setup_model(model_name, admin_user) - response = admin_client.post('/collab/{}/'.format(model_name), - data=json.dumps(model_data), - content_type="application/json") + response = admin_api_client.post('/collab/{}/'.format(model_name), + data=model_data, + HTTP_ACCEPT='application/json') assert_response(response, status.HTTP_201_CREATED) projects_created = [response.json()] - response = client.get('/collab/{}/'.format(model_name)) + response = api_client.get('/collab/{}/'.format(model_name), + HTTP_ACCEPT="application/json") assert_eq(response.json(), projects_created) +def test_template(admin_client): + response = admin_client.get('/accounts/profile/') + assert_response(response, status.HTTP_200_OK) + + @pytest.mark.django_db def test_file_fileversion(admin_client, admin_user): file = create_model('files', admin_user)