test: Add view must have function get_initial

organization is set here for tenancy objects

ref: #252
This commit is contained in:
2024-08-31 16:02:58 +09:30
parent fe353904d8
commit d1b9283a9a
6 changed files with 66 additions and 30 deletions

View File

@ -134,6 +134,34 @@ class AddView:
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 """
@ -524,6 +552,9 @@ class IndexView:
class AllViews(
AddView,
ChangeView,

View File

@ -14,16 +14,16 @@ class ConfigManagementViews(
):
add_module = 'config_management.views.groups.groups'
add_view = 'GroupAdd'
add_view = 'Add'
change_module = add_module
change_view = 'GroupView'
change_view = 'View'
delete_module = add_module
delete_view = 'GroupDelete'
delete_view = 'Delete'
display_module = add_module
display_view = 'GroupView'
display_view = 'View'
index_module = add_module
index_view = 'GroupIndexView'
index_view = 'Index'

View File

@ -16,13 +16,13 @@ class ConfigGroupsSoftwareViews(
):
add_module = 'config_management.views.groups.software'
add_view = 'GroupSoftwareAdd'
add_view = 'Add'
change_module = add_module
change_view = 'GroupSoftwareChange'
change_view = 'Change'
delete_module = add_module
delete_view = 'GroupSoftwareDelete'
delete_view = 'Delete'
# display_module = add_module
# display_view = 'GroupView'

View File

@ -1,22 +1,25 @@
from django.urls import path
from config_management.views.groups.groups import GroupIndexView, GroupAdd, GroupChange, GroupDelete, GroupView, GroupHostAdd, GroupHostDelete
from config_management.views.groups.software import GroupSoftwareAdd, GroupSoftwareChange, GroupSoftwareDelete
from config_management.views.groups import groups
from config_management.views.groups.groups import GroupHostAdd, GroupHostDelete
from config_management.views.groups import software
# from config_management.views.groups.software import GroupSoftwareAdd, GroupSoftwareChange, GroupSoftwareDelete
app_name = "Config Management"
urlpatterns = [
path('group', GroupIndexView.as_view(), name='Groups'),
path('group/add', GroupAdd.as_view(), name='_group_add'),
path('group/<int:pk>', GroupView.as_view(), name='_group_view'),
path('group/<int:pk>/edit', GroupChange.as_view(), name='_group_change'),
path('group', groups.Index.as_view(), name='Groups'),
path('group/add', groups.Add.as_view(), name='_group_add'),
path('group/<int:pk>', groups.View.as_view(), name='_group_view'),
path('group/<int:pk>/edit', groups.Change.as_view(), name='_group_change'),
path('group/<int:pk>/child', GroupAdd.as_view(), name='_group_add_child'),
path('group/<int:pk>/delete', GroupDelete.as_view(), name='_group_delete'),
path('group/<int:pk>/child', groups.Add.as_view(), name='_group_add_child'),
path('group/<int:pk>/delete', groups.Delete.as_view(), name='_group_delete'),
path("group/<int:pk>/software/add", GroupSoftwareAdd.as_view(), name="_group_software_add"),
path("group/<int:group_id>/software/<int:pk>", GroupSoftwareChange.as_view(), name="_group_software_change"),
path("group/<int:group_id>/software/<int:pk>/delete", GroupSoftwareDelete.as_view(), name="_group_software_delete"),
path("group/<int:pk>/software/add", software.Add.as_view(), name="_group_software_add"),
path("group/<int:group_id>/software/<int:pk>", software.Change.as_view(), name="_group_software_change"),
path("group/<int:group_id>/software/<int:pk>/delete", software.Delete.as_view(), name="_group_software_delete"),
path('group/<int:pk>/host', GroupHostAdd.as_view(), name='_group_add_host'),
path('group/<int:group_id>/host/<int:pk>/delete', GroupHostDelete.as_view(), name='_group_delete_host'),

View File

@ -18,7 +18,7 @@ from config_management.models.groups import ConfigGroups, ConfigGroupHosts, Conf
class GroupIndexView(IndexView):
class Index(IndexView):
context_object_name = "groups"
@ -50,7 +50,7 @@ class GroupIndexView(IndexView):
class GroupAdd(AddView):
class Add(AddView):
organization_field = 'organization'
@ -67,9 +67,11 @@ class GroupAdd(AddView):
def get_initial(self):
initial: dict = {
'organization': UserSettings.objects.get(user = self.request.user).default_organization
}
# initial: dict = {
# 'organization': UserSettings.objects.get(user = self.request.user).default_organization
# }
initial = super().get_initial()
if 'pk' in self.kwargs:
@ -102,7 +104,7 @@ class GroupAdd(AddView):
class GroupChange(ChangeView):
class Change(ChangeView):
context_object_name = "group"
@ -132,7 +134,7 @@ class GroupChange(ChangeView):
class GroupView(ChangeView):
class View(ChangeView):
context_object_name = "group"
@ -215,7 +217,7 @@ class GroupView(ChangeView):
class GroupDelete(DeleteView):
class Delete(DeleteView):
model = ConfigGroups

View File

@ -9,7 +9,7 @@ from config_management.models.groups import ConfigGroups, ConfigGroupSoftware
from core.views.common import AddView, ChangeView, DeleteView
class GroupSoftwareAdd(AddView):
class Add(AddView):
form_class = SoftwareAdd
@ -65,7 +65,7 @@ class GroupSoftwareAdd(AddView):
class GroupSoftwareChange(ChangeView):
class Change(ChangeView):
form_class = SoftwareUpdate
@ -104,7 +104,7 @@ class GroupSoftwareChange(ChangeView):
class GroupSoftwareDelete(DeleteView):
class Delete(DeleteView):
model = ConfigGroupSoftware