docges-api-py 0.1.5__tar.gz → 0.1.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. {docges_api_py-0.1.5/src/docges_api_py.egg-info → docges_api_py-0.1.6}/PKG-INFO +11 -5
  2. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/README.md +10 -4
  3. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/pyproject.toml +1 -1
  4. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/src/docges_api_py/client.py +63 -0
  5. {docges_api_py-0.1.5 → docges_api_py-0.1.6/src/docges_api_py.egg-info}/PKG-INFO +11 -5
  6. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/src/docges_api_py.egg-info/SOURCES.txt +1 -0
  7. docges_api_py-0.1.6/tests/test_check_dir_struct.py +135 -0
  8. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/LICENSE +0 -0
  9. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/setup.cfg +0 -0
  10. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/src/docges_api_py/__init__.py +0 -0
  11. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/src/docges_api_py/models/__init__.py +0 -0
  12. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/src/docges_api_py/models/auth.py +0 -0
  13. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/src/docges_api_py/models/document.py +0 -0
  14. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/src/docges_api_py/models/requests.py +0 -0
  15. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/src/docges_api_py/models/responses.py +0 -0
  16. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/src/docges_api_py.egg-info/dependency_links.txt +0 -0
  17. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/src/docges_api_py.egg-info/requires.txt +0 -0
  18. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/src/docges_api_py.egg-info/top_level.txt +0 -0
  19. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/tests/test_client_auth.py +0 -0
  20. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/tests/test_content_methods.py +0 -0
  21. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/tests/test_endpoints.py +0 -0
  22. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/tests/test_examples.py +0 -0
  23. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/tests/test_get_document.py +0 -0
  24. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/tests/test_initial_cats.py +0 -0
  25. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/tests/test_models_auth.py +0 -0
  26. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/tests/test_models_init.py +0 -0
  27. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/tests/test_models_requests.py +0 -0
  28. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/tests/test_models_responses.py +0 -0
  29. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/tests/test_remaining_methods.py +0 -0
  30. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/tests/test_retry.py +0 -0
  31. {docges_api_py-0.1.5 → docges_api_py-0.1.6}/tests/test_token_refresh.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: docges-api-py
3
- Version: 0.1.5
3
+ Version: 0.1.6
4
4
  Summary: Async, typed Python client for DocGes REST API
5
5
  Author-email: "ct.galega" <soporte@ctgalega.com>
6
6
  License: MIT
@@ -78,6 +78,7 @@ pip install -e ".[dev]"
78
78
  | `create_category(parent_sid, name)` | `POST /Content/CreateCategory` | Create a subcategory |
79
79
  | `rename_category(sid, new_name)` | `POST /Content/RenameCategory` | Rename a category |
80
80
  | `delete_category(sid)` | `POST /Content/DeleteCategory` | Delete a category |
81
+ | `check_dir_struct(root_sid, path_names, create_if_not_exist)` | — | Check or create nested directory structure |
81
82
 
82
83
  ### Document Management
83
84
  | Method | Endpoint | Description |
@@ -129,10 +130,12 @@ asyncio.run(main())
129
130
  | `DOCGES_USER` | Username | `administrador` |
130
131
  | `DOCGES_PASSWORD` | Password | `12345` |
131
132
  | `DOCGES_APP_ID` | App ID (maps to server config in `clients.xml`) | `local-dev` |
133
+ | `DOCGES_ROOT_SID` | Root category SID for directory operations | `1ddbfd1b-5d33-44af-b392-...` |
132
134
 
133
- **Known appIDs and their servers:**
134
- - `local-dev` — `192.168.0.90:49375/Almacen1`
135
- - `pre-dev` — `apps.ctgalega.com:54433/devbg`
135
+ **Known appIDs:**
136
+ - `local-dev` — local development
137
+ - `pre-dev` — pre-production
138
+ - `pro-*` — production servers
136
139
 
137
140
  ## Examples
138
141
 
@@ -156,6 +159,7 @@ python examples/<number>_<name>.py
156
159
  | 06 | `examples/06_download.py` | Download a document by SID |
157
160
  | 07 | `examples/07_category_crud.py` | Create, rename, and delete a category |
158
161
  | 08 | `examples/08_document_operations.py` | Update ERP metadata, move, and remove a document |
162
+ | 09 | `examples/09_dir_structure.py` | Check or create nested directory structure |
159
163
 
160
164
  ## Development
161
165
 
@@ -192,6 +196,7 @@ docges-api-py/
192
196
  │ ├── test_initial_cats.py
193
197
  │ ├── test_content_methods.py
194
198
  │ ├── test_remaining_methods.py
199
+ │ ├── test_check_dir_struct.py
195
200
  │ ├── test_models_requests.py
196
201
  │ ├── test_models_responses.py
197
202
  │ ├── test_models_init.py
