@ -1,32 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TenancyObject:
|
|
||||||
""" Tests for checking TenancyObject """
|
|
||||||
|
|
||||||
model = None
|
|
||||||
""" Model to be tested """
|
|
||||||
|
|
||||||
should_model_history_be_saved: bool = True
|
|
||||||
""" Should model history be saved.
|
|
||||||
|
|
||||||
By default this should always be 'True', however in special
|
|
||||||
circumstances, this may not be desired.
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
# def test_history_save(self):
|
|
||||||
# """Confirm the desired intent for saving model history."""
|
|
||||||
|
|
||||||
# assert self.model.save_model_history == self.should_model_history_be_saved
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# @pytest.mark.skip(reason="to be written")
|
|
||||||
# def test_edit_no_organization_fails(self):
|
|
||||||
# """ Devices must be assigned an organization
|
|
||||||
|
|
||||||
# Must not be able to edit an item without an organization
|
|
||||||
# """
|
|
||||||
# pass
|
|
||||||
|
|
@ -1,487 +0,0 @@
|
|||||||
import pytest
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
from django.test import Client
|
|
||||||
from django.shortcuts import reverse
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ModelPermissionsView:
|
|
||||||
""" Tests for checking model view permissions """
|
|
||||||
|
|
||||||
|
|
||||||
app_namespace: str = None
|
|
||||||
|
|
||||||
url_name_view: str
|
|
||||||
|
|
||||||
url_view_kwargs: dict = None
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_model_view_user_anon_denied(self):
|
|
||||||
""" Check correct permission for view
|
|
||||||
|
|
||||||
Attempt to view as anon user
|
|
||||||
"""
|
|
||||||
|
|
||||||
client = Client()
|
|
||||||
|
|
||||||
if self.app_namespace:
|
|
||||||
|
|
||||||
url = reverse(self.app_namespace + ':' + self.url_name_view, kwargs=self.url_view_kwargs)
|
|
||||||
|
|
||||||
else:
|
|
||||||
|
|
||||||
url = reverse(self.url_name_view, kwargs=self.url_view_kwargs)
|
|
||||||
|
|
||||||
response = client.get(url)
|
|
||||||
|
|
||||||
assert response.status_code == 302 and response.url.startswith('/account/login')
|
|
||||||
|
|
||||||
|
|
||||||
def test_model_view_no_permission_denied(self):
|
|
||||||
""" Check correct permission for view
|
|
||||||
|
|
||||||
Attempt to view with user missing permission
|
|
||||||
"""
|
|
||||||
|
|
||||||
client = Client()
|
|
||||||
if self.app_namespace:
|
|
||||||
|
|
||||||
url = reverse(self.app_namespace + ':' + self.url_name_view, kwargs=self.url_view_kwargs)
|
|
||||||
|
|
||||||
else:
|
|
||||||
|
|
||||||
url = reverse(self.url_name_view, kwargs=self.url_view_kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
client.force_login(self.no_permissions_user)
|
|
||||||
response = client.get(url)
|
|
||||||
|
|
||||||
assert response.status_code == 403
|
|
||||||
|
|
||||||
|
|
||||||
def test_model_view_different_organizaiton_denied(self):
|
|
||||||
""" Check correct permission for view
|
|
||||||
|
|
||||||
Attempt to view with user from different organization
|
|
||||||
"""
|
|
||||||
|
|
||||||
client = Client()
|
|
||||||
if self.app_namespace:
|
|
||||||
|
|
||||||
url = reverse(self.app_namespace + ':' + self.url_name_view, kwargs=self.url_view_kwargs)
|
|
||||||
|
|
||||||
else:
|
|
||||||
|
|
||||||
url = reverse(self.url_name_view, kwargs=self.url_view_kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
client.force_login(self.different_organization_user)
|
|
||||||
response = client.get(url)
|
|
||||||
|
|
||||||
assert response.status_code == 403
|
|
||||||
|
|
||||||
|
|
||||||
def test_model_view_has_permission(self):
|
|
||||||
""" Check correct permission for view
|
|
||||||
|
|
||||||
Attempt to view as user with view permission
|
|
||||||
"""
|
|
||||||
|
|
||||||
client = Client()
|
|
||||||
if self.app_namespace:
|
|
||||||
|
|
||||||
url = reverse(self.app_namespace + ':' + self.url_name_view, kwargs=self.url_view_kwargs)
|
|
||||||
|
|
||||||
else:
|
|
||||||
|
|
||||||
url = reverse(self.url_name_view, kwargs=self.url_view_kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
client.force_login(self.view_user)
|
|
||||||
response = client.get(url)
|
|
||||||
|
|
||||||
assert response.status_code == 200
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ModelPermissionsAdd:
|
|
||||||
""" Tests for checking model Add permissions """
|
|
||||||
|
|
||||||
app_namespace: str = None
|
|
||||||
|
|
||||||
url_name_add: str
|
|
||||||
|
|
||||||
url_add_kwargs: dict = None
|
|
||||||
|
|
||||||
add_data: dict = None
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip(reason="ToDO: write test")
|
|
||||||
def test_model_requires_attribute_parent_model(self):
|
|
||||||
""" Child model requires 'django view' attribute 'parent_model'
|
|
||||||
|
|
||||||
When a child-model is added the parent model is required so that the organization can be detrmined.
|
|
||||||
"""
|
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def test_model_add_user_anon_denied(self):
|
|
||||||
""" Check correct permission for add
|
|
||||||
|
|
||||||
Attempt to add as anon user
|
|
||||||
"""
|
|
||||||
|
|
||||||
client = Client()
|
|
||||||
|
|
||||||
if self.app_namespace:
|
|
||||||
|
|
||||||
url = reverse(self.app_namespace + ':' + self.url_name_add, kwargs=self.url_add_kwargs)
|
|
||||||
|
|
||||||
else:
|
|
||||||
|
|
||||||
url = reverse(self.url_name_add, kwargs=self.url_add_kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
response = client.put(url, data=self.add_data)
|
|
||||||
|
|
||||||
assert response.status_code == 302 and response.url.startswith('/account/login')
|
|
||||||
|
|
||||||
# @pytest.mark.skip(reason="ToDO: figure out why fails")
|
|
||||||
def test_model_add_no_permission_denied(self):
|
|
||||||
""" Check correct permission for add
|
|
||||||
|
|
||||||
Attempt to add as user with no permissions
|
|
||||||
"""
|
|
||||||
|
|
||||||
client = Client()
|
|
||||||
|
|
||||||
if self.app_namespace:
|
|
||||||
|
|
||||||
url = reverse(self.app_namespace + ':' + self.url_name_add, kwargs=self.url_add_kwargs)
|
|
||||||
|
|
||||||
else:
|
|
||||||
|
|
||||||
url = reverse(self.url_name_add, kwargs=self.url_add_kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
client.force_login(self.no_permissions_user)
|
|
||||||
response = client.post(url, data=self.add_data)
|
|
||||||
|
|
||||||
assert response.status_code == 403
|
|
||||||
|
|
||||||
|
|
||||||
# @pytest.mark.skip(reason="ToDO: figure out why fails")
|
|
||||||
def test_model_add_different_organization_denied(self):
|
|
||||||
""" Check correct permission for add
|
|
||||||
|
|
||||||
attempt to add as user from different organization
|
|
||||||
"""
|
|
||||||
|
|
||||||
client = Client()
|
|
||||||
|
|
||||||
if self.app_namespace:
|
|
||||||
|
|
||||||
url = reverse(self.app_namespace + ':' + self.url_name_add, kwargs=self.url_add_kwargs)
|
|
||||||
|
|
||||||
else:
|
|
||||||
|
|
||||||
url = reverse(self.url_name_add, kwargs=self.url_add_kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
client.force_login(self.different_organization_user)
|
|
||||||
response = client.post(url, data=self.add_data)
|
|
||||||
|
|
||||||
assert response.status_code == 403
|
|
||||||
|
|
||||||
|
|
||||||
def test_model_add_permission_view_denied(self):
|
|
||||||
""" Check correct permission for add
|
|
||||||
|
|
||||||
Attempt to add a user with view permission
|
|
||||||
"""
|
|
||||||
|
|
||||||
client = Client()
|
|
||||||
|
|
||||||
if self.app_namespace:
|
|
||||||
|
|
||||||
url = reverse(self.app_namespace + ':' + self.url_name_add, kwargs=self.url_add_kwargs)
|
|
||||||
|
|
||||||
else:
|
|
||||||
|
|
||||||
url = reverse(self.url_name_add, kwargs=self.url_add_kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
client.force_login(self.view_user)
|
|
||||||
response = client.post(url, data=self.add_data)
|
|
||||||
|
|
||||||
assert response.status_code == 403
|
|
||||||
|
|
||||||
|
|
||||||
def test_model_add_has_permission(self):
|
|
||||||
""" Check correct permission for add
|
|
||||||
|
|
||||||
Attempt to add as user with permission
|
|
||||||
"""
|
|
||||||
|
|
||||||
client = Client()
|
|
||||||
|
|
||||||
if self.app_namespace:
|
|
||||||
|
|
||||||
url = reverse(self.app_namespace + ':' + self.url_name_add, kwargs=self.url_add_kwargs)
|
|
||||||
|
|
||||||
else:
|
|
||||||
|
|
||||||
url = reverse(self.url_name_add, kwargs=self.url_add_kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
client.force_login(self.add_user)
|
|
||||||
response = client.post(url, data=self.add_data)
|
|
||||||
|
|
||||||
assert response.status_code == 200
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ModelPermissionsChange:
|
|
||||||
""" Tests for checking model change permissions """
|
|
||||||
|
|
||||||
app_namespace: str = None
|
|
||||||
|
|
||||||
url_name_change: str
|
|
||||||
|
|
||||||
url_change_kwargs: dict = None
|
|
||||||
|
|
||||||
change_data: dict = None
|
|
||||||
|
|
||||||
|
|
||||||
def test_model_change_user_anon_denied(self):
|
|
||||||
""" Check correct permission for change
|
|
||||||
|
|
||||||
Attempt to change as anon
|
|
||||||
"""
|
|
||||||
|
|
||||||
client = Client()
|
|
||||||
url = reverse(self.app_namespace + ':' + self.url_name_change, kwargs=self.url_change_kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
response = client.patch(url, data=self.change_data)
|
|
||||||
|
|
||||||
assert response.status_code == 302 and response.url.startswith('/account/login')
|
|
||||||
|
|
||||||
|
|
||||||
def test_model_change_no_permission_denied(self):
|
|
||||||
""" Ensure permission view cant make change
|
|
||||||
|
|
||||||
Attempt to make change as user without permissions
|
|
||||||
"""
|
|
||||||
|
|
||||||
client = Client()
|
|
||||||
url = reverse(self.app_namespace + ':' + self.url_name_change, kwargs=self.url_change_kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
client.force_login(self.no_permissions_user)
|
|
||||||
response = client.post(url, data=self.change_data)
|
|
||||||
|
|
||||||
assert response.status_code == 403
|
|
||||||
|
|
||||||
|
|
||||||
def test_model_change_different_organization_denied(self):
|
|
||||||
""" Ensure permission view cant make change
|
|
||||||
|
|
||||||
Attempt to make change as user from different organization
|
|
||||||
"""
|
|
||||||
|
|
||||||
client = Client()
|
|
||||||
url = reverse(self.app_namespace + ':' + self.url_name_change, kwargs=self.url_change_kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
client.force_login(self.different_organization_user)
|
|
||||||
response = client.post(url, data=self.change_data)
|
|
||||||
|
|
||||||
assert response.status_code == 403
|
|
||||||
|
|
||||||
|
|
||||||
def test_model_change_permission_view_denied(self):
|
|
||||||
""" Ensure permission view cant make change
|
|
||||||
|
|
||||||
Attempt to make change as user with view permission
|
|
||||||
"""
|
|
||||||
|
|
||||||
client = Client()
|
|
||||||
url = reverse(self.app_namespace + ':' + self.url_name_change, kwargs=self.url_change_kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
client.force_login(self.view_user)
|
|
||||||
response = client.post(url, data=self.change_data)
|
|
||||||
|
|
||||||
assert response.status_code == 403
|
|
||||||
|
|
||||||
|
|
||||||
def test_model_change_permission_add_denied(self):
|
|
||||||
""" Ensure permission view cant make change
|
|
||||||
|
|
||||||
Attempt to make change as user with add permission
|
|
||||||
"""
|
|
||||||
|
|
||||||
client = Client()
|
|
||||||
url = reverse(self.app_namespace + ':' + self.url_name_change, kwargs=self.url_change_kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
client.force_login(self.add_user)
|
|
||||||
response = client.post(url, data=self.change_data)
|
|
||||||
|
|
||||||
assert response.status_code == 403
|
|
||||||
|
|
||||||
|
|
||||||
def test_model_change_has_permission(self):
|
|
||||||
""" Check correct permission for change
|
|
||||||
|
|
||||||
Make change with user who has change permission
|
|
||||||
"""
|
|
||||||
|
|
||||||
client = Client()
|
|
||||||
url = reverse(self.app_namespace + ':' + self.url_name_change, kwargs=self.url_change_kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
client.force_login(self.change_user)
|
|
||||||
response = client.post(url, data=self.change_data)
|
|
||||||
|
|
||||||
assert response.status_code == 200
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ModelPermissionsDelete:
|
|
||||||
""" Tests for checking model delete permissions """
|
|
||||||
|
|
||||||
app_namespace: str = None
|
|
||||||
|
|
||||||
url_name_delete: str
|
|
||||||
|
|
||||||
url_delete_kwargs: dict = None
|
|
||||||
|
|
||||||
url_delete_response: str
|
|
||||||
|
|
||||||
delete_data: dict = None
|
|
||||||
|
|
||||||
def test_model_delete_user_anon_denied(self):
|
|
||||||
""" Check correct permission for delete
|
|
||||||
|
|
||||||
Attempt to delete item as anon user
|
|
||||||
"""
|
|
||||||
|
|
||||||
client = Client()
|
|
||||||
url = reverse(self.app_namespace + ':' + self.url_name_delete, kwargs=self.url_delete_kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
response = client.delete(url, data=self.delete_data)
|
|
||||||
|
|
||||||
assert response.status_code == 302 and response.url.startswith('/account/login')
|
|
||||||
|
|
||||||
|
|
||||||
def test_model_delete_no_permission_denied(self):
|
|
||||||
""" Check correct permission for delete
|
|
||||||
|
|
||||||
Attempt to delete as user with no permissons
|
|
||||||
"""
|
|
||||||
|
|
||||||
client = Client()
|
|
||||||
url = reverse(self.app_namespace + ':' + self.url_name_delete, kwargs=self.url_delete_kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
client.force_login(self.no_permissions_user)
|
|
||||||
response = client.delete(url, data=self.delete_data)
|
|
||||||
|
|
||||||
assert response.status_code == 403
|
|
||||||
|
|
||||||
|
|
||||||
def test_model_delete_different_organization_denied(self):
|
|
||||||
""" Check correct permission for delete
|
|
||||||
|
|
||||||
Attempt to delete as user from different organization
|
|
||||||
"""
|
|
||||||
|
|
||||||
client = Client()
|
|
||||||
url = reverse(self.app_namespace + ':' + self.url_name_delete, kwargs=self.url_delete_kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
client.force_login(self.different_organization_user)
|
|
||||||
response = client.delete(url, data=self.delete_data)
|
|
||||||
|
|
||||||
assert response.status_code == 403
|
|
||||||
|
|
||||||
|
|
||||||
def test_model_delete_permission_view_denied(self):
|
|
||||||
""" Check correct permission for delete
|
|
||||||
|
|
||||||
Attempt to delete as user with veiw permission only
|
|
||||||
"""
|
|
||||||
|
|
||||||
client = Client()
|
|
||||||
url = reverse(self.app_namespace + ':' + self.url_name_delete, kwargs=self.url_delete_kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
client.force_login(self.view_user)
|
|
||||||
response = client.delete(url, data=self.delete_data)
|
|
||||||
|
|
||||||
assert response.status_code == 403
|
|
||||||
|
|
||||||
|
|
||||||
def test_model_delete_permission_add_denied(self):
|
|
||||||
""" Check correct permission for delete
|
|
||||||
|
|
||||||
Attempt to delete as user with add permission only
|
|
||||||
"""
|
|
||||||
|
|
||||||
client = Client()
|
|
||||||
url = reverse(self.app_namespace + ':' + self.url_name_delete, kwargs=self.url_delete_kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
client.force_login(self.add_user)
|
|
||||||
response = client.delete(url, data=self.delete_data)
|
|
||||||
|
|
||||||
assert response.status_code == 403
|
|
||||||
|
|
||||||
|
|
||||||
def test_model_delete_permission_change_denied(self):
|
|
||||||
""" Check correct permission for delete
|
|
||||||
|
|
||||||
Attempt to delete as user with change permission only
|
|
||||||
"""
|
|
||||||
|
|
||||||
client = Client()
|
|
||||||
url = reverse(self.app_namespace + ':' + self.url_name_delete, kwargs=self.url_delete_kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
client.force_login(self.change_user)
|
|
||||||
response = client.delete(url, data=self.delete_data)
|
|
||||||
|
|
||||||
assert response.status_code == 403
|
|
||||||
|
|
||||||
|
|
||||||
def test_model_delete_has_permission(self):
|
|
||||||
""" Check correct permission for delete
|
|
||||||
|
|
||||||
Delete item as user with delete permission
|
|
||||||
"""
|
|
||||||
|
|
||||||
client = Client()
|
|
||||||
url = reverse(self.app_namespace + ':' + self.url_name_delete, kwargs=self.url_delete_kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
client.force_login(self.delete_user)
|
|
||||||
response = client.delete(url, data=self.delete_data)
|
|
||||||
|
|
||||||
assert response.status_code == 302 and response.url == self.url_delete_response
|
|
||||||
|
|
||||||
|
|
||||||
class ModelPermissions(
|
|
||||||
ModelPermissionsView,
|
|
||||||
ModelPermissionsAdd,
|
|
||||||
ModelPermissionsChange,
|
|
||||||
ModelPermissionsDelete
|
|
||||||
):
|
|
||||||
""" Tests for checking model permissions """
|
|
||||||
|
|
||||||
app_namespace: str = None
|
|
@ -1,62 +0,0 @@
|
|||||||
from centurion.tests.abstract.views import AddView, ChangeView, DeleteView, DisplayView, IndexView
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ModelAdd(
|
|
||||||
AddView
|
|
||||||
):
|
|
||||||
""" Unit Tests for Model Add """
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ModelChange(
|
|
||||||
ChangeView
|
|
||||||
):
|
|
||||||
""" Unit Tests for Model Change """
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ModelDelete(
|
|
||||||
DeleteView
|
|
||||||
):
|
|
||||||
""" Unit Tests for Model delete """
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ModelDisplay(
|
|
||||||
DisplayView
|
|
||||||
):
|
|
||||||
""" Unit Tests for Model display """
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ModelIndex(
|
|
||||||
IndexView
|
|
||||||
):
|
|
||||||
""" Unit Tests for Model index """
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ModelCommon(
|
|
||||||
ModelAdd,
|
|
||||||
ModelChange,
|
|
||||||
ModelDelete,
|
|
||||||
ModelDisplay
|
|
||||||
):
|
|
||||||
""" Unit Tests for all models """
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PrimaryModel(
|
|
||||||
ModelCommon,
|
|
||||||
ModelIndex
|
|
||||||
):
|
|
||||||
""" Tests for Primary Models
|
|
||||||
|
|
||||||
A Primary model is a model that is deemed a model that has the following views:
|
|
||||||
- Add
|
|
||||||
- Change
|
|
||||||
- Delete
|
|
||||||
- Display
|
|
||||||
- Index
|
|
||||||
"""
|
|
@ -1,626 +0,0 @@
|
|||||||
import inspect
|
|
||||||
import pytest
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class AddView:
|
|
||||||
""" Testing of Display view """
|
|
||||||
|
|
||||||
add_module: str = None
|
|
||||||
""" Full module path to test """
|
|
||||||
|
|
||||||
add_view: str = None
|
|
||||||
""" View Class name to test """
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_add_attribute_not_exists_fields(self):
|
|
||||||
""" Attribute does not exists test
|
|
||||||
|
|
||||||
Ensure that `fields` attribute is not defined as the expectation is that a form will be used.
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.add_module, fromlist=[self.add_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.add_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.add_view)
|
|
||||||
|
|
||||||
assert viewclass.fields is None
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_add_attribute_exists_form_class(self):
|
|
||||||
""" Attribute exists test
|
|
||||||
|
|
||||||
Ensure that `form_class` attribute is defined as it's required.
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.add_module, fromlist=[self.add_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.add_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.add_view)
|
|
||||||
|
|
||||||
assert hasattr(viewclass, 'form_class')
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_add_attribute_type_form_class(self):
|
|
||||||
""" Attribute Type Test
|
|
||||||
|
|
||||||
Ensure that `form_class` attribute is a class.
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.add_module, fromlist=[self.add_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.add_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.add_view)
|
|
||||||
|
|
||||||
assert inspect.isclass(viewclass.form_class)
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_add_attribute_exists_model(self):
|
|
||||||
""" Attribute exists test
|
|
||||||
|
|
||||||
Ensure that `model` attribute is defined as it's required .
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.add_module, fromlist=[self.add_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.add_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.add_view)
|
|
||||||
|
|
||||||
assert hasattr(viewclass, 'model')
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_add_attribute_exists_permission_required(self):
|
|
||||||
""" Attribute exists test
|
|
||||||
|
|
||||||
Ensure that `permission_required` attribute is defined as it's required.
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.add_module, fromlist=[self.add_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.add_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.add_view)
|
|
||||||
|
|
||||||
assert hasattr(viewclass, 'permission_required')
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_add_attribute_type_permission_required(self):
|
|
||||||
""" Attribute Type Test
|
|
||||||
|
|
||||||
Ensure that `permission_required` attribute is a list
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.add_module, fromlist=[self.add_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.add_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.add_view)
|
|
||||||
|
|
||||||
assert type(viewclass.permission_required) is list
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_add_attribute_exists_template_name(self):
|
|
||||||
""" Attribute exists test
|
|
||||||
|
|
||||||
Ensure that `template_name` attribute is defined as it's required.
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.add_module, fromlist=[self.add_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.add_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.add_view)
|
|
||||||
|
|
||||||
assert hasattr(viewclass, 'template_name')
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_add_attribute_type_template_name(self):
|
|
||||||
""" Attribute Type Test
|
|
||||||
|
|
||||||
Ensure that `template_name` attribute is a string.
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.add_module, fromlist=[self.add_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.add_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.add_view)
|
|
||||||
|
|
||||||
assert type(viewclass.template_name) is str
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_add_function_get_initial_exists(self):
|
|
||||||
"""Ensure that get_initial exists
|
|
||||||
|
|
||||||
Field `get_initial` must be defined as the base class is used for setup.
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.add_module, fromlist=[self.add_view])
|
|
||||||
|
|
||||||
view_class = getattr(module, 'Add')
|
|
||||||
|
|
||||||
assert hasattr(view_class, 'get_initial')
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_add_function_get_initial_callable(self):
|
|
||||||
"""Ensure that get_initial is a function
|
|
||||||
|
|
||||||
Field `get_initial` must be callable as it's used for setup.
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.add_module, fromlist=[self.add_view])
|
|
||||||
|
|
||||||
view_class = getattr(module, 'Add')
|
|
||||||
|
|
||||||
func = getattr(view_class, 'get_initial')
|
|
||||||
|
|
||||||
assert callable(func)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ChangeView:
|
|
||||||
""" Testing of Display view """
|
|
||||||
|
|
||||||
change_module: str = None
|
|
||||||
""" Full module path to test """
|
|
||||||
|
|
||||||
change_view: str = None
|
|
||||||
""" Change Class name to test """
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_change_attribute_not_exists_fields(self):
|
|
||||||
""" Attribute does not exists test
|
|
||||||
|
|
||||||
Ensure that `fields` attribute is not defined as the expectation is that a form will be used.
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.change_module, fromlist=[self.change_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.change_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.change_view)
|
|
||||||
|
|
||||||
assert viewclass.fields is None
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_change_attribute_exists_form_class(self):
|
|
||||||
""" Attribute exists test
|
|
||||||
|
|
||||||
Ensure that `form_class` attribute is defined as it's required.
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.change_module, fromlist=[self.change_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.change_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.change_view)
|
|
||||||
|
|
||||||
assert hasattr(viewclass, 'form_class')
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_change_attribute_type_form_class(self):
|
|
||||||
""" Attribute Type Test
|
|
||||||
|
|
||||||
Ensure that `form_class` attribute is a string.
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.change_module, fromlist=[self.change_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.change_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.change_view)
|
|
||||||
|
|
||||||
assert inspect.isclass(viewclass.form_class)
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_change_attribute_exists_model(self):
|
|
||||||
""" Attribute exists test
|
|
||||||
|
|
||||||
Ensure that `model` attribute is defined as it's required .
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.change_module, fromlist=[self.change_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.change_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.change_view)
|
|
||||||
|
|
||||||
assert hasattr(viewclass, 'model')
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_change_attribute_exists_permission_required(self):
|
|
||||||
""" Attribute exists test
|
|
||||||
|
|
||||||
Ensure that `permission_required` attribute is defined as it's required.
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.change_module, fromlist=[self.change_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.change_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.change_view)
|
|
||||||
|
|
||||||
assert hasattr(viewclass, 'permission_required')
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_change_attribute_type_permission_required(self):
|
|
||||||
""" Attribute Type Test
|
|
||||||
|
|
||||||
Ensure that `permission_required` attribute is a list
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.change_module, fromlist=[self.change_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.change_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.change_view)
|
|
||||||
|
|
||||||
assert type(viewclass.permission_required) is list
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_change_attribute_exists_template_name(self):
|
|
||||||
""" Attribute exists test
|
|
||||||
|
|
||||||
Ensure that `template_name` attribute is defined as it's required.
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.change_module, fromlist=[self.change_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.change_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.change_view)
|
|
||||||
|
|
||||||
assert hasattr(viewclass, 'template_name')
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_change_attribute_type_template_name(self):
|
|
||||||
""" Attribute Type Test
|
|
||||||
|
|
||||||
Ensure that `template_name` attribute is a string.
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.change_module, fromlist=[self.change_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.change_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.change_view)
|
|
||||||
|
|
||||||
assert type(viewclass.template_name) is str
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class DeleteView:
|
|
||||||
""" Testing of Display view """
|
|
||||||
|
|
||||||
delete_module: str = None
|
|
||||||
""" Full module path to test """
|
|
||||||
|
|
||||||
delete_view: str = None
|
|
||||||
""" Delete Class name to test """
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_delete_attribute_exists_model(self):
|
|
||||||
""" Attribute exists test
|
|
||||||
|
|
||||||
Ensure that `model` attribute is defined as it's required .
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.delete_module, fromlist=[self.delete_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.delete_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.delete_view)
|
|
||||||
|
|
||||||
assert hasattr(viewclass, 'model')
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_delete_attribute_exists_permission_required(self):
|
|
||||||
""" Attribute exists test
|
|
||||||
|
|
||||||
Ensure that `model` attribute is defined as it's required .
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.delete_module, fromlist=[self.delete_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.delete_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.delete_view)
|
|
||||||
|
|
||||||
assert hasattr(viewclass, 'permission_required')
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_delete_attribute_type_permission_required(self):
|
|
||||||
""" Attribute Type Test
|
|
||||||
|
|
||||||
Ensure that `permission_required` attribute is a list
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.delete_module, fromlist=[self.delete_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.delete_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.delete_view)
|
|
||||||
|
|
||||||
assert type(viewclass.permission_required) is list
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_delete_attribute_exists_template_name(self):
|
|
||||||
""" Attribute exists test
|
|
||||||
|
|
||||||
Ensure that `template_name` attribute is defined as it's required.
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.delete_module, fromlist=[self.delete_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.delete_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.delete_view)
|
|
||||||
|
|
||||||
assert hasattr(viewclass, 'template_name')
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_delete_attribute_type_template_name(self):
|
|
||||||
""" Attribute Type Test
|
|
||||||
|
|
||||||
Ensure that `template_name` attribute is a string.
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.delete_module, fromlist=[self.delete_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.delete_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.delete_view)
|
|
||||||
|
|
||||||
assert type(viewclass.template_name) is str
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class DisplayView:
|
|
||||||
""" Testing of Display view """
|
|
||||||
|
|
||||||
display_module: str = None
|
|
||||||
""" Full module path to test """
|
|
||||||
|
|
||||||
display_view: str = None
|
|
||||||
""" Change Class name to test """
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_display_attribute_exists_model(self):
|
|
||||||
""" Attribute exists test
|
|
||||||
|
|
||||||
Ensure that `model` attribute is defined as it's required .
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.display_module, fromlist=[self.display_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.display_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.display_view)
|
|
||||||
|
|
||||||
assert hasattr(viewclass, 'model')
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_display_attribute_exists_permission_required(self):
|
|
||||||
""" Attribute exists test
|
|
||||||
|
|
||||||
Ensure that `permission_required` attribute is defined as it's required.
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.display_module, fromlist=[self.display_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.display_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.display_view)
|
|
||||||
|
|
||||||
assert hasattr(viewclass, 'permission_required')
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_display_attribute_type_permission_required(self):
|
|
||||||
""" Attribute Type Test
|
|
||||||
|
|
||||||
Ensure that `permission_required` attribute is a list
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.display_module, fromlist=[self.display_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.display_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.display_view)
|
|
||||||
|
|
||||||
assert type(viewclass.permission_required) is list
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_display_attribute_exists_template_name(self):
|
|
||||||
""" Attribute exists test
|
|
||||||
|
|
||||||
Ensure that `template_name` attribute is defined as it's required.
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.display_module, fromlist=[self.display_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.display_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.display_view)
|
|
||||||
|
|
||||||
assert hasattr(viewclass, 'template_name')
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_display_attribute_type_template_name(self):
|
|
||||||
""" Attribute Type Test
|
|
||||||
|
|
||||||
Ensure that `template_name` attribute is a string.
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.display_module, fromlist=[self.display_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.display_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.display_view)
|
|
||||||
|
|
||||||
assert type(viewclass.template_name) is str
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class IndexView:
|
|
||||||
""" Testing of Display view """
|
|
||||||
|
|
||||||
index_module: str = None
|
|
||||||
""" Full module path to test """
|
|
||||||
|
|
||||||
index_view: str = None
|
|
||||||
""" Index Class name to test """
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_index_attribute_exists_model(self):
|
|
||||||
""" Attribute exists test
|
|
||||||
|
|
||||||
Ensure that `model` attribute is defined as it's required .
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.index_module, fromlist=[self.index_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.index_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.index_view)
|
|
||||||
|
|
||||||
assert hasattr(viewclass, 'model')
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_index_attribute_exists_permission_required(self):
|
|
||||||
""" Attribute exists test
|
|
||||||
|
|
||||||
Ensure that `model` attribute is defined as it's required .
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.index_module, fromlist=[self.index_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.index_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.index_view)
|
|
||||||
|
|
||||||
assert hasattr(viewclass, 'permission_required')
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_index_attribute_type_permission_required(self):
|
|
||||||
""" Attribute Type Test
|
|
||||||
|
|
||||||
Ensure that `permission_required` attribute is a list
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.index_module, fromlist=[self.index_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.index_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.index_view)
|
|
||||||
|
|
||||||
assert type(viewclass.permission_required) is list
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_index_attribute_exists_template_name(self):
|
|
||||||
""" Attribute exists test
|
|
||||||
|
|
||||||
Ensure that `template_name` attribute is defined as it's required.
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.index_module, fromlist=[self.index_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.index_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.index_view)
|
|
||||||
|
|
||||||
assert hasattr(viewclass, 'template_name')
|
|
||||||
|
|
||||||
|
|
||||||
def test_view_index_attribute_type_template_name(self):
|
|
||||||
""" Attribute Type Test
|
|
||||||
|
|
||||||
Ensure that `template_name` attribute is a string.
|
|
||||||
"""
|
|
||||||
|
|
||||||
module = __import__(self.index_module, fromlist=[self.index_view])
|
|
||||||
|
|
||||||
assert hasattr(module, self.index_view)
|
|
||||||
|
|
||||||
viewclass = getattr(module, self.index_view)
|
|
||||||
|
|
||||||
assert type(viewclass.template_name) is str
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class AllViews(
|
|
||||||
AddView,
|
|
||||||
ChangeView,
|
|
||||||
DeleteView,
|
|
||||||
DisplayView,
|
|
||||||
IndexView
|
|
||||||
):
|
|
||||||
""" Abstract test class containing ALL view tests """
|
|
||||||
|
|
||||||
add_module: str = None
|
|
||||||
""" Full module path to test """
|
|
||||||
|
|
||||||
add_view: str = None
|
|
||||||
""" View Class name to test """
|
|
||||||
|
|
||||||
change_module: str = None
|
|
||||||
""" Full module path to test """
|
|
||||||
|
|
||||||
change_view: str = None
|
|
||||||
""" Change Class name to test """
|
|
||||||
|
|
||||||
delete_module: str = None
|
|
||||||
""" Full module path to test """
|
|
||||||
|
|
||||||
delete_view: str = None
|
|
||||||
""" Delete Class name to test """
|
|
||||||
|
|
||||||
display_module: str = None
|
|
||||||
""" Full module path to test """
|
|
||||||
|
|
||||||
display_view: str = None
|
|
||||||
""" Change Class name to test """
|
|
||||||
|
|
||||||
index_module: str = None
|
|
||||||
""" Full module path to test """
|
|
||||||
|
|
||||||
index_view: str = None
|
|
||||||
""" Index Class name to test """
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip(reason='write test')
|
|
||||||
def test_view_index_attribute_missing_permission_required(self):
|
|
||||||
""" Attribute missing Test
|
|
||||||
|
|
||||||
Ensure that `permission_required` attribute is not defined within the view.
|
|
||||||
|
|
||||||
this can be done by mocking the inherited class with the `permission_required` attribute
|
|
||||||
set to a value that if it changed would be considered defined in the created view.
|
|
||||||
|
|
||||||
## Why?
|
|
||||||
|
|
||||||
This attribute can be dynamically added based of of the view name along with attributes
|
|
||||||
`model._meta.model_name` and `str(__class__.__name__).lower()`.
|
|
||||||
|
|
||||||
Additional test:
|
|
||||||
- ensure that the attribute does get automagically created.
|
|
||||||
- ensure that the classes name is one of add, change, delete, display or index.
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip(reason='write test')
|
|
||||||
def test_view_index_attribute_missing_template_name(self):
|
|
||||||
""" Attribute missing Test
|
|
||||||
|
|
||||||
Ensure that `template_name` attribute is not defined within the view if the value
|
|
||||||
is `form.html.j2`
|
|
||||||
|
|
||||||
this valuse is already defined in the base form
|
|
||||||
"""
|
|
Reference in New Issue
Block a user