odoo-addon-project-task-api 16.0.1.1.2__py3-none-any.whl
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.
- odoo/addons/project_task_api/CHANGELOG.md +26 -0
- odoo/addons/project_task_api/README.rst +121 -0
- odoo/addons/project_task_api/__init__.py +1 -0
- odoo/addons/project_task_api/__manifest__.py +26 -0
- odoo/addons/project_task_api/data/fastapi_endpoint.xml +10 -0
- odoo/addons/project_task_api/models/__init__.py +3 -0
- odoo/addons/project_task_api/models/fastapi_endpoint.py +40 -0
- odoo/addons/project_task_api/routers/__init__.py +1 -0
- odoo/addons/project_task_api/routers/project_task_router.py +253 -0
- odoo/addons/project_task_api/schemas/__init__.py +2 -0
- odoo/addons/project_task_api/schemas/common.py +6 -0
- odoo/addons/project_task_api/schemas/project_task.py +257 -0
- odoo/addons/project_task_api/static/description/icon.png +0 -0
- odoo/addons/project_task_api/tests/__init__.py +1 -0
- odoo/addons/project_task_api/tests/test_fastapi_endpoint.py +551 -0
- odoo_addon_project_task_api-16.0.1.1.2.dist-info/METADATA +141 -0
- odoo_addon_project_task_api-16.0.1.1.2.dist-info/RECORD +19 -0
- odoo_addon_project_task_api-16.0.1.1.2.dist-info/WHEEL +5 -0
- odoo_addon_project_task_api-16.0.1.1.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
|
|
3
|
+
from fastapi import status
|
|
4
|
+
|
|
5
|
+
from odoo.addons.fastapi_auth_api_key_sc.tests.common import APICommonBaseFastAPICase
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class TestFastAPiEndpoint(APICommonBaseFastAPICase):
|
|
9
|
+
@classmethod
|
|
10
|
+
def setUpClass(cls) -> None:
|
|
11
|
+
super().setUpClass()
|
|
12
|
+
endpoint_model = cls.env["fastapi.endpoint"]
|
|
13
|
+
cls.default_fastapi_router = endpoint_model._get_project_tasks_router()
|
|
14
|
+
cls.default_fastapi_running_user = cls.env.ref(
|
|
15
|
+
"fastapi_auth_api_key_sc.fastapi_service_user"
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
def setUp(self):
|
|
19
|
+
super().setUp()
|
|
20
|
+
self.project_task = self.env.ref("project.project_1_task_1")
|
|
21
|
+
self.url = "project_tasks"
|
|
22
|
+
self.partner = self.env.ref("base.res_partner_12")
|
|
23
|
+
self.partner.ref = "TEST_REF"
|
|
24
|
+
self.project_task.partner_id = self.partner
|
|
25
|
+
self.contract_partner = self.env.ref("base.res_partner_2")
|
|
26
|
+
self.contract_partner.ref = "CONTRACT_REF"
|
|
27
|
+
self.contract = self.env["contract.contract"].create(
|
|
28
|
+
{
|
|
29
|
+
"name": "Test contract",
|
|
30
|
+
"code": "TEST_CONTRACT_CODE",
|
|
31
|
+
"partner_id": self.contract_partner.id,
|
|
32
|
+
}
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
def test_project_task_get(self):
|
|
36
|
+
"""
|
|
37
|
+
Test the GET /project_tasks/{record_id} endpoint to retrieve
|
|
38
|
+
a project task by its ID.
|
|
39
|
+
"""
|
|
40
|
+
with self._create_test_client() as test_client:
|
|
41
|
+
response = test_client.get(
|
|
42
|
+
f"/{self.url}/{self.project_task.id}", headers=self.api_key_headers()
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
46
|
+
self.assertIsInstance(response.json(), dict)
|
|
47
|
+
self.assertEqual(response.json()["id"], self.project_task.id)
|
|
48
|
+
|
|
49
|
+
def test_project_task_search_project_id(self):
|
|
50
|
+
"""
|
|
51
|
+
Test the GET /project_tasks endpoint can search by project_id
|
|
52
|
+
retrieving a list of all the project tasks from the given project.
|
|
53
|
+
"""
|
|
54
|
+
project = self.project_task.project_id
|
|
55
|
+
|
|
56
|
+
with self._create_test_client() as test_client:
|
|
57
|
+
response = test_client.get(
|
|
58
|
+
f"/{self.url}?project_id={project.id}",
|
|
59
|
+
headers=self.api_key_headers(),
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
63
|
+
self.assertIsInstance(response.json(), list)
|
|
64
|
+
self.assertEqual(len(response.json()), len(project.tasks))
|
|
65
|
+
self.assertIn(self.project_task.id, [task["id"] for task in response.json()])
|
|
66
|
+
|
|
67
|
+
def test_project_task_search_partner_ref(self):
|
|
68
|
+
"""
|
|
69
|
+
Test the GET /project_tasks endpoint can search by both project_id
|
|
70
|
+
and partner_ref retrieving a list of all the project tasks from the given
|
|
71
|
+
project and partner.
|
|
72
|
+
"""
|
|
73
|
+
|
|
74
|
+
with self._create_test_client(env=self.env) as test_client:
|
|
75
|
+
response = test_client.get(
|
|
76
|
+
"/{}?project_id={}&partner_ref={}".format(
|
|
77
|
+
self.url,
|
|
78
|
+
self.project_task.project_id.id,
|
|
79
|
+
self.project_task.partner_id.ref,
|
|
80
|
+
),
|
|
81
|
+
headers=self.api_key_headers(),
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
85
|
+
self.assertIsInstance(response.json(), list)
|
|
86
|
+
self.assertEqual(len(response.json()), 1)
|
|
87
|
+
self.assertEqual(response.json()[0]["id"], self.project_task.id)
|
|
88
|
+
|
|
89
|
+
def test_project_task_search_partner_phone(self):
|
|
90
|
+
"""
|
|
91
|
+
Test the GET /project_tasks endpoint can search by partner_phone
|
|
92
|
+
retrieving a list of all the project tasks from the given partner.
|
|
93
|
+
"""
|
|
94
|
+
self.project_task.partner_phone = "699696969"
|
|
95
|
+
|
|
96
|
+
with self._create_test_client(env=self.env) as test_client:
|
|
97
|
+
response = test_client.get(
|
|
98
|
+
"/{}?project_id={}&partner_phone={}".format(
|
|
99
|
+
self.url,
|
|
100
|
+
self.project_task.project_id.id,
|
|
101
|
+
self.project_task.partner_phone,
|
|
102
|
+
),
|
|
103
|
+
headers=self.api_key_headers(),
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
107
|
+
self.assertIsInstance(response.json(), list)
|
|
108
|
+
self.assertEqual(len(response.json()), 1)
|
|
109
|
+
self.assertEqual(response.json()[0]["id"], self.project_task.id)
|
|
110
|
+
|
|
111
|
+
def test_project_task_search_without_params(self):
|
|
112
|
+
"""
|
|
113
|
+
Test the GET /project_tasks endpoint returns an error if
|
|
114
|
+
not called by none of the params project_id or partner_ref or partner_phone.
|
|
115
|
+
"""
|
|
116
|
+
with self._create_test_client() as test_client:
|
|
117
|
+
response = test_client.get(f"/{self.url}", headers=self.api_key_headers())
|
|
118
|
+
|
|
119
|
+
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
|
120
|
+
self.assertIsInstance(response.json(), dict)
|
|
121
|
+
self.assertEqual(
|
|
122
|
+
response.json()["detail"],
|
|
123
|
+
"At least one of the following query parameters must be provided: partner_ref, project_id, partner_phone", # noqa: E501
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
def test_project_task_create(self):
|
|
127
|
+
"""
|
|
128
|
+
Test the POST /project_tasks endpoint creates a new project task.
|
|
129
|
+
"""
|
|
130
|
+
code = "TESTCODE"
|
|
131
|
+
self.project_task.project_id.code = code
|
|
132
|
+
payload = {
|
|
133
|
+
"name": "Implement authentication",
|
|
134
|
+
"project_code": code,
|
|
135
|
+
"priority": "1",
|
|
136
|
+
"partner_ref": self.project_task.partner_id.ref,
|
|
137
|
+
"tag_ids": [1, 2],
|
|
138
|
+
"date_deadline": "2026-05-01",
|
|
139
|
+
}
|
|
140
|
+
with self._create_test_client(env=self.env) as test_client:
|
|
141
|
+
response = test_client.post(
|
|
142
|
+
f"/{self.url}", json=payload, headers=self.api_key_headers()
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
146
|
+
created = response.json()
|
|
147
|
+
self.assertEqual(created["name"], payload["name"])
|
|
148
|
+
self.assertEqual(created["project_id"], self.project_task.project_id.id)
|
|
149
|
+
self.assertEqual(created["priority"], payload["priority"])
|
|
150
|
+
self.assertEqual(created["tag_ids"], payload["tag_ids"])
|
|
151
|
+
self.assertEqual(created["date_deadline"], payload["date_deadline"])
|
|
152
|
+
|
|
153
|
+
def test_project_task_create_with_properties(self):
|
|
154
|
+
"""
|
|
155
|
+
Test the POST /project_tasks endpoint creates a project task with
|
|
156
|
+
properties.
|
|
157
|
+
"""
|
|
158
|
+
code = "TESTCODE"
|
|
159
|
+
self.project_task.project_id.code = code
|
|
160
|
+
self.project_task.project_id.task_properties_definition = [
|
|
161
|
+
{"name": "color", "string": "Color", "type": "char"},
|
|
162
|
+
{"name": "size", "string": "Size", "type": "char"},
|
|
163
|
+
]
|
|
164
|
+
|
|
165
|
+
payload = {
|
|
166
|
+
"name": "Implement authentication",
|
|
167
|
+
"project_code": code,
|
|
168
|
+
"partner_ref": self.project_task.partner_id.ref,
|
|
169
|
+
"properties": {"color": "red", "size": "large"},
|
|
170
|
+
}
|
|
171
|
+
with self._create_test_client(env=self.env) as test_client:
|
|
172
|
+
response = test_client.post(
|
|
173
|
+
f"/{self.url}", json=payload, headers=self.api_key_headers()
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
177
|
+
created = response.json()
|
|
178
|
+
self.assertEqual(created["task_properties"][0]["name"], "color")
|
|
179
|
+
self.assertEqual(
|
|
180
|
+
created["task_properties"][0]["value"], payload["properties"]["color"]
|
|
181
|
+
)
|
|
182
|
+
self.assertEqual(created["task_properties"][1]["name"], "size")
|
|
183
|
+
self.assertEqual(
|
|
184
|
+
created["task_properties"][1]["value"], payload["properties"]["size"]
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
def test_project_task_create_with_contract_code(self):
|
|
188
|
+
"""
|
|
189
|
+
Test the POST /project_tasks endpoint links the created task to the
|
|
190
|
+
contract carrying the given contract_code.
|
|
191
|
+
"""
|
|
192
|
+
code = "TESTCODE"
|
|
193
|
+
self.project_task.project_id.code = code
|
|
194
|
+
payload = {
|
|
195
|
+
"name": "SIM change",
|
|
196
|
+
"project_code": code,
|
|
197
|
+
"partner_ref": self.contract_partner.ref,
|
|
198
|
+
"contract_code": self.contract.code,
|
|
199
|
+
}
|
|
200
|
+
with self._create_test_client(env=self.env) as test_client:
|
|
201
|
+
response = test_client.post(
|
|
202
|
+
f"/{self.url}", json=payload, headers=self.api_key_headers()
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
206
|
+
created = response.json()
|
|
207
|
+
self.assertEqual(created["contract_code"], self.contract.code)
|
|
208
|
+
self.assertEqual(created["partner_id"], self.contract_partner.id)
|
|
209
|
+
task = self.env["project.task"].browse(created["id"])
|
|
210
|
+
self.assertEqual(task.contract_id, self.contract)
|
|
211
|
+
|
|
212
|
+
def test_project_task_create_with_contract_code_without_partner_ref(self):
|
|
213
|
+
"""
|
|
214
|
+
Test the POST /project_tasks endpoint takes the partner of the task
|
|
215
|
+
from the contract when the payload carries no partner_ref.
|
|
216
|
+
"""
|
|
217
|
+
code = "TESTCODE"
|
|
218
|
+
self.project_task.project_id.code = code
|
|
219
|
+
payload = {
|
|
220
|
+
"name": "SIM change",
|
|
221
|
+
"project_code": code,
|
|
222
|
+
"contract_code": self.contract.code,
|
|
223
|
+
}
|
|
224
|
+
with self._create_test_client(env=self.env) as test_client:
|
|
225
|
+
response = test_client.post(
|
|
226
|
+
f"/{self.url}", json=payload, headers=self.api_key_headers()
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
230
|
+
created = response.json()
|
|
231
|
+
self.assertEqual(created["partner_id"], self.contract_partner.id)
|
|
232
|
+
self.assertEqual(created["contract_code"], self.contract.code)
|
|
233
|
+
|
|
234
|
+
def test_project_task_create_contract_code_of_another_partner(self):
|
|
235
|
+
"""
|
|
236
|
+
Test the POST /project_tasks endpoint refuses a contract that is not
|
|
237
|
+
of the given partner_ref, the payload disagreeing with itself about
|
|
238
|
+
who the task is for.
|
|
239
|
+
"""
|
|
240
|
+
code = "TESTCODE"
|
|
241
|
+
self.project_task.project_id.code = code
|
|
242
|
+
payload = {
|
|
243
|
+
"name": "SIM change",
|
|
244
|
+
"project_code": code,
|
|
245
|
+
"partner_ref": self.partner.ref,
|
|
246
|
+
"contract_code": self.contract.code,
|
|
247
|
+
}
|
|
248
|
+
with self._create_test_client(env=self.env) as test_client:
|
|
249
|
+
response = test_client.post(
|
|
250
|
+
f"/{self.url}", json=payload, headers=self.api_key_headers()
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
|
|
254
|
+
self.assertEqual(
|
|
255
|
+
response.json()["detail"],
|
|
256
|
+
"Contract with code {} not found".format(self.contract.code),
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
def test_project_task_create_contract_code_not_found(self):
|
|
260
|
+
"""
|
|
261
|
+
Test the POST /project_tasks endpoint returns a 404 error when no
|
|
262
|
+
contract carries the given contract_code.
|
|
263
|
+
"""
|
|
264
|
+
code = "TESTCODE"
|
|
265
|
+
self.project_task.project_id.code = code
|
|
266
|
+
payload = {
|
|
267
|
+
"name": "SIM change",
|
|
268
|
+
"project_code": code,
|
|
269
|
+
"contract_code": "MISSINGCONTRACT",
|
|
270
|
+
}
|
|
271
|
+
with self._create_test_client(env=self.env) as test_client:
|
|
272
|
+
response = test_client.post(
|
|
273
|
+
f"/{self.url}", json=payload, headers=self.api_key_headers()
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
|
|
277
|
+
self.assertEqual(
|
|
278
|
+
response.json()["detail"],
|
|
279
|
+
"Contract with code MISSINGCONTRACT not found",
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
def test_project_task_create_without_partner_ref(self):
|
|
283
|
+
"""
|
|
284
|
+
Test the POST /project_tasks endpoint leaves the partner of the task
|
|
285
|
+
to Odoo when the payload names neither a partner_ref nor a
|
|
286
|
+
contract_code, instead of assigning it to the partner of the API key.
|
|
287
|
+
"""
|
|
288
|
+
code = "TESTCODE"
|
|
289
|
+
self.project_task.project_id.code = code
|
|
290
|
+
payload = {"name": "Implement authentication", "project_code": code}
|
|
291
|
+
with self._create_test_client(env=self.env) as test_client:
|
|
292
|
+
response = test_client.post(
|
|
293
|
+
f"/{self.url}", json=payload, headers=self.api_key_headers()
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
297
|
+
created = response.json()
|
|
298
|
+
api_key_partner = self.env.ref("fastapi_auth_api_key_sc.fastapi_partner")
|
|
299
|
+
self.assertNotEqual(created["partner_id"], api_key_partner.id)
|
|
300
|
+
self.assertEqual(
|
|
301
|
+
created["partner_id"], self.project_task.project_id.partner_id.id or None
|
|
302
|
+
)
|
|
303
|
+
|
|
304
|
+
def _attachments(self, task_id):
|
|
305
|
+
return (
|
|
306
|
+
self.env["ir.attachment"]
|
|
307
|
+
.sudo()
|
|
308
|
+
.search([("res_model", "=", "project.task"), ("res_id", "=", task_id)])
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
def test_project_task_create_with_documents(self):
|
|
312
|
+
"""
|
|
313
|
+
Test the POST /project_tasks endpoint attaches the files sent along
|
|
314
|
+
with the task to it, as they came.
|
|
315
|
+
"""
|
|
316
|
+
code = "TESTCODE"
|
|
317
|
+
self.project_task.project_id.code = code
|
|
318
|
+
content = base64.b64encode(b"%PDF-1.4 invoice").decode()
|
|
319
|
+
other_content = base64.b64encode(b"proof").decode()
|
|
320
|
+
payload = {
|
|
321
|
+
"name": "Implement authentication",
|
|
322
|
+
"project_code": code,
|
|
323
|
+
"documents": [
|
|
324
|
+
{"name": "invoice.pdf", "content": content},
|
|
325
|
+
{"name": "proof.txt", "content": other_content},
|
|
326
|
+
],
|
|
327
|
+
}
|
|
328
|
+
with self._create_test_client(env=self.env) as test_client:
|
|
329
|
+
response = test_client.post(
|
|
330
|
+
f"/{self.url}", json=payload, headers=self.api_key_headers()
|
|
331
|
+
)
|
|
332
|
+
|
|
333
|
+
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
334
|
+
attachments = self._attachments(response.json()["id"])
|
|
335
|
+
self.assertEqual(len(attachments), 2)
|
|
336
|
+
self.assertEqual(
|
|
337
|
+
sorted(attachments.mapped("name")), ["invoice.pdf", "proof.txt"]
|
|
338
|
+
)
|
|
339
|
+
invoice = attachments.filtered(lambda a: a.name == "invoice.pdf")
|
|
340
|
+
self.assertEqual(base64.b64decode(invoice.datas), b"%PDF-1.4 invoice")
|
|
341
|
+
|
|
342
|
+
def test_project_task_create_without_documents(self):
|
|
343
|
+
"""
|
|
344
|
+
Test the POST /project_tasks endpoint attaches nothing to a task
|
|
345
|
+
created with no documents.
|
|
346
|
+
"""
|
|
347
|
+
code = "TESTCODE"
|
|
348
|
+
self.project_task.project_id.code = code
|
|
349
|
+
payload = {"name": "Implement authentication", "project_code": code}
|
|
350
|
+
with self._create_test_client(env=self.env) as test_client:
|
|
351
|
+
response = test_client.post(
|
|
352
|
+
f"/{self.url}", json=payload, headers=self.api_key_headers()
|
|
353
|
+
)
|
|
354
|
+
|
|
355
|
+
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
356
|
+
self.assertFalse(self._attachments(response.json()["id"]))
|
|
357
|
+
|
|
358
|
+
def test_project_task_create_with_document_not_base64(self):
|
|
359
|
+
"""
|
|
360
|
+
Test the POST /project_tasks endpoint rejects a file that is not
|
|
361
|
+
base64 encoded rather than creating the task with an attachment
|
|
362
|
+
nobody can open.
|
|
363
|
+
"""
|
|
364
|
+
code = "TESTCODE"
|
|
365
|
+
self.project_task.project_id.code = code
|
|
366
|
+
name = "Task with a broken document"
|
|
367
|
+
payload = {
|
|
368
|
+
"name": name,
|
|
369
|
+
"project_code": code,
|
|
370
|
+
"documents": [{"name": "invoice.pdf", "content": "not base64"}],
|
|
371
|
+
}
|
|
372
|
+
with self._create_test_client(env=self.env) as test_client:
|
|
373
|
+
response = test_client.post(
|
|
374
|
+
f"/{self.url}", json=payload, headers=self.api_key_headers()
|
|
375
|
+
)
|
|
376
|
+
|
|
377
|
+
self.assertEqual(response.status_code, status.HTTP_422_UNPROCESSABLE_ENTITY)
|
|
378
|
+
self.assertIn(
|
|
379
|
+
"content is not base64 encoded", response.json()["detail"][0]["msg"]
|
|
380
|
+
)
|
|
381
|
+
self.assertFalse(self.env["project.task"].sudo().search([("name", "=", name)]))
|
|
382
|
+
|
|
383
|
+
def test_project_task_create_project_code_not_found(self):
|
|
384
|
+
"""
|
|
385
|
+
Test the POST /project_tasks endpoint returns a 404 error when no
|
|
386
|
+
project carries the given project_code.
|
|
387
|
+
"""
|
|
388
|
+
code = "MISSINGCODE"
|
|
389
|
+
payload = {
|
|
390
|
+
"name": "Implement authentication",
|
|
391
|
+
"project_code": code,
|
|
392
|
+
"partner_ref": self.project_task.partner_id.ref,
|
|
393
|
+
}
|
|
394
|
+
with self._create_test_client(env=self.env) as test_client:
|
|
395
|
+
response = test_client.post(
|
|
396
|
+
f"/{self.url}", json=payload, headers=self.api_key_headers()
|
|
397
|
+
)
|
|
398
|
+
|
|
399
|
+
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
|
|
400
|
+
self.assertEqual(
|
|
401
|
+
response.json()["detail"],
|
|
402
|
+
"Project record with code {} not found".format(code),
|
|
403
|
+
)
|
|
404
|
+
|
|
405
|
+
def test_project_task_update(self):
|
|
406
|
+
"""
|
|
407
|
+
Test the PUT /project_tasks/{record_id} endpoint updates a project
|
|
408
|
+
task's regular fields.
|
|
409
|
+
"""
|
|
410
|
+
payload = {"name": "Updated task name", "priority": "1"}
|
|
411
|
+
with self._create_test_client(env=self.env) as test_client:
|
|
412
|
+
response = test_client.put(
|
|
413
|
+
f"/{self.url}/{self.project_task.id}",
|
|
414
|
+
json=payload,
|
|
415
|
+
headers=self.api_key_headers(),
|
|
416
|
+
)
|
|
417
|
+
|
|
418
|
+
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
419
|
+
updated = response.json()
|
|
420
|
+
self.assertEqual(updated["name"], payload["name"])
|
|
421
|
+
self.assertEqual(updated["priority"], payload["priority"])
|
|
422
|
+
self.assertEqual(self.project_task.name, payload["name"])
|
|
423
|
+
|
|
424
|
+
def test_project_task_update_contract_code(self):
|
|
425
|
+
"""
|
|
426
|
+
Test the PUT /project_tasks/{record_id} endpoint links the task to the
|
|
427
|
+
contract carrying the given contract_code.
|
|
428
|
+
"""
|
|
429
|
+
payload = {
|
|
430
|
+
"partner_ref": self.contract_partner.ref,
|
|
431
|
+
"contract_code": self.contract.code,
|
|
432
|
+
}
|
|
433
|
+
with self._create_test_client(env=self.env) as test_client:
|
|
434
|
+
response = test_client.put(
|
|
435
|
+
f"/{self.url}/{self.project_task.id}",
|
|
436
|
+
json=payload,
|
|
437
|
+
headers=self.api_key_headers(),
|
|
438
|
+
)
|
|
439
|
+
|
|
440
|
+
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
441
|
+
self.assertEqual(response.json()["contract_code"], self.contract.code)
|
|
442
|
+
self.assertEqual(self.project_task.contract_id, self.contract)
|
|
443
|
+
self.assertEqual(self.project_task.partner_id, self.contract_partner)
|
|
444
|
+
|
|
445
|
+
def test_project_task_update_contract_code_without_partner_ref(self):
|
|
446
|
+
"""
|
|
447
|
+
Test the PUT /project_tasks/{record_id} endpoint moves the task to the
|
|
448
|
+
partner of the contract when the payload carries no partner_ref.
|
|
449
|
+
"""
|
|
450
|
+
payload = {"contract_code": self.contract.code}
|
|
451
|
+
with self._create_test_client(env=self.env) as test_client:
|
|
452
|
+
response = test_client.put(
|
|
453
|
+
f"/{self.url}/{self.project_task.id}",
|
|
454
|
+
json=payload,
|
|
455
|
+
headers=self.api_key_headers(),
|
|
456
|
+
)
|
|
457
|
+
|
|
458
|
+
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
459
|
+
self.assertEqual(response.json()["partner_id"], self.contract_partner.id)
|
|
460
|
+
self.assertEqual(self.project_task.partner_id, self.contract_partner)
|
|
461
|
+
|
|
462
|
+
def test_project_task_update_contract_code_of_another_partner(self):
|
|
463
|
+
"""
|
|
464
|
+
Test the PUT /project_tasks/{record_id} endpoint refuses a contract
|
|
465
|
+
that is not of the given partner_ref, and leaves the task untouched.
|
|
466
|
+
"""
|
|
467
|
+
payload = {
|
|
468
|
+
"partner_ref": self.partner.ref,
|
|
469
|
+
"contract_code": self.contract.code,
|
|
470
|
+
}
|
|
471
|
+
with self._create_test_client(env=self.env) as test_client:
|
|
472
|
+
response = test_client.put(
|
|
473
|
+
f"/{self.url}/{self.project_task.id}",
|
|
474
|
+
json=payload,
|
|
475
|
+
headers=self.api_key_headers(),
|
|
476
|
+
)
|
|
477
|
+
|
|
478
|
+
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
|
|
479
|
+
self.assertEqual(
|
|
480
|
+
response.json()["detail"],
|
|
481
|
+
"Contract with code {} not found".format(self.contract.code),
|
|
482
|
+
)
|
|
483
|
+
self.assertFalse(self.project_task.contract_id)
|
|
484
|
+
|
|
485
|
+
def test_project_task_update_properties(self):
|
|
486
|
+
"""
|
|
487
|
+
Test the PUT /project_tasks/{record_id} endpoint saves the given
|
|
488
|
+
properties while keeping the ones not sent untouched.
|
|
489
|
+
"""
|
|
490
|
+
self.project_task.project_id.task_properties_definition = [
|
|
491
|
+
{"name": "esim_activation_code", "string": "Urgent", "type": "char"},
|
|
492
|
+
{"name": "notes", "string": "Notes", "type": "char"},
|
|
493
|
+
]
|
|
494
|
+
self.project_task.task_properties = {
|
|
495
|
+
"esim_activation_code": False,
|
|
496
|
+
"notes": "old note",
|
|
497
|
+
}
|
|
498
|
+
payload = {"properties": {"esim_activation_code": "hello@hello.com"}}
|
|
499
|
+
|
|
500
|
+
with self._create_test_client(env=self.env) as test_client:
|
|
501
|
+
response = test_client.put(
|
|
502
|
+
f"/{self.url}/{self.project_task.id}",
|
|
503
|
+
json=payload,
|
|
504
|
+
headers=self.api_key_headers(),
|
|
505
|
+
)
|
|
506
|
+
|
|
507
|
+
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
508
|
+
properties = {
|
|
509
|
+
prop["name"]: prop["value"] for prop in self.project_task.task_properties
|
|
510
|
+
}
|
|
511
|
+
self.assertEqual(
|
|
512
|
+
properties["esim_activation_code"],
|
|
513
|
+
payload["properties"]["esim_activation_code"],
|
|
514
|
+
)
|
|
515
|
+
self.assertEqual(properties["notes"], "old note")
|
|
516
|
+
|
|
517
|
+
def test_project_task_update_unknown_property(self):
|
|
518
|
+
"""
|
|
519
|
+
Test the PUT /project_tasks/{record_id} endpoint returns a 400 error
|
|
520
|
+
when a property is not defined on the task's project.
|
|
521
|
+
"""
|
|
522
|
+
self.project_task.project_id.task_properties_definition = [
|
|
523
|
+
{"name": "urgent", "string": "Urgent", "type": "boolean"},
|
|
524
|
+
]
|
|
525
|
+
self.project_task.task_properties = {"urgent": False}
|
|
526
|
+
|
|
527
|
+
payload = {"properties": {"unknown_prop": True}}
|
|
528
|
+
with self._create_test_client(env=self.env) as test_client:
|
|
529
|
+
response = test_client.put(
|
|
530
|
+
f"/{self.url}/{self.project_task.id}",
|
|
531
|
+
json=payload,
|
|
532
|
+
headers=self.api_key_headers(),
|
|
533
|
+
)
|
|
534
|
+
|
|
535
|
+
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
|
536
|
+
self.assertIn("unknown_prop", response.json()["detail"])
|
|
537
|
+
|
|
538
|
+
def test_project_task_update_not_found(self):
|
|
539
|
+
"""
|
|
540
|
+
Test the PUT /project_tasks/{record_id} endpoint returns a 404 error
|
|
541
|
+
when the project task does not exist.
|
|
542
|
+
"""
|
|
543
|
+
payload = {"name": "Updated task name"}
|
|
544
|
+
with self._create_test_client(env=self.env) as test_client:
|
|
545
|
+
response = test_client.put(
|
|
546
|
+
f"/{self.url}/999999",
|
|
547
|
+
json=payload,
|
|
548
|
+
headers=self.api_key_headers(),
|
|
549
|
+
)
|
|
550
|
+
|
|
551
|
+
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: odoo-addon-project_task_api
|
|
3
|
+
Version: 16.0.1.1.2
|
|
4
|
+
Requires-Python: >=3.10
|
|
5
|
+
Requires-Dist: fastapi
|
|
6
|
+
Requires-Dist: odoo-addon-fastapi_auth_api_key_sc>=16.0dev,<16.1dev
|
|
7
|
+
Requires-Dist: odoo-addon-project_task_contract>=16.0dev,<16.1dev
|
|
8
|
+
Requires-Dist: odoo>=16.0a,<16.1dev
|
|
9
|
+
Requires-Dist: pydantic
|
|
10
|
+
Summary: API module based on FastAPI to get and create project tasks from external applications
|
|
11
|
+
Home-page: https://git.coopdevs.org/coopdevs/som-connexio/odoo/odoo-custom-modules
|
|
12
|
+
License: AGPL-3
|
|
13
|
+
Author: =?utf-8?q?Som_Connexi=C3=B3_SCCL=2C_Odoo_Community_Association_=28OCA=29?=
|
|
14
|
+
Author-email: support@odoo-community.org
|
|
15
|
+
Classifier: Programming Language :: Python
|
|
16
|
+
Classifier: Framework :: Odoo
|
|
17
|
+
Classifier: Framework :: Odoo :: 16.0
|
|
18
|
+
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
|
|
19
|
+
Description-Content-Type: text/x-rst
|
|
20
|
+
|
|
21
|
+
##################
|
|
22
|
+
Project Task API
|
|
23
|
+
##################
|
|
24
|
+
|
|
25
|
+
This module uses OCAs FAST API module for creating endpoints to get and
|
|
26
|
+
create project tasks from external applications.
|
|
27
|
+
|
|
28
|
+
.. note::
|
|
29
|
+
|
|
30
|
+
This module is made by and for developers.
|
|
31
|
+
|
|
32
|
+
**Table of contents**
|
|
33
|
+
|
|
34
|
+
.. contents::
|
|
35
|
+
:local:
|
|
36
|
+
|
|
37
|
+
***************
|
|
38
|
+
Configuration
|
|
39
|
+
***************
|
|
40
|
+
|
|
41
|
+
As this module is based on `fastapi_auth_api_key_sc`, an API-KEY is
|
|
42
|
+
required to authenticate requests. Read README from
|
|
43
|
+
`fastapi_auth_api_key_sc` for more information about the user related
|
|
44
|
+
API-KEY authentication.
|
|
45
|
+
|
|
46
|
+
*******
|
|
47
|
+
Usage
|
|
48
|
+
*******
|
|
49
|
+
|
|
50
|
+
This module provides FastAPI-based endpoints of project tasks by
|
|
51
|
+
extending `fastapi.endpoint`.
|
|
52
|
+
|
|
53
|
+
The module registers the following routes:
|
|
54
|
+
|
|
55
|
+
- GET: `/api/project_tasks`
|
|
56
|
+
- POST: `/api/project_tasks`
|
|
57
|
+
- GET: `/api/project_tasks/{id}`
|
|
58
|
+
- PUT: `/api/project_tasks/{id}`
|
|
59
|
+
|
|
60
|
+
The authenticated API uses `API-KEY`
|
|
61
|
+
|
|
62
|
+
Other modules can serve their own routes under `/api/project_tasks`,
|
|
63
|
+
with the same authentication, by extending
|
|
64
|
+
`fastapi.endpoint._get_project_task_routers` to add their router. Their
|
|
65
|
+
routes are relative to `/project_tasks`, so the router does not set the
|
|
66
|
+
prefix itself:
|
|
67
|
+
|
|
68
|
+
.. code:: python
|
|
69
|
+
|
|
70
|
+
new_project_router = APIRouter()
|
|
71
|
+
|
|
72
|
+
@new_project_router.post("/new-project") # POST /api/project_tasks/new-project
|
|
73
|
+
def create_task_new_project(...):
|
|
74
|
+
...
|
|
75
|
+
|
|
76
|
+
class FastapiEndpoint(models.Model):
|
|
77
|
+
_inherit = "fastapi.endpoint"
|
|
78
|
+
|
|
79
|
+
@api.model
|
|
80
|
+
def _get_project_task_routers(self):
|
|
81
|
+
return super()._get_project_task_routers() + [new_project_router]
|
|
82
|
+
|
|
83
|
+
Their tests build the test client with
|
|
84
|
+
`env["fastapi.endpoint"]._get_project_tasks_router()`, so the routes are
|
|
85
|
+
tested at their full path.
|
|
86
|
+
|
|
87
|
+
************************
|
|
88
|
+
Known issues / Roadmap
|
|
89
|
+
************************
|
|
90
|
+
|
|
91
|
+
There are no known issues for this module.
|
|
92
|
+
|
|
93
|
+
*************
|
|
94
|
+
Bug Tracker
|
|
95
|
+
*************
|
|
96
|
+
|
|
97
|
+
Bugs are tracked on `GitLab Issues
|
|
98
|
+
<https://gitlab.com/somitcoop/erp-research/odoo-helpdesk/-/issues>`_. In
|
|
99
|
+
case of trouble, please check there if your issue has already been
|
|
100
|
+
reported. If you spotted it first, help us smashing it by providing a
|
|
101
|
+
detailed and welcomed feedback.
|
|
102
|
+
|
|
103
|
+
Do not contact contributors directly about support or help with
|
|
104
|
+
technical issues.
|
|
105
|
+
|
|
106
|
+
TODO: Module to be substituted by `the OCA module`_ once this ODOO is
|
|
107
|
+
migrated to the 17th version or further.
|
|
108
|
+
|
|
109
|
+
.. _the oca module: https://github.com/OCA/rest-framework/tree/17.0/fastapi_auth_api_key/
|
|
110
|
+
|
|
111
|
+
*********
|
|
112
|
+
Credits
|
|
113
|
+
*********
|
|
114
|
+
|
|
115
|
+
Authors
|
|
116
|
+
=======
|
|
117
|
+
|
|
118
|
+
- Som Connexio SCCL
|
|
119
|
+
|
|
120
|
+
Contributors
|
|
121
|
+
============
|
|
122
|
+
|
|
123
|
+
- `Som Connexio SCCL <https://somconnexio.coop>`_:
|
|
124
|
+
|
|
125
|
+
- Gerard Funosas <gerard.funosas@somconnexio.coop>
|
|
126
|
+
|
|
127
|
+
Maintainers
|
|
128
|
+
===========
|
|
129
|
+
|
|
130
|
+
This module is maintained by the OCA.
|
|
131
|
+
|
|
132
|
+
.. image:: https://odoo-community.org/logo.png
|
|
133
|
+
:alt: Odoo Community Association
|
|
134
|
+
:target: https://odoo-community.org
|
|
135
|
+
|
|
136
|
+
OCA, or the Odoo Community Association, is a nonprofit organization
|
|
137
|
+
whose mission is to support the collaborative development of Odoo
|
|
138
|
+
features and promote its widespread use.
|
|
139
|
+
|
|
140
|
+
You are welcome to contribute. To learn how please visit
|
|
141
|
+
https://odoo-community.org/page/Contribute.
|