@@ -207,7 +212,8 @@ docges-api-py/
207
212
  │ ├── 05_upload.py
208
213
  │ ├── 06_download.py
209
214
  │ ├── 07_category_crud.py
210
- │ └── 08_document_operations.py
215
+ │ ├── 08_document_operations.py
216
+ │ └── 09_dir_structure.py
211
217
  ├── docs/
212
218
  │ └── MIGRATION.md
213
219
  ├── scripts/
@@ -58,6 +58,7 @@ pip install -e ".[dev]"
58
58
  | `create_category(parent_sid, name)` | `POST /Content/CreateCategory` | Create a subcategory |
59
59
  | `rename_category(sid, new_name)` | `POST /Content/RenameCategory` | Rename a category |
60
60
  | `delete_category(sid)` | `POST /Content/DeleteCategory` | Delete a category |
61
+ | `check_dir_struct(root_sid, path_names, create_if_not_exist)` | — | Check or create nested directory structure |
61
62
 
62
63
  ### Document Management
63
64
  | Method | Endpoint | Description |
@@ -109,10 +110,12 @@ asyncio.run(main())
109
110
  | `DOCGES_USER` | Username | `administrador` |
110
111
  | `DOCGES_PASSWORD` | Password | `12345` |
111
112
  | `DOCGES_APP_ID` | App ID (maps to server config in `clients.xml`) | `local-dev` |
113
+ | `DOCGES_ROOT_SID` | Root category SID for directory operations | `1ddbfd1b-5d33-44af-b392-...` |
112
114
 
113
- **Known appIDs and their servers:**
114
- - `local-dev` — `192.168.0.90:49375/Almacen1`
115
- - `pre-dev` — `apps.ctgalega.com:54433/devbg`
115
+ **Known appIDs:**
116
+ - `local-dev` — local development
117
+ - `pre-dev` — pre-production
118
+ - `pro-*` — production servers
116
119
 
117
120
  ## Examples
118
121
 
@@ -136,6 +139,7 @@ python examples/<number>_<name>.py
136
139
  | 06 | `examples/06_download.py` | Download a document by SID |
137
140
  | 07 | `examples/07_category_crud.py` | Create, rename, and delete a category |
138
141
  | 08 | `examples/08_document_operations.py` | Update ERP metadata, move, and remove a document |
142
+ | 09 | `examples/09_dir_structure.py` | Check or create nested directory structure |
139
143
 
140
144
  ## Development
141
145
 
@@ -172,6 +176,7 @@ docges-api-py/
172
176
  │ ├── test_initial_cats.py
173
177
  │ ├── test_content_methods.py
174
178
  │ ├── test_remaining_methods.py
179
+ │ ├── test_check_dir_struct.py
175
180
  │ ├── test_models_requests.py
176
181
  │ ├── test_models_responses.py
177
182
  │ ├── test_models_init.py
@@ -187,7 +192,8 @@ docges-api-py/
187
192
  │ ├── 05_upload.py
188
193
  │ ├── 06_download.py
189
194
  │ ├── 07_category_crud.py
190
- │ └── 08_document_operations.py
195
+ │ ├── 08_document_operations.py
196
+ │ └── 09_dir_structure.py
191
197
  ├── docs/
192
198
  │ └── MIGRATION.md
193
199
  ├── scripts/
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "docges-api-py"
7
- version = "0.1.5"
7
+ version = "0.1.6"
8
8
  description = "Async, typed Python client for DocGes REST API"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -362,6 +362,69 @@ class AsyncDocGes:
362
362
  resp = await self.do_request(Endpoints.content_delete_category, data)
363
363
  return bool(resp.get("result"))
364
364
 
365
+ async def check_dir_struct(
366
+ self,
367
+ root_sid: str,
368
+ path_names: list[str],
369
+ create_if_not_exist: bool = False,
370
+ ) -> list[dict] | None:
371
+ """
372
+ Check or create a directory structure under a given root SID.
373
+
374
+ Traverses the hierarchy level by level. For each level:
375
+ 1. Gets child categories via get_cat_info()
376
+ 2. Searches for a matching category by name
377
+ 3. If not found and create_if_not_exist=True, creates it
378
+
379
+ Args:
380
+ root_sid: The root SID to start from
381
+ path_names: List of category names to traverse/create (e.g., ["2025", "PM-001"])
382
+ create_if_not_exist: If True, create missing categories
383
+
384
+ Returns:
385
+ List of dicts with keys: sid, parent_sid, name (one per level)
386
+ None on error
387
+ """
388
+ results: list[dict] = []
389
+ current_sid = root_sid
390
+
391
+ try:
392
+ for name in path_names:
393
+ cat_info = await self.get_cat_info(current_sid)
394
+
395
+ found_sid = None
396
+ if cat_info and cat_info.CategoriasHijas:
397
+ for child in cat_info.CategoriasHijas:
398
+ if child.get("Nombre") == name:
399
+ found_sid = child.get("SID")
400
+ break
401
+
402
+ if found_sid:
403
+ results.append({
404
+ "sid": found_sid,
405
+ "parent_sid": current_sid,
406
+ "name": name,
407
+ })
408
+ current_sid = found_sid
409
+ elif create_if_not_exist:
410
+ new_sid = await self.create_category(current_sid, name)
411
+ if new_sid:
412
+ results.append({
413
+ "sid": new_sid,
414
+ "parent_sid": current_sid,
415
+ "name": name,
416
+ })
417
+ current_sid = new_sid
418
+ else:
419
+ return None
420
+ else:
421
+ return None
422
+
423
+ return results
424
+
425
+ except Exception:
426
+ return None
427
+
365
428
  async def remove_document(self, sid: str) -> bool:
