Generalize organization test. Add more organization tests to the folders app.
This commit is contained in:
@@ -1,28 +1,52 @@
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from documents.tests.test_views import GenericDocumentViewTestCase
|
||||
from organizations.models import Organization
|
||||
from organizations.tests.test_organization_views import OrganizationViewTestCase
|
||||
|
||||
from ..models import Folder
|
||||
|
||||
from .literals import TEST_FOLDER_LABEL, TEST_FOLDER_EDITED_LABEL
|
||||
|
||||
|
||||
class FolderOrganizationViewTestCase(GenericDocumentViewTestCase):
|
||||
def setUp(self):
|
||||
super(FolderOrganizationViewTestCase, self).setUp()
|
||||
# Create two organizations
|
||||
self.organization_a = Organization.objects.create(
|
||||
label='Organization A'
|
||||
)
|
||||
self.organization_b = Organization.objects.create(
|
||||
label='Organization B'
|
||||
class FolderOrganizationViewTestCase(OrganizationViewTestCase):
|
||||
def test_folder_create_view(self):
|
||||
# Create a folder for organization A
|
||||
with self.settings(ORGANIZATION_ID=self.organization_a.pk):
|
||||
response = self.post(
|
||||
'folders:folder_create', data={
|
||||
'label': TEST_FOLDER_LABEL
|
||||
}
|
||||
)
|
||||
self.assertEqual(response.status_code, 404)
|
||||
self.assertEqual(Folder.on_organization.count(), 1)
|
||||
|
||||
with self.settings(ORGANIZATION_ID=self.organization_b.pk):
|
||||
self.assertEqual(Folder.on_organization.count(), 0)
|
||||
|
||||
def test_folder_delete_view(self):
|
||||
# Create a folder for organization A
|
||||
folder = Folder.objects.create(
|
||||
organization=self.organization_a, label=TEST_FOLDER_LABEL
|
||||
)
|
||||
|
||||
# Create an organization admin for organization B
|
||||
username, password = self.organization_b.create_admin()
|
||||
with self.settings(ORGANIZATION_ID=self.organization_b.pk):
|
||||
# Login organization admin for organization B
|
||||
self.login(username=username, password=password)
|
||||
response = self.post('folders:folder_delete', args=(folder.pk,))
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
def test_folder_edit_view(self):
|
||||
# Create a folder for organization A
|
||||
folder = Folder.objects.create(
|
||||
organization=self.organization_a, label=TEST_FOLDER_LABEL
|
||||
)
|
||||
|
||||
with self.settings(ORGANIZATION_ID=self.organization_b.pk):
|
||||
# Make sure admin for organization B cannot edit the folder
|
||||
response = self.post(
|
||||
'folders:folder_edit', args=(folder.pk,), data={
|
||||
'label': TEST_FOLDER_EDITED_LABEL
|
||||
}
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
def test_folder_view_view(self):
|
||||
# Create a folder for organization A
|
||||
|
||||
23
mayan/apps/organizations/tests/test_organization_views.py
Normal file
23
mayan/apps/organizations/tests/test_organization_views.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from documents.tests.test_views import GenericDocumentViewTestCase
|
||||
|
||||
from ..models import Organization
|
||||
|
||||
|
||||
class OrganizationViewTestCase(GenericDocumentViewTestCase):
|
||||
def setUp(self):
|
||||
super(OrganizationViewTestCase, self).setUp()
|
||||
# Create two organizations
|
||||
self.organization_a = Organization.objects.create(
|
||||
label='Organization A'
|
||||
)
|
||||
self.organization_b = Organization.objects.create(
|
||||
label='Organization B'
|
||||
)
|
||||
|
||||
# Create an organization admin for organization B
|
||||
username, password = self.organization_b.create_admin()
|
||||
with self.settings(ORGANIZATION_ID=self.organization_b.pk):
|
||||
# Login organization admin for organization B
|
||||
self.login(username=username, password=password)
|
||||
Reference in New Issue
Block a user