Backeup configs & cleanup of files and db
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
"""
|
||||
Publishing Tests
|
||||
Phase 5: Sites Renderer & Publishing
|
||||
"""
|
||||
|
||||
@@ -1,139 +0,0 @@
|
||||
"""
|
||||
Tests for Publishing Adapters
|
||||
Phase 6: Site Integration & Multi-Destination Publishing
|
||||
"""
|
||||
from django.test import TestCase
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from igny8_core.auth.models import Account, Site, Sector, User, Plan, Industry, IndustrySector
|
||||
from igny8_core.business.publishing.services.adapters.base_adapter import BaseAdapter
|
||||
from igny8_core.business.publishing.services.adapters.sites_renderer_adapter import SitesRendererAdapter
|
||||
from igny8_core.business.publishing.services.adapters.wordpress_adapter import WordPressAdapter
|
||||
from igny8_core.business.site_building.models import SiteBlueprint
|
||||
|
||||
|
||||
class AdapterPatternTestCase(TestCase):
|
||||
"""Test cases for adapter pattern"""
|
||||
|
||||
def setUp(self):
|
||||
"""Set up test data"""
|
||||
# Create plan first
|
||||
self.plan = Plan.objects.create(
|
||||
name="Test Plan",
|
||||
slug="test-plan",
|
||||
price=0,
|
||||
credits_per_month=1000
|
||||
)
|
||||
|
||||
# Create user first (Account needs owner)
|
||||
self.user = User.objects.create_user(
|
||||
username='testuser',
|
||||
email='test@test.com',
|
||||
password='testpass123',
|
||||
role='owner'
|
||||
)
|
||||
|
||||
# Create account with owner
|
||||
self.account = Account.objects.create(
|
||||
name="Test Account",
|
||||
slug="test-account",
|
||||
plan=self.plan,
|
||||
owner=self.user
|
||||
)
|
||||
|
||||
# Update user to have account
|
||||
self.user.account = self.account
|
||||
self.user.save()
|
||||
|
||||
# Create industry and sector
|
||||
self.industry = Industry.objects.create(
|
||||
name="Test Industry",
|
||||
slug="test-industry"
|
||||
)
|
||||
|
||||
self.industry_sector = IndustrySector.objects.create(
|
||||
industry=self.industry,
|
||||
name="Test Sector",
|
||||
slug="test-sector"
|
||||
)
|
||||
|
||||
self.site = Site.objects.create(
|
||||
account=self.account,
|
||||
name="Test Site",
|
||||
slug="test-site",
|
||||
industry=self.industry
|
||||
)
|
||||
self.sector = Sector.objects.create(
|
||||
account=self.account,
|
||||
site=self.site,
|
||||
industry_sector=self.industry_sector,
|
||||
name="Test Sector",
|
||||
slug="test-sector"
|
||||
)
|
||||
self.blueprint = SiteBlueprint.objects.create(
|
||||
account=self.account,
|
||||
site=self.site,
|
||||
sector=self.sector,
|
||||
name="Test Blueprint",
|
||||
status='ready'
|
||||
)
|
||||
|
||||
def test_sites_renderer_adapter_implements_base_interface(self):
|
||||
"""Test: Adapter pattern works correctly"""
|
||||
adapter = SitesRendererAdapter()
|
||||
|
||||
self.assertIsInstance(adapter, BaseAdapter)
|
||||
self.assertTrue(hasattr(adapter, 'publish'))
|
||||
self.assertTrue(hasattr(adapter, 'test_connection'))
|
||||
self.assertTrue(hasattr(adapter, 'get_status'))
|
||||
|
||||
def test_wordpress_adapter_implements_base_interface(self):
|
||||
"""Test: Adapter pattern works correctly"""
|
||||
adapter = WordPressAdapter()
|
||||
|
||||
self.assertIsInstance(adapter, BaseAdapter)
|
||||
self.assertTrue(hasattr(adapter, 'publish'))
|
||||
self.assertTrue(hasattr(adapter, 'test_connection'))
|
||||
self.assertTrue(hasattr(adapter, 'get_status'))
|
||||
|
||||
def test_sites_renderer_adapter_deploys_site(self):
|
||||
"""Test: Multi-destination publishing works"""
|
||||
adapter = SitesRendererAdapter()
|
||||
|
||||
result = adapter.deploy(self.blueprint)
|
||||
|
||||
self.assertTrue(result.get('success'))
|
||||
self.assertIsNotNone(result.get('deployment_url'))
|
||||
self.assertIsNotNone(result.get('version'))
|
||||
|
||||
def test_wordpress_adapter_publishes_content(self):
|
||||
"""Test: Multi-destination publishing works"""
|
||||
from igny8_core.business.content.models import Content
|
||||
|
||||
content = Content.objects.create(
|
||||
account=self.account,
|
||||
site=self.site,
|
||||
sector=self.sector,
|
||||
title="Test Content",
|
||||
html_content="<p>Test</p>"
|
||||
)
|
||||
|
||||
adapter = WordPressAdapter()
|
||||
config = {
|
||||
'site_url': 'https://example.com',
|
||||
'username': 'test',
|
||||
'app_password': 'test'
|
||||
}
|
||||
|
||||
# Patch WordPressClient at the point where it's used in the adapter
|
||||
with patch('igny8_core.business.publishing.services.adapters.wordpress_adapter.WordPressClient') as mock_client_class:
|
||||
mock_instance = Mock()
|
||||
mock_instance.create_post.return_value = {'id': 123, 'link': 'https://example.com/post/123'}
|
||||
mock_client_class.return_value = mock_instance
|
||||
|
||||
result = adapter.publish(content, config)
|
||||
|
||||
self.assertTrue(result.get('success'))
|
||||
self.assertIsNotNone(result.get('external_id'))
|
||||
self.assertIsNotNone(result.get('url'))
|
||||
|
||||
@@ -1,141 +0,0 @@
|
||||
"""
|
||||
DEPRECATED: Tests for DeploymentService - SiteBlueprint models removed
|
||||
Phase 5: Sites Renderer & Publishing
|
||||
"""
|
||||
from django.test import TestCase
|
||||
from django.utils import timezone
|
||||
|
||||
from igny8_core.auth.models import Account, Site, Sector, User, Plan, Industry, IndustrySector
|
||||
from igny8_core.business.publishing.models import DeploymentRecord
|
||||
from igny8_core.business.publishing.services.deployment_service import DeploymentService
|
||||
|
||||
|
||||
class DeploymentServiceTestCase(TestCase):
|
||||
"""DEPRECATED: Test cases for DeploymentService"""
|
||||
|
||||
def setUp(self):
|
||||
"""Set up test data"""
|
||||
# Create plan first
|
||||
self.plan = Plan.objects.create(
|
||||
name="Test Plan",
|
||||
slug="test-plan",
|
||||
price=0,
|
||||
credits_per_month=1000
|
||||
)
|
||||
|
||||
# Create user first (Account needs owner)
|
||||
self.user = User.objects.create_user(
|
||||
username='testuser',
|
||||
email='test@test.com',
|
||||
password='testpass123',
|
||||
role='owner'
|
||||
)
|
||||
|
||||
# Create account with owner
|
||||
self.account = Account.objects.create(
|
||||
name="Test Account",
|
||||
slug="test-account",
|
||||
plan=self.plan,
|
||||
owner=self.user
|
||||
)
|
||||
|
||||
# Update user to have account
|
||||
self.user.account = self.account
|
||||
self.user.save()
|
||||
|
||||
# Create industry and sector
|
||||
self.industry = Industry.objects.create(
|
||||
name="Test Industry",
|
||||
slug="test-industry"
|
||||
)
|
||||
|
||||
self.industry_sector = IndustrySector.objects.create(
|
||||
industry=self.industry,
|
||||
name="Test Sector",
|
||||
slug="test-sector"
|
||||
)
|
||||
|
||||
self.site = Site.objects.create(
|
||||
account=self.account,
|
||||
name="Test Site",
|
||||
slug="test-site",
|
||||
industry=self.industry
|
||||
)
|
||||
self.sector = Sector.objects.create(
|
||||
account=self.account,
|
||||
site=self.site,
|
||||
industry_sector=self.industry_sector,
|
||||
name="Test Sector",
|
||||
slug="test-sector"
|
||||
)
|
||||
# DEPRECATED: SiteBlueprint model removed
|
||||
self.blueprint = None
|
||||
self.service = DeploymentService()
|
||||
|
||||
def test_get_status_returns_deployed_record(self):
|
||||
"""Test: Sites are accessible publicly"""
|
||||
DeploymentRecord.objects.create(
|
||||
account=self.account,
|
||||
site=self.site,
|
||||
sector=self.sector,
|
||||
site_blueprint=self.blueprint,
|
||||
version=1,
|
||||
status='deployed',
|
||||
deployment_url='https://test-site.igny8.com',
|
||||
deployed_at=timezone.now()
|
||||
)
|
||||
|
||||
status = self.service.get_status(self.blueprint)
|
||||
|
||||
self.assertIsNotNone(status)
|
||||
self.assertEqual(status.status, 'deployed')
|
||||
self.assertEqual(status.deployment_url, 'https://test-site.igny8.com')
|
||||
|
||||
def test_get_latest_deployment_returns_most_recent(self):
|
||||
"""Test: Deployment works end-to-end"""
|
||||
DeploymentRecord.objects.create(
|
||||
account=self.account,
|
||||
site=self.site,
|
||||
sector=self.sector,
|
||||
site_blueprint=self.blueprint,
|
||||
version=1,
|
||||
status='failed',
|
||||
created_at=timezone.now()
|
||||
)
|
||||
|
||||
latest = DeploymentRecord.objects.create(
|
||||
account=self.account,
|
||||
site=self.site,
|
||||
sector=self.sector,
|
||||
site_blueprint=self.blueprint,
|
||||
version=2,
|
||||
status='deployed',
|
||||
deployment_url='https://test-site.igny8.com',
|
||||
deployed_at=timezone.now()
|
||||
)
|
||||
|
||||
result = self.service.get_latest_deployment(self.blueprint)
|
||||
|
||||
self.assertIsNotNone(result)
|
||||
self.assertEqual(result.version, 2)
|
||||
self.assertEqual(result.status, 'deployed')
|
||||
|
||||
def test_rollback_reverts_to_previous_version(self):
|
||||
"""Test: Deployment works end-to-end"""
|
||||
DeploymentRecord.objects.create(
|
||||
account=self.account,
|
||||
site=self.site,
|
||||
sector=self.sector,
|
||||
site_blueprint=self.blueprint,
|
||||
version=1,
|
||||
status='deployed',
|
||||
deployment_url='https://test-site.igny8.com',
|
||||
deployed_at=timezone.now()
|
||||
)
|
||||
|
||||
result = self.service.rollback(self.blueprint, target_version=1)
|
||||
|
||||
self.assertTrue(result.get('success'))
|
||||
self.blueprint.refresh_from_db()
|
||||
self.assertEqual(self.blueprint.deployed_version, 1)
|
||||
|
||||
@@ -1,151 +0,0 @@
|
||||
"""
|
||||
Tests for PublisherService
|
||||
Phase 5: Sites Renderer & Publishing
|
||||
"""
|
||||
from django.test import TestCase
|
||||
from django.utils import timezone
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from igny8_core.auth.models import Account, Site, Sector, User, Plan, Industry, IndustrySector
|
||||
from igny8_core.business.site_building.models import SiteBlueprint
|
||||
from igny8_core.business.publishing.models import PublishingRecord, DeploymentRecord
|
||||
from igny8_core.business.publishing.services.publisher_service import PublisherService
|
||||
|
||||
|
||||
class PublisherServiceTestCase(TestCase):
|
||||
"""Test cases for PublisherService"""
|
||||
|
||||
def setUp(self):
|
||||
"""Set up test data"""
|
||||
# Create plan first
|
||||
self.plan = Plan.objects.create(
|
||||
name="Test Plan",
|
||||
slug="test-plan",
|
||||
price=0,
|
||||
credits_per_month=1000
|
||||
)
|
||||
|
||||
# Create user first (Account needs owner)
|
||||
self.user = User.objects.create_user(
|
||||
username='testuser',
|
||||
email='test@test.com',
|
||||
password='testpass123',
|
||||
role='owner'
|
||||
)
|
||||
|
||||
# Create account with owner
|
||||
self.account = Account.objects.create(
|
||||
name="Test Account",
|
||||
slug="test-account",
|
||||
plan=self.plan,
|
||||
owner=self.user
|
||||
)
|
||||
|
||||
# Update user to have account
|
||||
self.user.account = self.account
|
||||
self.user.save()
|
||||
|
||||
# Create industry and sector
|
||||
self.industry = Industry.objects.create(
|
||||
name="Test Industry",
|
||||
slug="test-industry"
|
||||
)
|
||||
|
||||
self.industry_sector = IndustrySector.objects.create(
|
||||
industry=self.industry,
|
||||
name="Test Sector",
|
||||
slug="test-sector"
|
||||
)
|
||||
|
||||
self.site = Site.objects.create(
|
||||
account=self.account,
|
||||
name="Test Site",
|
||||
slug="test-site",
|
||||
industry=self.industry
|
||||
)
|
||||
self.sector = Sector.objects.create(
|
||||
account=self.account,
|
||||
site=self.site,
|
||||
industry_sector=self.industry_sector,
|
||||
name="Test Sector",
|
||||
slug="test-sector"
|
||||
)
|
||||
self.blueprint = SiteBlueprint.objects.create(
|
||||
account=self.account,
|
||||
site=self.site,
|
||||
sector=self.sector,
|
||||
name="Test Blueprint",
|
||||
status='ready'
|
||||
)
|
||||
self.service = PublisherService()
|
||||
|
||||
def test_publish_to_sites_creates_deployment_record(self):
|
||||
"""Test: Deployment works end-to-end"""
|
||||
# Don't mock deploy - let it run to create the deployment record
|
||||
# But mock the filesystem operations to avoid actual file writes
|
||||
with patch('igny8_core.business.publishing.services.adapters.sites_renderer_adapter.Path.mkdir'), \
|
||||
patch('igny8_core.business.publishing.services.adapters.sites_renderer_adapter.open', create=True) as mock_open:
|
||||
mock_file = mock_open.return_value.__enter__.return_value
|
||||
|
||||
result = self.service.publish_to_sites(self.blueprint)
|
||||
|
||||
self.assertTrue(result.get('success'))
|
||||
self.assertIsNotNone(result.get('deployment_url'))
|
||||
|
||||
# Verify deployment record was created
|
||||
deployment = DeploymentRecord.objects.filter(site_blueprint=self.blueprint).first()
|
||||
self.assertIsNotNone(deployment)
|
||||
|
||||
def test_get_deployment_status_returns_latest(self):
|
||||
"""Test: Sites are accessible publicly"""
|
||||
DeploymentRecord.objects.create(
|
||||
account=self.account,
|
||||
site=self.site,
|
||||
sector=self.sector,
|
||||
site_blueprint=self.blueprint,
|
||||
version=1,
|
||||
status='deployed',
|
||||
deployment_url='https://test-site.igny8.com',
|
||||
deployed_at=timezone.now()
|
||||
)
|
||||
|
||||
status = self.service.get_deployment_status(self.blueprint)
|
||||
|
||||
self.assertIsNotNone(status)
|
||||
self.assertEqual(status.status, 'deployed')
|
||||
self.assertIsNotNone(status.deployment_url)
|
||||
|
||||
def test_publish_content_to_multiple_destinations(self):
|
||||
"""Test: Multi-destination publishing works"""
|
||||
from igny8_core.business.content.models import Content
|
||||
|
||||
content = Content.objects.create(
|
||||
account=self.account,
|
||||
site=self.site,
|
||||
sector=self.sector,
|
||||
title="Test Content",
|
||||
html_content="<p>Test</p>"
|
||||
)
|
||||
|
||||
with patch.object(self.service, '_get_adapter') as mock_get_adapter:
|
||||
mock_adapter = Mock()
|
||||
mock_adapter.publish.return_value = {
|
||||
'success': True,
|
||||
'external_id': '123',
|
||||
'url': 'https://example.com/post/123'
|
||||
}
|
||||
mock_get_adapter.return_value = mock_adapter
|
||||
|
||||
result = self.service.publish_content(
|
||||
content_id=content.id,
|
||||
destinations=['wordpress', 'sites'],
|
||||
account=self.account
|
||||
)
|
||||
|
||||
self.assertTrue(result.get('success'))
|
||||
self.assertEqual(len(result.get('results', [])), 2)
|
||||
|
||||
# Verify publishing records were created
|
||||
records = PublishingRecord.objects.filter(content=content)
|
||||
self.assertEqual(records.count(), 2)
|
||||
|
||||
Reference in New Issue
Block a user