test(config_management): history save tests for config groups software
!22 closes #43
This commit is contained in:
@ -3,102 +3,25 @@ import pytest
|
||||
import unittest
|
||||
import requests
|
||||
|
||||
from django.test import TestCase, Client
|
||||
from django.test import TestCase
|
||||
|
||||
from access.models import Organization
|
||||
|
||||
from core.models.history import History
|
||||
|
||||
from config_management.models.groups import ConfigGroups
|
||||
from config_management.models.groups import ConfigGroups, ConfigGroupSoftware
|
||||
|
||||
|
||||
# @pytest.mark.skip(reason="to be written")
|
||||
# def test_history_auth_view():
|
||||
# """ User requires Permission view_history """
|
||||
# pass
|
||||
|
||||
|
||||
# @pytest.mark.skip(reason="to be written")
|
||||
# def test_history_device_create():
|
||||
# """ History row must be added to history table on create """
|
||||
# pass
|
||||
|
||||
|
||||
# @pytest.mark.skip(reason="to be written")
|
||||
# def test_history_device_update():
|
||||
# """ History row must be added to history table on updatej """
|
||||
# pass
|
||||
|
||||
|
||||
# @pytest.mark.skip(reason="to be written")
|
||||
# def test_history_device_delete():
|
||||
# """ History row must be added to history table on delete """
|
||||
# pass
|
||||
|
||||
|
||||
|
||||
# @pytest.mark.skip(reason="to be written")
|
||||
# def test_history_device_operating_system_create():
|
||||
# """ History row must be added to history table on create
|
||||
|
||||
# Must also have populated parent_item_pk and parent_item_class columns
|
||||
# """
|
||||
# pass
|
||||
|
||||
|
||||
# @pytest.mark.skip(reason="to be written")
|
||||
# def test_history_device_operating_system_update():
|
||||
# """ History row must be added to history table on update
|
||||
|
||||
# Must also have populated parent_item_pk and parent_item_class columns
|
||||
# """
|
||||
# pass
|
||||
|
||||
|
||||
# @pytest.mark.skip(reason="to be written")
|
||||
# def test_history_device_operating_system_delete():
|
||||
# """ History row must be added to history table on delete
|
||||
|
||||
# Must also have populated parent_item_pk and parent_item_class columns
|
||||
# """
|
||||
# pass
|
||||
|
||||
|
||||
|
||||
# @pytest.mark.skip(reason="to be written")
|
||||
# def test_history_device_software_create():
|
||||
# """ History row must be added to history table on create
|
||||
|
||||
# Must also have populated parent_item_pk and parent_item_class columns
|
||||
# """
|
||||
# pass
|
||||
|
||||
|
||||
# @pytest.mark.skip(reason="to be written")
|
||||
# def test_history_device_software_update():
|
||||
# """ History row must be added to history table on update
|
||||
|
||||
# Must also have populated parent_item_pk and parent_item_class columns
|
||||
# """
|
||||
# pass
|
||||
|
||||
|
||||
# @pytest.mark.skip(reason="to be written")
|
||||
# def test_history_device_software_delete():
|
||||
# """ History row must be added to history table on delete
|
||||
|
||||
# Must also have populated parent_item_pk and parent_item_class columns
|
||||
# """
|
||||
# pass
|
||||
from itam.models.device import DeviceSoftware
|
||||
from itam.models.software import Software
|
||||
|
||||
|
||||
|
||||
|
||||
class ConfigGroupSoftwareHistory(TestCase):
|
||||
|
||||
model = ConfigGroups
|
||||
model = ConfigGroupSoftware
|
||||
|
||||
model_name = 'configgroups'
|
||||
parent_model = ConfigGroups
|
||||
|
||||
|
||||
@classmethod
|
||||
@ -109,20 +32,32 @@ class ConfigGroupSoftwareHistory(TestCase):
|
||||
|
||||
self.organization = organization
|
||||
|
||||
self.item_create = self.model.objects.create(
|
||||
name = 'test_item_' + self.model_name,
|
||||
self.parent_object = self.parent_model.objects.create(
|
||||
name = 'test_item_' + self.model._meta.model_name,
|
||||
organization = self.organization
|
||||
)
|
||||
|
||||
software = Software.objects.create(
|
||||
name = 'test_item_' + self.model._meta.model_name,
|
||||
organization = self.organization
|
||||
)
|
||||
|
||||
self.item_create = self.model.objects.create(
|
||||
organization = self.organization,
|
||||
config_group = self.parent_object,
|
||||
software = software,
|
||||
action = DeviceSoftware.Actions.INSTALL,
|
||||
)
|
||||
|
||||
|
||||
self.history_create = History.objects.get(
|
||||
action = History.Actions.ADD[0],
|
||||
item_pk = self.item_create.pk,
|
||||
item_class = self.model._meta.model_name,
|
||||
item_class = self.model._meta.model_name
|
||||
)
|
||||
|
||||
self.item_change = self.item_create
|
||||
self.item_change.name = 'test_item_' + self.model_name + '_changed'
|
||||
self.item_change.action = DeviceSoftware.Actions.REMOVE
|
||||
self.item_change.save()
|
||||
|
||||
self.history_change = History.objects.get(
|
||||
@ -131,10 +66,32 @@ class ConfigGroupSoftwareHistory(TestCase):
|
||||
item_class = self.model._meta.model_name,
|
||||
)
|
||||
|
||||
# self.item_delete = self.item_change
|
||||
#
|
||||
software_two = Software.objects.create(
|
||||
name = 'test_item_two_' + self.model._meta.model_name,
|
||||
organization = self.organization
|
||||
)
|
||||
|
||||
# field type testing to be done as part of model testing
|
||||
@pytest.mark.skip(reason="figure out best way to test")
|
||||
def test_device_history_entry_item_add_field_action(self):
|
||||
self.item_delete = self.model.objects.create(
|
||||
organization = self.organization,
|
||||
config_group = self.parent_object,
|
||||
software = software_two,
|
||||
action = DeviceSoftware.Actions.INSTALL,
|
||||
)
|
||||
|
||||
self.deleted_pk = self.item_delete.pk
|
||||
|
||||
self.item_delete.delete()
|
||||
|
||||
self.history_delete = History.objects.get(
|
||||
action = History.Actions.DELETE[0],
|
||||
item_pk = self.deleted_pk,
|
||||
item_class = self.model._meta.model_name,
|
||||
)
|
||||
|
||||
|
||||
def test_configgroup_software_history_entry_item_add_field_action(self):
|
||||
""" Ensure action is "add" for item creation """
|
||||
|
||||
history = self.history_create.__dict__
|
||||
@ -143,9 +100,8 @@ class ConfigGroupSoftwareHistory(TestCase):
|
||||
# assert type(history['action']) is int
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="to be written")
|
||||
@pytest.mark.skip(reason="figure out best way to test")
|
||||
def test_device_history_entry_item_add_field_after(self):
|
||||
def test_configgroup_software_history_entry_item_add_field_after(self):
|
||||
""" Ensure after field contains correct value """
|
||||
|
||||
history = self.history_create.__dict__
|
||||
@ -154,8 +110,7 @@ class ConfigGroupSoftwareHistory(TestCase):
|
||||
# assert type(history['after']) is str
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="figure out best way to test")
|
||||
def test_device_history_entry_item_add_field_before(self):
|
||||
def test_configgroup_software_history_entry_item_add_field_before(self):
|
||||
""" Ensure before field is an empty JSON string for create """
|
||||
|
||||
history = self.history_create.__dict__
|
||||
@ -164,8 +119,7 @@ class ConfigGroupSoftwareHistory(TestCase):
|
||||
# assert type(history['before']) is str
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="figure out best way to test")
|
||||
def test_device_history_entry_item_add_field_item_pk(self):
|
||||
def test_configgroup_software_history_entry_item_add_field_item_pk(self):
|
||||
""" Ensure history entry field item_pk is the created items pk """
|
||||
|
||||
history = self.history_create.__dict__
|
||||
@ -174,8 +128,7 @@ class ConfigGroupSoftwareHistory(TestCase):
|
||||
# assert type(history['item_pk']) is int
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="figure out best way to test")
|
||||
def test_device_history_entry_item_add_field_item_class(self):
|
||||
def test_configgroup_software_history_entry_item_add_field_item_class(self):
|
||||
""" Ensure history entry field item_class is the model name """
|
||||
|
||||
history = self.history_create.__dict__
|
||||
@ -184,6 +137,24 @@ class ConfigGroupSoftwareHistory(TestCase):
|
||||
# assert type(history['item_class']) is str
|
||||
|
||||
|
||||
def test_configgroup_software_history_entry_item_add_field_parent_pk(self):
|
||||
""" Ensure history entry field parent_pk is the created parents pk """
|
||||
|
||||
history = self.history_create.__dict__
|
||||
|
||||
assert history['item_parent_pk'] == self.parent_object.pk
|
||||
# assert type(history['parentpk']) is int
|
||||
|
||||
|
||||
def test_configgroup_software_history_entry_item_add_field_parent_class(self):
|
||||
""" Ensure history entry field parent_class is the model name """
|
||||
|
||||
history = self.history_create.__dict__
|
||||
|
||||
assert history['item_parent_class'] == self.parent_model._meta.model_name
|
||||
# assert type(history['item_class']) is str
|
||||
|
||||
|
||||
|
||||
|
||||
################################## Change ##################################
|
||||
@ -191,9 +162,7 @@ class ConfigGroupSoftwareHistory(TestCase):
|
||||
|
||||
|
||||
|
||||
# field type testing to be done as part of model testing
|
||||
@pytest.mark.skip(reason="figure out best way to test")
|
||||
def test_device_history_entry_item_change_field_action(self):
|
||||
def test_configgroup_software_history_entry_item_change_field_action(self):
|
||||
""" Ensure action is "add" for item creation """
|
||||
|
||||
history = self.history_change.__dict__
|
||||
@ -202,19 +171,17 @@ class ConfigGroupSoftwareHistory(TestCase):
|
||||
# assert type(history['action']) is int
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="figure out best way to test")
|
||||
def test_device_history_entry_item_change_field_after(self):
|
||||
def test_configgroup_software_history_entry_item_change_field_after(self):
|
||||
""" Ensure after field contains correct value """
|
||||
|
||||
history = self.history_change.__dict__
|
||||
|
||||
assert history['after'] == str('{"name": "test_item_' + self.model_name + '_changed"}')
|
||||
assert history['after'] == str('{"action": "' + DeviceSoftware.Actions.REMOVE + '"}')
|
||||
# assert type(history['after']) is str
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="to be written")
|
||||
@pytest.mark.skip(reason="figure out best way to test")
|
||||
def test_device_history_entry_item_change_field_before(self):
|
||||
def test_configgroup_software_history_entry_item_change_field_before(self):
|
||||
""" Ensure before field is an empty JSON string for create """
|
||||
|
||||
history = self.history_change.__dict__
|
||||
@ -223,8 +190,7 @@ class ConfigGroupSoftwareHistory(TestCase):
|
||||
# assert type(history['before']) is str
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="figure out best way to test")
|
||||
def test_device_history_entry_item_change_field_item_pk(self):
|
||||
def test_configgroup_software_history_entry_item_change_field_item_pk(self):
|
||||
""" Ensure history entry field item_pk is the created items pk """
|
||||
|
||||
history = self.history_change.__dict__
|
||||
@ -233,8 +199,7 @@ class ConfigGroupSoftwareHistory(TestCase):
|
||||
# assert type(history['item_pk']) is int
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="figure out best way to test")
|
||||
def test_device_history_entry_item_change_field_item_class(self):
|
||||
def test_configgroup_software_history_entry_item_change_field_item_class(self):
|
||||
""" Ensure history entry field item_class is the model name """
|
||||
|
||||
history = self.history_change.__dict__
|
||||
@ -243,3 +208,100 @@ class ConfigGroupSoftwareHistory(TestCase):
|
||||
# assert type(history['item_class']) is str
|
||||
|
||||
|
||||
def test_configgroup_software_history_entry_item_change_field_parent_pk(self):
|
||||
""" Ensure history entry field parent_pk is the created parent pk """
|
||||
|
||||
history = self.history_change.__dict__
|
||||
|
||||
assert history['item_parent_pk'] == self.parent_object.pk
|
||||
# assert type(history['item_pk']) is int
|
||||
|
||||
|
||||
def test_configgroup_software_history_entry_item_change_field_parent_class(self):
|
||||
""" Ensure history entry field parent_class is the model name """
|
||||
|
||||
history = self.history_change.__dict__
|
||||
|
||||
assert history['item_parent_class'] == self.parent_model._meta.model_name
|
||||
# assert type(history['item_class']) is str
|
||||
|
||||
|
||||
|
||||
|
||||
################################## Delete ##################################
|
||||
|
||||
|
||||
|
||||
|
||||
def test_configgroup_software_history_entry_item_delete_field_action(self):
|
||||
""" Ensure action is "add" for item creation """
|
||||
|
||||
history = self.history_delete.__dict__
|
||||
|
||||
assert history['action'] == int(History.Actions.DELETE[0])
|
||||
# assert type(history['action']) is int
|
||||
|
||||
|
||||
# @pytest.mark.skip(reason="figure out best way to test")
|
||||
def test_configgroup_software_history_entry_item_delete_field_after(self):
|
||||
""" Ensure after field contains correct value """
|
||||
|
||||
history = self.history_delete.__dict__
|
||||
|
||||
assert history['after'] == None
|
||||
# assert type(history['after']) is str
|
||||
|
||||
|
||||
# @pytest.mark.skip(reason="to be written")
|
||||
@pytest.mark.skip(reason="figure out best way to test")
|
||||
def test_configgroup_software_history_entry_item_delete_field_before(self):
|
||||
""" Ensure before field is an empty JSON string for create """
|
||||
|
||||
history = self.history_delete.__dict__
|
||||
|
||||
assert history['before'] == str('{}')
|
||||
# assert type(history['before']) is str
|
||||
|
||||
|
||||
# @pytest.mark.skip(reason="figure out best way to test")
|
||||
def test_configgroup_software_history_entry_item_delete_field_item_pk(self):
|
||||
""" Ensure history entry field item_pk is the created items pk """
|
||||
|
||||
history = self.history_delete.__dict__
|
||||
|
||||
assert history['item_pk'] == self.deleted_pk
|
||||
# assert type(history['item_pk']) is int
|
||||
|
||||
|
||||
# @pytest.mark.skip(reason="figure out best way to test")
|
||||
def test_configgroup_software_history_entry_item_delete_field_item_class(self):
|
||||
""" Ensure history entry field item_class is the model name """
|
||||
|
||||
history = self.history_delete.__dict__
|
||||
|
||||
assert history['item_class'] == self.model._meta.model_name
|
||||
# assert type(history['item_class']) is str
|
||||
|
||||
|
||||
|
||||
# @pytest.mark.skip(reason="figure out best way to test")
|
||||
def test_configgroup_software_history_entry_item_delete_field_parent_pk(self):
|
||||
""" Ensure history entry field item_pk is the created parents pk """
|
||||
|
||||
history = self.history_delete.__dict__
|
||||
|
||||
assert history['item_parent_pk'] == self.parent_object.pk
|
||||
# assert type(history['item_pk']) is int
|
||||
|
||||
|
||||
# @pytest.mark.skip(reason="figure out best way to test")
|
||||
def test_configgroup_software_history_entry_item_delete_field_parent_class(self):
|
||||
""" Ensure history entry field parent_class is the model name """
|
||||
|
||||
history = self.history_delete.__dict__
|
||||
|
||||
assert history['item_parent_class'] == self.parent_model._meta.model_name
|
||||
# assert type(history['item_class']) is str
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user