62 lines
1.9 KiB
Python
62 lines
1.9 KiB
Python
from __future__ import annotations
|
|
|
|
import subprocess
|
|
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
|
|
_IMPORT_PROGRAM = """
|
|
import importlib
|
|
import socket
|
|
import sys
|
|
|
|
sys.path.insert(0, sys.argv[1])
|
|
|
|
def deny_network(*args, **kwargs):
|
|
raise AssertionError("Campaign imports must not connect to external services")
|
|
|
|
class NoNetworkSocket(socket.socket):
|
|
connect = deny_network
|
|
connect_ex = deny_network
|
|
|
|
socket.create_connection = deny_network
|
|
socket.socket = NoNetworkSocket
|
|
|
|
importlib.import_module(sys.argv[2])
|
|
from govoplan_campaign.backend.campaign import (
|
|
CampaignConfig, SemanticIssue, SemanticReport,
|
|
load_campaign_config, load_campaign_json, validate_campaign_config,
|
|
)
|
|
from govoplan_campaign.backend.attachments.resolver import resolve_campaign_attachments
|
|
|
|
assert all(callable(value) for value in (
|
|
CampaignConfig, SemanticIssue, SemanticReport,
|
|
load_campaign_config, load_campaign_json, validate_campaign_config,
|
|
resolve_campaign_attachments,
|
|
))
|
|
"""
|
|
|
|
|
|
class CampaignImportOrderTests(unittest.TestCase):
|
|
def test_model_validation_and_attachment_entry_points_import_independently(self):
|
|
source_root = Path(__file__).resolve().parents[1] / "src"
|
|
for first_module in (
|
|
"govoplan_campaign.backend.attachments.resolver",
|
|
"govoplan_campaign.backend.campaign.validation",
|
|
"govoplan_campaign.backend.campaign.entries",
|
|
):
|
|
with self.subTest(first_module=first_module):
|
|
completed = subprocess.run(
|
|
[sys.executable, "-I", "-c", _IMPORT_PROGRAM, str(source_root), first_module],
|
|
capture_output=True,
|
|
text=True,
|
|
check=False,
|
|
timeout=30,
|
|
)
|
|
self.assertEqual(0, completed.returncode, completed.stderr or completed.stdout)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|