Improve document indexing tests and add test for GitLab issue #268 @bat79a
This commit is contained in:
@@ -5,15 +5,16 @@ from user_management.tests import (
|
||||
TEST_USER_USERNAME, TEST_USER_PASSWORD
|
||||
)
|
||||
|
||||
from ..models import Index
|
||||
from ..models import Index, IndexInstanceNode
|
||||
from ..permissions import (
|
||||
permission_document_indexing_create, permission_document_indexing_delete,
|
||||
permission_document_indexing_edit
|
||||
permission_document_indexing_edit, permission_document_indexing_view
|
||||
)
|
||||
|
||||
TEST_INDEX_LABEL = 'test label'
|
||||
TEST_INDEX_EDITED_LABEL = 'test edited label'
|
||||
TEST_INDEX_SLUG = 'test_slug'
|
||||
from .literals import (
|
||||
TEST_INDEX_LABEL, TEST_INDEX_LABEL_EDITED, TEST_INDEX_SLUG,
|
||||
TEST_INDEX_TEMPLATE_LABEL_EXPRESSION
|
||||
)
|
||||
|
||||
|
||||
class IndexViewTestCase(GenericDocumentViewTestCase):
|
||||
@@ -84,7 +85,7 @@ class IndexViewTestCase(GenericDocumentViewTestCase):
|
||||
|
||||
response = self.post(
|
||||
'indexing:index_setup_edit', args=(index.pk,), data={
|
||||
'label': TEST_INDEX_EDITED_LABEL, 'slug': TEST_INDEX_SLUG
|
||||
'label': TEST_INDEX_LABEL_EDITED, 'slug': TEST_INDEX_SLUG
|
||||
}
|
||||
)
|
||||
self.assertEqual(response.status_code, 403)
|
||||
@@ -104,10 +105,55 @@ class IndexViewTestCase(GenericDocumentViewTestCase):
|
||||
|
||||
response = self.post(
|
||||
'indexing:index_setup_edit', args=(index.pk,), data={
|
||||
'label': TEST_INDEX_EDITED_LABEL, 'slug': TEST_INDEX_SLUG
|
||||
'label': TEST_INDEX_LABEL_EDITED, 'slug': TEST_INDEX_SLUG
|
||||
}, follow=True
|
||||
)
|
||||
|
||||
index = Index.objects.get(pk=index.pk)
|
||||
self.assertContains(response, text='update', status_code=200)
|
||||
self.assertEqual(index.label, TEST_INDEX_EDITED_LABEL)
|
||||
self.assertEqual(index.label, TEST_INDEX_LABEL_EDITED)
|
||||
|
||||
def create_test_index(self):
|
||||
# Create empty index
|
||||
index = Index.objects.create(label=TEST_INDEX_LABEL)
|
||||
|
||||
# Add our document type to the new index
|
||||
index.document_types.add(self.document_type)
|
||||
|
||||
# Create simple index template
|
||||
root = index.template_root
|
||||
index.node_templates.create(
|
||||
parent=root, expression=TEST_INDEX_TEMPLATE_LABEL_EXPRESSION,
|
||||
link_documents=True
|
||||
)
|
||||
|
||||
# Rebuild indexes
|
||||
IndexInstanceNode.objects.rebuild_all_indexes()
|
||||
|
||||
return index
|
||||
|
||||
def test_index_instance_node_view_no_permission(self):
|
||||
index = self.create_test_index()
|
||||
|
||||
self.login(username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD)
|
||||
|
||||
response = self.get(
|
||||
'indexing:index_instance_node_view', args=(index.instance_root.pk,)
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 403)
|
||||
|
||||
def test_index_instance_node_view_with_permission(self):
|
||||
index = self.create_test_index()
|
||||
|
||||
self.login(username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD)
|
||||
|
||||
self.role.permissions.add(
|
||||
permission_document_indexing_view.stored_permission
|
||||
)
|
||||
|
||||
response = self.get(
|
||||
'indexing:index_instance_node_view', args=(index.instance_root.pk,)
|
||||
)
|
||||
|
||||
self.assertContains(response, text=TEST_INDEX_LABEL, status_code=200)
|
||||
|
||||
Reference in New Issue
Block a user