366
429
  """Remove a single document. Returns True on success."""
367
430
  await self._ensure_session()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: docges-api-py
3
- Version: 0.1.5
3
+ Version: 0.1.6
4
4
  Summary: Async, typed Python client for DocGes REST API
5
5
  Author-email: "ct.galega" <soporte@ctgalega.com>
6
6
  License: MIT
@@ -78,6 +78,7 @@ pip install -e ".[dev]"
78
78
  | `create_category(parent_sid, name)` | `POST /Content/CreateCategory` | Create a subcategory |
79
79
  | `rename_category(sid, new_name)` | `POST /Content/RenameCategory` | Rename a category |
80
80
  | `delete_category(sid)` | `POST /Content/DeleteCategory` | Delete a category |
81
+ | `check_dir_struct(root_sid, path_names, create_if_not_exist)` | — | Check or create nested directory structure |
81
82
 
82
83
  ### Document Management
83
84
  | Method | Endpoint | Description |
@@ -129,10 +130,12 @@ asyncio.run(main())
129
130
  | `DOCGES_USER` | Username | `administrador` |
130
131
  | `DOCGES_PASSWORD` | Password | `12345` |
131
132
  | `DOCGES_APP_ID` | App ID (maps to server config in `clients.xml`) | `local-dev` |
133
+ | `DOCGES_ROOT_SID` | Root category SID for directory operations | `1ddbfd1b-5d33-44af-b392-...` |
132
134
 
133
- **Known appIDs and their servers:**
134
- - `local-dev` — `192.168.0.90:49375/Almacen1`
135
- - `pre-dev` — `apps.ctgalega.com:54433/devbg`
135
+ **Known appIDs:**
136
+ - `local-dev` — local development
137
+ - `pre-dev` — pre-production
138
+ - `pro-*` — production servers
136
139
 
137
140
  ## Examples
138
141
 
@@ -156,6 +159,7 @@ python examples/<number>_<name>.py
156
159
  | 06 | `examples/06_download.py` | Download a document by SID |
157
160
  | 07 | `examples/07_category_crud.py` | Create, rename, and delete a category |
158
161
  | 08 | `examples/08_document_operations.py` | Update ERP metadata, move, and remove a document |
162
+ | 09 | `examples/09_dir_structure.py` | Check or create nested directory structure |
159
163
 
160
164
  ## Development
161
165
 
@@ -192,6 +196,7 @@ docges-api-py/
192
196
  │ ├── test_initial_cats.py
193
197
  │ ├── test_content_methods.py
194
198
  │ ├── test_remaining_methods.py
199
+ │ ├── test_check_dir_struct.py
195
200
  │ ├── test_models_requests.py
196
201
  │ ├── test_models_responses.py
197
202
  │ ├── test_models_init.py
@@ -207,7 +212,8 @@ docges-api-py/
207
212
  │ ├── 05_upload.py
208
213
  │ ├── 06_download.py
209
214
  │ ├── 07_category_crud.py
210
- │ └── 08_document_operations.py
215
+ │ ├── 08_document_operations.py
216
+ │ └── 09_dir_structure.py
211
217
  ├── docs/
212
218
  │ └── MIGRATION.md
213
219
  ├── scripts/
@@ -13,6 +13,7 @@ src/docges_api_py/models/auth.py
13
13
  src/docges_api_py/models/document.py
14
14
  src/docges_api_py/models/requests.py
15
15
  src/docges_api_py/models/responses.py
16
+ tests/test_check_dir_struct.py
16
17
  tests/test_client_auth.py
17
18
  tests/test_content_methods.py
18
19
  tests/test_endpoints.py
