Finish base document states API views.
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ api_urls = [
|
||||
name='workflow-document-type-list'
|
||||
),
|
||||
url(
|
||||
r'^workflows/(?P<pk>[0-9]+)/document_types/(?P<document_pk>[0-9]+)/$',
|
||||
r'^workflows/(?P<pk>[0-9]+)/document_types/(?P<document_type_pk>[0-9]+)/$',
|
||||
APIWorkflowDocumentTypeView.as_view(),
|
||||
name='workflow-document-type-detail'
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user