147 lines
4.7 KiB
Python
147 lines
4.7 KiB
Python
"""
|
|
Tests for Compliance & Governance module
|
|
"""
|
|
from django.test import TestCase
|
|
from django.contrib.auth import get_user_model
|
|
from django.utils import timezone
|
|
from datetime import date, timedelta
|
|
|
|
from .models import (
|
|
RegulatoryFramework,
|
|
ComplianceRequirement,
|
|
EvidenceCollection,
|
|
RetentionPolicy,
|
|
ExportRequest,
|
|
LegalHold,
|
|
)
|
|
|
|
User = get_user_model()
|
|
|
|
|
|
class RegulatoryFrameworkModelTest(TestCase):
|
|
"""Test cases for RegulatoryFramework model"""
|
|
|
|
def setUp(self):
|
|
self.user = User.objects.create_user(
|
|
username='testuser',
|
|
email='test@example.com',
|
|
password='testpass123'
|
|
)
|
|
|
|
def test_create_framework(self):
|
|
"""Test creating a regulatory framework"""
|
|
framework = RegulatoryFramework.objects.create(
|
|
name='Test GDPR Framework',
|
|
framework_type='GDPR',
|
|
version='1.0',
|
|
description='Test framework',
|
|
applicable_regions=['EU', 'UK'],
|
|
industry_sectors=['Technology'],
|
|
is_active=True,
|
|
effective_date=date.today(),
|
|
created_by=self.user
|
|
)
|
|
|
|
self.assertEqual(framework.name, 'Test GDPR Framework')
|
|
self.assertEqual(framework.framework_type, 'GDPR')
|
|
self.assertTrue(framework.is_active)
|
|
self.assertEqual(framework.created_by, self.user)
|
|
|
|
def test_framework_str_representation(self):
|
|
"""Test string representation of framework"""
|
|
framework = RegulatoryFramework.objects.create(
|
|
name='Test Framework',
|
|
framework_type='GDPR',
|
|
version='1.0',
|
|
description='Test',
|
|
is_active=True,
|
|
effective_date=date.today()
|
|
)
|
|
|
|
self.assertEqual(str(framework), 'Test Framework v1.0')
|
|
|
|
|
|
class ComplianceRequirementModelTest(TestCase):
|
|
"""Test cases for ComplianceRequirement model"""
|
|
|
|
def setUp(self):
|
|
self.user = User.objects.create_user(
|
|
username='testuser',
|
|
email='test@example.com',
|
|
password='testpass123'
|
|
)
|
|
|
|
self.framework = RegulatoryFramework.objects.create(
|
|
name='Test Framework',
|
|
framework_type='GDPR',
|
|
version='1.0',
|
|
description='Test',
|
|
is_active=True,
|
|
effective_date=date.today()
|
|
)
|
|
|
|
def test_create_requirement(self):
|
|
"""Test creating a compliance requirement"""
|
|
requirement = ComplianceRequirement.objects.create(
|
|
framework=self.framework,
|
|
requirement_id='GDPR-001',
|
|
title='Test Requirement',
|
|
description='Test requirement description',
|
|
requirement_type='TECHNICAL',
|
|
priority='HIGH',
|
|
responsible_team='Security Team',
|
|
assigned_to=self.user
|
|
)
|
|
|
|
self.assertEqual(requirement.requirement_id, 'GDPR-001')
|
|
self.assertEqual(requirement.framework, self.framework)
|
|
self.assertEqual(requirement.assigned_to, self.user)
|
|
self.assertEqual(requirement.compliance_status, 'NOT_ASSESSED')
|
|
|
|
|
|
class RetentionPolicyModelTest(TestCase):
|
|
"""Test cases for RetentionPolicy model"""
|
|
|
|
def setUp(self):
|
|
self.user = User.objects.create_user(
|
|
username='testuser',
|
|
email='test@example.com',
|
|
password='testpass123'
|
|
)
|
|
|
|
def test_create_retention_policy(self):
|
|
"""Test creating a retention policy"""
|
|
policy = RetentionPolicy.objects.create(
|
|
name='Test Retention Policy',
|
|
description='Test policy description',
|
|
policy_type='INCIDENT_DATA',
|
|
retention_period=7,
|
|
retention_unit='YEARS',
|
|
auto_archive=True,
|
|
auto_delete=False,
|
|
is_active=True,
|
|
effective_date=date.today(),
|
|
created_by=self.user
|
|
)
|
|
|
|
self.assertEqual(policy.name, 'Test Retention Policy')
|
|
self.assertEqual(policy.retention_period, 7)
|
|
self.assertEqual(policy.retention_unit, 'YEARS')
|
|
self.assertTrue(policy.auto_archive)
|
|
self.assertFalse(policy.auto_delete)
|
|
|
|
def test_get_retention_duration(self):
|
|
"""Test getting retention duration as timedelta"""
|
|
policy = RetentionPolicy.objects.create(
|
|
name='Test Policy',
|
|
description='Test',
|
|
policy_type='INCIDENT_DATA',
|
|
retention_period=2,
|
|
retention_unit='YEARS',
|
|
is_active=True,
|
|
effective_date=date.today()
|
|
)
|
|
|
|
duration = policy.get_retention_duration()
|
|
expected_days = 2 * 365 # 2 years
|
|
self.assertEqual(duration.days, expected_days) |