Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nirizr/improve tests #202

Merged
merged 3 commits into from
Feb 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 34 additions & 15 deletions tests/server/collab/test_all.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
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

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))

Expand Down Expand Up @@ -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)
Expand Down