Files
mayan-edms/mayan/apps/common/tests/test_views.py
Roberto Rosario 36a51eeb73 Switch to full app paths
Instead of inserting the path of the apps into the Python app,
the apps are now referenced by their full import path.

This solves name clashes with external or native Python libraries.
Example: Mayan statistics app vs. Python new statistics library.

Every app reference is now prepended with 'mayan.apps'.

Existing config.yml files need to be updated manually.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
2019-04-05 02:02:57 -04:00

69 lines
2.1 KiB
Python

from __future__ import absolute_import, unicode_literals
from django.contrib.auth import get_user_model
from django.contrib.contenttypes.models import ContentType
from mayan.apps.acls import ModelPermission
from ..models import ErrorLogEntry
from ..permissions_runtime import permission_error_log_view
from .base import GenericViewTestCase
from .literals import TEST_ERROR_LOG_ENTRY_RESULT
class CommonViewTestCase(GenericViewTestCase):
def test_about_view(self):
self.login_user()
response = self.get('common:about_view')
self.assertContains(response, text='About', status_code=200)
def _create_error_log_entry(self):
ModelPermission.register(
model=get_user_model(), permissions=(permission_error_log_view,)
)
ErrorLogEntry.objects.register(model=get_user_model())
self.error_log_entry = self.user.error_logs.create(
result=TEST_ERROR_LOG_ENTRY_RESULT
)
def _request_object_error_log_list(self):
content_type = ContentType.objects.get_for_model(model=self.user)
return self.get(
'common:object_error_list', kwargs={
'app_label': content_type.app_label,
'model': content_type.model,
'object_id': self.user.pk
}, follow=True
)
def test_object_error_list_view_with_permissions(self):
self._create_error_log_entry()
self.login_user()
self.grant_access(
obj=self.user, permission=permission_error_log_view
)
response = self._request_object_error_log_list()
self.assertContains(
response=response, text=TEST_ERROR_LOG_ENTRY_RESULT,
status_code=200
)
def test_object_error_list_view_no_permissions(self):
self._create_error_log_entry()
self.login_user()
response = self._request_object_error_log_list()
self.assertNotContains(
response=response, text=TEST_ERROR_LOG_ENTRY_RESULT,
status_code=403
)