-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconftest.py
More file actions
205 lines (184 loc) · 5.74 KB
/
Copy pathconftest.py
File metadata and controls
205 lines (184 loc) · 5.74 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
"""
Pytest configuration and fixtures for Alfresco API testing.
Provides:
- Mock Alfresco server fixtures
- Test client fixtures
- Configuration fixtures
"""
import pytest
from unittest.mock import Mock, patch
from typing import Dict, Any
import asyncio
# Test configuration
TEST_CONFIG = {
'host': 'http://localhost:8080',
'username': 'admin',
'password': 'admin',
'verify_ssl': True
}
# Configure pytest markers
def pytest_configure(config):
"""Configure pytest with custom markers"""
config.addinivalue_line("markers", "integration: mark test as integration test requiring live server")
config.addinivalue_line("markers", "asyncio: mark test as async test")
# Configure asyncio event loop for tests
@pytest.fixture(scope="session")
def event_loop():
"""Create an instance of the default event loop for the test session."""
loop = asyncio.get_event_loop_policy().new_event_loop()
yield loop
loop.close()
@pytest.fixture
def mock_alfresco_server():
"""Mock Alfresco server responses."""
mock_server = Mock()
# Mock repository information
mock_server.get_repository_information.return_value = Mock(
entry=Mock(
repository=Mock(
name="Alfresco Test Repository",
version="7.4.0",
edition="Community"
)
)
)
# Mock node responses
mock_server.get_node.return_value = Mock(
id="test-node-id",
name="test-node",
node_type="cm:content",
is_file=True,
is_folder=False
)
# Mock search responses
mock_server.search.return_value = Mock(
list=Mock(
entries=[
Mock(entry=Mock(id="search-result-1", name="result1")),
Mock(entry=Mock(id="search-result-2", name="result2"))
],
pagination=Mock(count=2, total_items=2)
)
)
return mock_server
@pytest.fixture
def test_client_config():
"""Test client configuration."""
return TEST_CONFIG.copy()
@pytest.fixture
def mock_api_client():
"""Mock API client for unit testing."""
mock_client = Mock()
# Mock configuration
mock_client.configuration = Mock(
host=TEST_CONFIG['host'],
username=TEST_CONFIG['username'],
password=TEST_CONFIG['password'],
verify_ssl=TEST_CONFIG['verify_ssl']
)
return mock_client
@pytest.fixture
def alfresco_client():
"""Fixture providing an AlfrescoClient for testing."""
try:
from python_alfresco_api import ClientFactory
factory = ClientFactory(
base_url="http://localhost:8080",
username="admin",
password="admin",
verify_ssl=False
)
return factory.create_master_client()
except Exception as e:
pytest.skip(f"ClientFactory not available: {e}")
@pytest.fixture
def live_client():
"""Live Alfresco client for integration testing."""
try:
from python_alfresco_api import ClientFactory
# Use current factory pattern API
factory = ClientFactory(
base_url=TEST_CONFIG['host'],
username=TEST_CONFIG['username'],
password=TEST_CONFIG['password'],
verify_ssl=TEST_CONFIG['verify_ssl']
)
# Create master client with dot syntax access
client = factory.create_master_client()
# Test basic availability
try:
# Simple test - just verify client exists
return client
except Exception:
pytest.skip("Live Alfresco server not available")
except ImportError:
pytest.skip("ClientFactory not available")
@pytest.fixture
def mock_responses():
"""Common mock responses for testing."""
return {
'auth_ticket': {
'entry': {
'id': 'TICKET_1234567890abcdef',
'userId': 'admin'
}
},
'node_list': {
'list': {
'entries': [
{
'entry': {
'id': 'node-1',
'name': 'test-file.txt',
'nodeType': 'cm:content',
'isFile': True,
'isFolder': False
}
},
{
'entry': {
'id': 'node-2',
'name': 'test-folder',
'nodeType': 'cm:folder',
'isFile': False,
'isFolder': True
}
}
],
'pagination': {
'count': 2,
'totalItems': 2
}
}
},
'site_list': {
'list': {
'entries': [
{
'entry': {
'id': 'test-site',
'title': 'Test Site',
'visibility': 'PUBLIC'
}
}
],
'pagination': {
'count': 1,
'totalItems': 1
}
}
}
}
@pytest.fixture
def master_client():
"""Fixture providing master client for integration tests."""
try:
from python_alfresco_api import ClientFactory
factory = ClientFactory(
base_url="http://localhost:8080",
username="admin",
password="admin"
)
return factory.create_master_client()
except Exception as e:
pytest.skip(f"Master client not available: {e}")