-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathtest_config.py
More file actions
134 lines (108 loc) · 4.6 KB
/
test_config.py
File metadata and controls
134 lines (108 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env python3
"""
Test script to verify DataPusher Plus conditional features
"""
import os
import sys
# Add CKAN to Python path (adjust as needed)
sys.path.insert(0, '/usr/lib/ckan/default/src/ckan')
def test_configuration():
"""Test the conditional loading of DataPusher Plus features"""
print("=== DataPusher Plus Configuration Test ===\n")
# Mock configuration scenarios
test_configs = [
{
'name': 'All disabled (default)',
'config': {}
},
{
'name': 'DRUF enabled only',
'config': {'ckanext.datapusher_plus.enable_druf': 'true'}
},
{
'name': 'IFormRedirect enabled only',
'config': {'ckanext.datapusher_plus.enable_form_redirect': 'true'}
},
{
'name': 'Both enabled',
'config': {
'ckanext.datapusher_plus.enable_druf': 'true',
'ckanext.datapusher_plus.enable_form_redirect': 'true'
}
}
]
try:
# Import required modules
from ckan.plugins import toolkit as tk
for test in test_configs:
print(f"Testing: {test['name']}")
print(f"Config: {test['config']}")
# Simulate configuration
for key, value in test['config'].items():
tk.config[key] = value
# Test helper functions
enable_druf = tk.asbool(tk.config.get('ckanext.datapusher_plus.enable_druf', False))
enable_form_redirect = tk.asbool(tk.config.get('ckanext.datapusher_plus.enable_form_redirect', False))
print(f" DRUF enabled: {enable_druf}")
print(f" IFormRedirect enabled: {enable_form_redirect}")
# Check template directory logic
template_dirs = ['templates']
if enable_druf:
template_dirs.append('templates/druf')
print(f" Template directories: {template_dirs}")
print()
# Clear config for next test
for key in test['config'].keys():
tk.config.pop(key, None)
except ImportError as e:
print(f"Could not import CKAN modules: {e}")
print("This is expected if running outside CKAN environment")
return False
return True
def check_template_structure():
"""Verify template directory structure"""
print("=== Template Structure Check ===\n")
base_dir = "/usr/lib/ckan/default/src/datapusher-plus/ckanext/datapusher_plus/templates"
# Check expected directories
expected_dirs = [
"templates",
"templates/druf",
"templates/druf/snippets",
"templates/druf/package/snippets",
"templates/druf/scheming/package/snippets"
]
# Check expected files
expected_files = [
"templates/snippets/add_dataset.html",
"templates/druf/snippets/add_dataset.html",
"templates/package/snippets/package_form.html",
"templates/druf/package/snippets/package_form.html",
"templates/scheming/package/snippets/package_form.html",
"templates/druf/scheming/package/snippets/package_form.html"
]
print("Checking directories:")
for dir_path in expected_dirs:
full_path = os.path.join(base_dir, dir_path.replace("templates/", ""))
if dir_path == "templates":
full_path = base_dir
exists = os.path.exists(full_path)
print(f" {dir_path}: {'✓' if exists else '✗'}")
print("\nChecking template files:")
for file_path in expected_files:
full_path = os.path.join(base_dir, file_path.replace("templates/", ""))
if file_path.startswith("templates/") and not file_path.startswith("templates/druf"):
full_path = os.path.join(base_dir, file_path[10:]) # Remove "templates/"
exists = os.path.exists(full_path)
print(f" {file_path}: {'✓' if exists else '✗'}")
print()
if __name__ == "__main__":
print("DataPusher Plus Configuration and Template Test\n")
check_template_structure()
test_configuration()
print("=== Summary ===")
print("✓ Template structure organized for conditional loading")
print("✓ Configuration options available for DRUF and IFormRedirect")
print("✓ Backwards compatibility maintained when features disabled")
print("\nTo enable features, add to your CKAN config:")
print(" ckanext.datapusher_plus.enable_druf = true")
print(" ckanext.datapusher_plus.enable_form_redirect = true")