@@ -0,0 +1,135 @@
1
+ """Tests for check_dir_struct() — path traversal and creation logic."""
2
+
3
+ import httpx
4
+ import pytest
5
+ import respx
6
+
7
+ from docges_api_py.client import AsyncDocGes
8
+
9
+ REAL_LOGIN_PAYLOAD = {
10
+ "userInfo": {"SID": "a6e65fd7-1234-5678-abcd-ef0123456789", "Nombre": "Administrador", "Id": 5},
11
+ "wareHouseInfo": {"SID": "16cf3ed3-aaaa-bbbb-cccc-ddddeeee0001", "Nombre": "devbg"},
12
+ }
13
+
14
+
15
+ @pytest.fixture
16
+ def client():
17
+ c = AsyncDocGes("http://test.example.com", "testuser", "testpass", "test-app")
18
+ c._login_response = REAL_LOGIN_PAYLOAD
19
+ return c
20
+
21
+
22
+ @pytest.mark.asyncio
23
+ async def test_check_dir_struct_existing_path(client):
24
+ """When all categories exist, returns the path without creating anything."""
25
+ with respx.mock:
26
+ respx.post("http://test.example.com/Content/LoadChilds").mock(
27
+ return_value=httpx.Response(
28
+ 200,
29
+ json={
30
+ "result": {
31
+ "CategoriasHijas": [{"SID": "sid-2025", "Nombre": "2025"}],
32
+ "Documentos": [],
33
+ }
34
+ },
35
+ )
36
+ )
37
+
38
+ result = await client.check_dir_struct(
39
+ root_sid="root-sid",
40
+ path_names=["2025"],
41
+ create_if_not_exist=False,
42
+ )
43
+
44
+ assert result == [
45
+ {"sid": "sid-2025", "parent_sid": "root-sid", "name": "2025"}
46
+ ]
47
+
48
+
49
+ @pytest.mark.asyncio
50
+ async def test_check_dir_struct_missing_path_without_create(client):
51
+ """When category doesn't exist and create_if_not_exist=False, returns None."""
52
+ with respx.mock:
53
+ respx.post("http://test.example.com/Content/LoadChilds").mock(
54
+ return_value=httpx.Response(
55
+ 200,
56
+ json={
57
+ "result": {
58
+ "CategoriasHijas": [{"SID": "sid-existing", "Nombre": "existing"}],
59
+ "Documentos": [],
60
+ }
61
+ },
62
+ )
63
+ )
64
+
65
+ result = await client.check_dir_struct(
66
+ root_sid="root-sid",
67
+ path_names=["new-folder"],
68
+ create_if_not_exist=False,
69
+ )
70
+
71
+ assert result is None
72
+
73
+
74
+ @pytest.mark.asyncio
75
+ async def test_check_dir_struct_creates_missing_path(client):
76
+ """When category doesn't exist and create_if_not_exist=True, creates it."""
77
+ with respx.mock:
78
+ respx.post("http://test.example.com/Content/LoadChilds").mock(
79
+ return_value=httpx.Response(
80
+ 200,
81
+ json={"result": {"CategoriasHijas": [], "Documentos": []}},
82
+ )
83
+ )
84
+ respx.post("http://test.example.com/Content/CreateCategory").mock(
85
+ return_value=httpx.Response(200, json={"result": "new-sid-2025"})
86
+ )
87
+
88
+ result = await client.check_dir_struct(
89
+ root_sid="root-sid",
90
+ path_names=["2025"],
91
+ create_if_not_exist=True,
92
+ )
93
+
94
+ assert result == [
95
+ {"sid": "new-sid-2025", "parent_sid": "root-sid", "name": "2025"}
96
+ ]
97
+
98
+
99
+ @pytest.mark.asyncio
100
+ async def test_check_dir_struct_mixed_path(client):
101
+ """First level exists, second level needs creation."""
102
+ with respx.mock:
103
+ respx.post("http://test.example.com/Content/LoadChilds").mock(
104
+ side_effect=[
105
+ # First call: root has "2025"
106
+ httpx.Response(
107
+ 200,
108
+ json={
109
+ "result": {
110
+ "CategoriasHijas": [{"SID": "sid-2025", "Nombre": "2025"}],
111
+ "Documentos": [],
112
+ }
113
+ },
114
+ ),
115
+ # Second call: "2025" has no children
116
+ httpx.Response(
117
+ 200,
118
+ json={"result": {"CategoriasHijas": [], "Documentos": []}},
119
+ ),
120
+ ]
121
+ )
122
+ respx.post("http://test.example.com/Content/CreateCategory").mock(
123
+ return_value=httpx.Response(200, json={"result": "new-sid-pm"})
124
+ )
125
+
126
+ result = await client.check_dir_struct(
127
+ root_sid="root-sid",
128
+ path_names=["2025", "PM-001"],
129
+ create_if_not_exist=True,
130
+ )
131
+
132
+ assert result == [
133
+ {"sid": "sid-2025", "parent_sid": "root-sid", "name": "2025"},
134
+ {"sid": "new-sid-pm", "parent_sid": "sid-2025", "name": "PM-001"},
135
+ ]
File without changes
File without changes