From e4da3eb7866d659f2b8f219588d59bcc8f8ff378 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Wed, 8 Feb 2017 20:46:34 -0400 Subject: [PATCH] Finish base document states API views. --- mayan/apps/document_states/api_views.py | 6 +-- mayan/apps/document_states/tests/test_api.py | 56 +++++++++++++++++++- mayan/apps/document_states/urls.py | 2 +- 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/mayan/apps/document_states/api_views.py b/mayan/apps/document_states/api_views.py index 1f61c1980a..c838a82849 100644 --- a/mayan/apps/document_states/api_views.py +++ b/mayan/apps/document_states/api_views.py @@ -108,7 +108,7 @@ class APIWorkflowDocumentTypeList(generics.ListCreateAPIView): class APIWorkflowDocumentTypeView(generics.RetrieveDestroyAPIView): filter_backends = (MayanObjectPermissionsFilter,) - lookup_url_kwarg = 'document_pk' + lookup_url_kwarg = 'document_type_pk' mayan_object_permissions = { 'GET': (permission_document_type_view,), } @@ -177,8 +177,8 @@ class APIWorkflowDocumentTypeView(generics.RetrieveDestroyAPIView): RESEARCH: Move this kind of methods to the serializer instead it that ability becomes available in Django REST framework """ - print "DESTROY!" - self.get_workflow().documents.remove(instance) + + self.get_workflow().document_types.remove(instance) class APIWorkflowListView(generics.ListCreateAPIView): diff --git a/mayan/apps/document_states/tests/test_api.py b/mayan/apps/document_states/tests/test_api.py index 3fd55a3f32..bf2ea54d82 100644 --- a/mayan/apps/document_states/tests/test_api.py +++ b/mayan/apps/document_states/tests/test_api.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals from django.contrib.auth import get_user_model from django.core.urlresolvers import reverse from django.test import override_settings +from django.utils.encoding import force_text from rest_framework.test import APITestCase @@ -92,6 +93,60 @@ class WorkflowAPITestCase(APITestCase): self.assertEqual(response.data['label'], workflow.label) + def test_workflow_document_type_create_view(self): + workflow = self._create_workflow() + + response = self.client.post( + reverse( + 'rest_api:workflow-document-type-list', + args=(workflow.pk,) + ), data={'document_type_pk': self.document_type.pk} + ) + + self.assertQuerysetEqual( + workflow.document_types.all(), (repr(self.document_type),) + ) + + def test_workflow_document_type_delete_view(self): + workflow = self._create_workflow() + workflow.document_types.add(self.document_type) + + response = self.client.delete( + reverse( + 'rest_api:workflow-document-type-detail', + args=(workflow.pk, self.document_type.pk) + ) + ) + + workflow.refresh_from_db() + self.assertQuerysetEqual(workflow.document_types.all(), ()) + + def test_workflow_document_type_detail_view(self): + workflow = self._create_workflow() + workflow.document_types.add(self.document_type) + + response = self.client.get( + reverse( + 'rest_api:workflow-document-type-detail', + args=(workflow.pk, self.document_type.pk) + ) + ) + + self.assertEqual(response.data['label'], self.document_type.label) + + def test_workflow_document_type_list_view(self): + workflow = self._create_workflow() + workflow.document_types.add(self.document_type) + + response = self.client.get( + reverse('rest_api:workflow-document-type-list', + args=(workflow.pk,)) + ) + + self.assertEqual( + response.data['results'][0]['label'], self.document_type.label + ) + def test_workflow_list_view(self): workflow = self._create_workflow() @@ -120,4 +175,3 @@ class WorkflowAPITestCase(APITestCase): workflow.refresh_from_db() self.assertEqual(workflow.label, TEST_WORKFLOW_LABEL_EDITED) - diff --git a/mayan/apps/document_states/urls.py b/mayan/apps/document_states/urls.py index 34b9bffd16..a11c453718 100644 --- a/mayan/apps/document_states/urls.py +++ b/mayan/apps/document_states/urls.py @@ -114,7 +114,7 @@ api_urls = [ name='workflow-document-type-list' ), url( - r'^workflows/(?P[0-9]+)/document_types/(?P[0-9]+)/$', + r'^workflows/(?P[0-9]+)/document_types/(?P[0-9]+)/$', APIWorkflowDocumentTypeView.as_view(), name='workflow-document-type-detail' ),