iatoolkit 0.7.11__py3-none-any.whl → 0.7.14__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.
Potentially problematic release.
This version of iatoolkit might be problematic. Click here for more details.
- iatoolkit/cli_commands.py +1 -1
- iatoolkit/iatoolkit.py +14 -16
- {iatoolkit-0.7.11.dist-info → iatoolkit-0.7.14.dist-info}/METADATA +1 -1
- {iatoolkit-0.7.11.dist-info → iatoolkit-0.7.14.dist-info}/RECORD +72 -6
- {iatoolkit-0.7.11.dist-info → iatoolkit-0.7.14.dist-info}/top_level.txt +1 -0
- tests/__init__.py +5 -0
- tests/common/__init__.py +0 -0
- tests/common/test_auth.py +279 -0
- tests/common/test_routes.py +42 -0
- tests/common/test_session_manager.py +59 -0
- tests/common/test_util.py +444 -0
- tests/companies/__init__.py +5 -0
- tests/conftest.py +36 -0
- tests/infra/__init__.py +5 -0
- tests/infra/connectors/__init__.py +5 -0
- tests/infra/connectors/test_google_drive_connector.py +107 -0
- tests/infra/connectors/test_local_file_connector.py +85 -0
- tests/infra/connectors/test_s3_connector.py +95 -0
- tests/infra/test_call_service.py +92 -0
- tests/infra/test_database_manager.py +59 -0
- tests/infra/test_gemini_adapter.py +137 -0
- tests/infra/test_google_chat_app.py +68 -0
- tests/infra/test_llm_client.py +165 -0
- tests/infra/test_llm_proxy.py +122 -0
- tests/infra/test_mail_app.py +94 -0
- tests/infra/test_openai_adapter.py +105 -0
- tests/infra/test_redis_session_manager_service.py +117 -0
- tests/repositories/__init__.py +5 -0
- tests/repositories/test_database_manager.py +87 -0
- tests/repositories/test_document_repo.py +76 -0
- tests/repositories/test_llm_query_repo.py +340 -0
- tests/repositories/test_models.py +38 -0
- tests/repositories/test_profile_repo.py +142 -0
- tests/repositories/test_tasks_repo.py +76 -0
- tests/repositories/test_vs_repo.py +107 -0
- tests/services/__init__.py +5 -0
- tests/services/test_dispatcher_service.py +274 -0
- tests/services/test_document_service.py +181 -0
- tests/services/test_excel_service.py +208 -0
- tests/services/test_file_processor_service.py +121 -0
- tests/services/test_history_service.py +164 -0
- tests/services/test_jwt_service.py +255 -0
- tests/services/test_load_documents_service.py +112 -0
- tests/services/test_mail_service.py +70 -0
- tests/services/test_profile_service.py +379 -0
- tests/services/test_prompt_manager_service.py +190 -0
- tests/services/test_query_service.py +243 -0
- tests/services/test_search_service.py +39 -0
- tests/services/test_sql_service.py +160 -0
- tests/services/test_tasks_service.py +252 -0
- tests/services/test_user_feedback_service.py +389 -0
- tests/services/test_user_session_context_service.py +132 -0
- tests/views/__init__.py +5 -0
- tests/views/test_change_password_view.py +191 -0
- tests/views/test_chat_token_request_view.py +188 -0
- tests/views/test_chat_view.py +98 -0
- tests/views/test_download_file_view.py +149 -0
- tests/views/test_external_chat_login_view.py +120 -0
- tests/views/test_external_login_view.py +102 -0
- tests/views/test_file_store_view.py +128 -0
- tests/views/test_forgot_password_view.py +142 -0
- tests/views/test_history_view.py +336 -0
- tests/views/test_home_view.py +61 -0
- tests/views/test_llm_query_view.py +154 -0
- tests/views/test_login_view.py +114 -0
- tests/views/test_prompt_view.py +111 -0
- tests/views/test_signup_view.py +140 -0
- tests/views/test_tasks_review_view.py +104 -0
- tests/views/test_tasks_view.py +130 -0
- tests/views/test_user_feedback_view.py +214 -0
- tests/views/test_verify_user_view.py +110 -0
- {iatoolkit-0.7.11.dist-info → iatoolkit-0.7.14.dist-info}/WHEEL +0 -0
iatoolkit/cli_commands.py
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import click
|
|
7
7
|
import logging
|
|
8
8
|
from iatoolkit import IAToolkit
|
|
9
|
-
from iatoolkit.services import ProfileService
|
|
9
|
+
from iatoolkit.services.profile_service import ProfileService
|
|
10
10
|
|
|
11
11
|
def register_core_commands(app):
|
|
12
12
|
"""Registra los comandos CLI del núcleo de IAToolkit."""
|
iatoolkit/iatoolkit.py
CHANGED
|
@@ -264,15 +264,15 @@ class IAToolkit:
|
|
|
264
264
|
binder.bind(TaskRepo, to=TaskRepo)
|
|
265
265
|
|
|
266
266
|
def _bind_services(self, binder: Binder):
|
|
267
|
-
from iatoolkit.services import QueryService
|
|
267
|
+
from iatoolkit.services.query_service import QueryService
|
|
268
268
|
from iatoolkit.services.tasks_service import TaskService
|
|
269
|
-
from iatoolkit.services import BenchmarkService
|
|
269
|
+
from iatoolkit.services.benchmark_service import BenchmarkService
|
|
270
270
|
from iatoolkit.services.document_service import DocumentService
|
|
271
271
|
from iatoolkit.services.prompt_manager_service import PromptService
|
|
272
272
|
from iatoolkit.services.excel_service import ExcelService
|
|
273
|
-
from iatoolkit.services import MailService
|
|
273
|
+
from iatoolkit.services.mail_service import MailService
|
|
274
274
|
from iatoolkit.services.load_documents_service import LoadDocumentsService
|
|
275
|
-
from iatoolkit.services import ProfileService
|
|
275
|
+
from iatoolkit.services.profile_service import ProfileService
|
|
276
276
|
from iatoolkit.services.jwt_service import JWTService
|
|
277
277
|
from iatoolkit.services.dispatcher_service import Dispatcher
|
|
278
278
|
|
|
@@ -290,10 +290,10 @@ class IAToolkit:
|
|
|
290
290
|
|
|
291
291
|
def _bind_infrastructure(self, binder: Binder):
|
|
292
292
|
from iatoolkit.infra.llm_client import llmClient
|
|
293
|
-
from iatoolkit.infra import LLMProxy
|
|
294
|
-
from iatoolkit.infra import GoogleChatApp
|
|
293
|
+
from iatoolkit.infra.llm_proxy import LLMProxy
|
|
294
|
+
from iatoolkit.infra.google_chat_app import GoogleChatApp
|
|
295
295
|
from iatoolkit.infra.mail_app import MailApp
|
|
296
|
-
from iatoolkit.common import IAuthentication
|
|
296
|
+
from iatoolkit.common.auth import IAuthentication
|
|
297
297
|
from iatoolkit.common.util import Utility
|
|
298
298
|
|
|
299
299
|
|
|
@@ -307,10 +307,10 @@ class IAToolkit:
|
|
|
307
307
|
|
|
308
308
|
def _bind_views(self, binder: Binder):
|
|
309
309
|
"""Vincula las vistas después de que el injector ha sido creado"""
|
|
310
|
-
from iatoolkit.views import LLMQueryView
|
|
311
|
-
from iatoolkit.views import HomeView
|
|
312
|
-
from iatoolkit.views import ChatView
|
|
313
|
-
from iatoolkit.views import ChangePasswordView
|
|
310
|
+
from iatoolkit.views.llmquery_view import LLMQueryView
|
|
311
|
+
from iatoolkit.views.home_view import HomeView
|
|
312
|
+
from iatoolkit.views.chat_view import ChatView
|
|
313
|
+
from iatoolkit.views.change_password_view import ChangePasswordView
|
|
314
314
|
|
|
315
315
|
binder.bind(HomeView, to=HomeView)
|
|
316
316
|
binder.bind(ChatView, to=ChatView)
|
|
@@ -355,7 +355,7 @@ class IAToolkit:
|
|
|
355
355
|
# Configura context processors para templates
|
|
356
356
|
@self.app.context_processor
|
|
357
357
|
def inject_globals():
|
|
358
|
-
from iatoolkit.common import SessionManager
|
|
358
|
+
from iatoolkit.common.session_manager import SessionManager
|
|
359
359
|
return {
|
|
360
360
|
'url_for': url_for,
|
|
361
361
|
'iatoolkit_version': self.version,
|
|
@@ -367,16 +367,14 @@ class IAToolkit:
|
|
|
367
367
|
def _get_default_static_folder(self) -> str:
|
|
368
368
|
try:
|
|
369
369
|
current_dir = os.path.dirname(os.path.abspath(__file__)) # .../src/iatoolkit
|
|
370
|
-
|
|
371
|
-
return os.path.join(src_dir, "static")
|
|
370
|
+
return os.path.join(current_dir, "static")
|
|
372
371
|
except:
|
|
373
372
|
return 'static'
|
|
374
373
|
|
|
375
374
|
def _get_default_template_folder(self) -> str:
|
|
376
375
|
try:
|
|
377
376
|
current_dir = os.path.dirname(os.path.abspath(__file__)) # .../src/iatoolkit
|
|
378
|
-
|
|
379
|
-
return os.path.join(src_dir, "templates")
|
|
377
|
+
return os.path.join(current_dir, "templates")
|
|
380
378
|
except:
|
|
381
379
|
return 'templates'
|
|
382
380
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
iatoolkit/__init__.py,sha256=yi7Uw68KajDWUUo-v4xV31Nt7hjr_-2gCXbkhdiDl44,1887
|
|
2
2
|
iatoolkit/base_company.py,sha256=gM3X7xedNaVLodOObvjUN9eJKPO5-HmSLaBFa9jowCk,4277
|
|
3
|
-
iatoolkit/cli_commands.py,sha256=
|
|
3
|
+
iatoolkit/cli_commands.py,sha256=G5L9xQXZ0lVFXQWBaE_KEZHyfuiT6PL1nTQRoSdnBzc,2302
|
|
4
4
|
iatoolkit/company_registry.py,sha256=tduqt3oV8iDX_IB1eA7KIgvIxE4edTcy-3qZIXh3Lzw,2549
|
|
5
|
-
iatoolkit/iatoolkit.py,sha256=
|
|
5
|
+
iatoolkit/iatoolkit.py,sha256=UTixRTy0HoOMfO01H58IhC6BJFfZFZU_cbyOA25gkmM,15888
|
|
6
6
|
iatoolkit/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
7
|
iatoolkit/common/auth.py,sha256=8NH6MQXfddLQd1GxrO2op3IYrrP4SMQKoKzj1o1jZmc,8486
|
|
8
8
|
iatoolkit/common/exceptions.py,sha256=EXx40n5htp7UiOM6P1xfJ9U6NMcADqm62dlFaKz7ICU,1154
|
|
@@ -122,7 +122,73 @@ iatoolkit/views/tasks_review_view.py,sha256=keLsLCyOTTlcoIapnB_lbuSvLwrPVZVpBiFC
|
|
|
122
122
|
iatoolkit/views/tasks_view.py,sha256=a3anTXrJTTvbQuc6PSpOzidLKQFL4hWa7PI2Cppcz8w,4110
|
|
123
123
|
iatoolkit/views/user_feedback_view.py,sha256=G37zmP8P4LvZrSymNJ5iFXhLZg1A3BEwRfTpH1Iam5w,2652
|
|
124
124
|
iatoolkit/views/verify_user_view.py,sha256=a3q4wHJ8mKAEmgbNTOcnX4rMikROjOR3mHvCr30qGGA,2351
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
tests/__init__.py,sha256=5JqK9sZ6jBuK83zDQokUhxQ0wuJJJ9DXB8pYCLkX7X4,102
|
|
126
|
+
tests/conftest.py,sha256=S000Ry-rWczEDsndTtOvsj2zf2EYgjHi78oVn60hoOU,1094
|
|
127
|
+
tests/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
128
|
+
tests/common/test_auth.py,sha256=WViWPG3E8OldgZyPbl-lp5rosjgPQb9MlADGLr1rq4k,14338
|
|
129
|
+
tests/common/test_routes.py,sha256=_Fz8mYqxp8YZ39CSng0CQOIRs9fOfgC42iU9XiHLMzU,1560
|
|
130
|
+
tests/common/test_session_manager.py,sha256=8FLa8Z7ueLYNnJeJyTgCm8pp1DY6QvC0b0ZxZC2vpKc,2388
|
|
131
|
+
tests/common/test_util.py,sha256=SMh0pSIv8K-bCeMZeYBbCD70o6MpOUXHQH6kZFLLN5c,20653
|
|
132
|
+
tests/companies/__init__.py,sha256=5JqK9sZ6jBuK83zDQokUhxQ0wuJJJ9DXB8pYCLkX7X4,102
|
|
133
|
+
tests/infra/__init__.py,sha256=5JqK9sZ6jBuK83zDQokUhxQ0wuJJJ9DXB8pYCLkX7X4,102
|
|
134
|
+
tests/infra/test_call_service.py,sha256=p5kFqXFojSmHucLTyika2u3wvpQwJRCrAlVOPeohoVE,3747
|
|
135
|
+
tests/infra/test_database_manager.py,sha256=SMU_pcCsW89b6GyykAU2LEO8UaHL9gO5rdeWGFP3A6g,2503
|
|
136
|
+
tests/infra/test_gemini_adapter.py,sha256=gMjSgxh854sC08vYQpH6QSIX9w921U3g_Jrt_HU1i1Y,6292
|
|
137
|
+
tests/infra/test_google_chat_app.py,sha256=D1iUaGy8Z-PHufJuQ607lGEUOFueedoziXR8J9b7qmM,2363
|
|
138
|
+
tests/infra/test_llm_client.py,sha256=i5uRPy3k2csoNOg16dlVAaZq93MDTk5OxLgRPrsyDow,7619
|
|
139
|
+
tests/infra/test_llm_proxy.py,sha256=Y9F8ozVsnPLOiIt_Minr_VvANEz0x0JIPvFaWJBCLgk,5753
|
|
140
|
+
tests/infra/test_mail_app.py,sha256=6Mhj3HbnQ_sVaQc7wgTpIEFb2GAzc4kkFNWgPWBCmp0,3727
|
|
141
|
+
tests/infra/test_openai_adapter.py,sha256=4CLLIOqQLaC_zpc3clyoA9fiMu5uJmfDoPqs7hEw4Qo,4319
|
|
142
|
+
tests/infra/test_redis_session_manager_service.py,sha256=NbrUVxmEmWIZc9TtnFd1IiWwm1N0Ih0y7chP7z5Mx34,4914
|
|
143
|
+
tests/infra/connectors/__init__.py,sha256=5JqK9sZ6jBuK83zDQokUhxQ0wuJJJ9DXB8pYCLkX7X4,102
|
|
144
|
+
tests/infra/connectors/test_google_drive_connector.py,sha256=UxbR64xiDpFyeE18--BHiKgvwEuaWt9b4Cf6bL6LreM,4434
|
|
145
|
+
tests/infra/connectors/test_local_file_connector.py,sha256=-1wpjXt2DOn_NbSUerdGFd-g-NI3rWS5vDoL3PFqxGA,3459
|
|
146
|
+
tests/infra/connectors/test_s3_connector.py,sha256=2hsJvKPyTWQj6kkNjtpRwsLNdvW3O5N5JlhzUM67x5Q,3512
|
|
147
|
+
tests/repositories/__init__.py,sha256=5JqK9sZ6jBuK83zDQokUhxQ0wuJJJ9DXB8pYCLkX7X4,102
|
|
148
|
+
tests/repositories/test_database_manager.py,sha256=C6pqzxPCtk0DcZE7VNaFCT5ahONO7mWFKDo1bxb-9sU,3990
|
|
149
|
+
tests/repositories/test_document_repo.py,sha256=sqNL5yVM_8phPaxcYR3FupuTWN5RNG8yLfeDxR07uIM,2543
|
|
150
|
+
tests/repositories/test_llm_query_repo.py,sha256=Vdu85MI_L7Nh5ksNz9X3d4hORp9hXaXPwH1AUbuN5YE,13228
|
|
151
|
+
tests/repositories/test_models.py,sha256=CJbz3U89BgPKmP61pwGdwDW8vHvPROKwYfqcg4lx-_Q,1627
|
|
152
|
+
tests/repositories/test_profile_repo.py,sha256=Ex9R5JH2uyam8dt8Nl-1yiNYYj72Ma9A3Jlo_JkwktI,4981
|
|
153
|
+
tests/repositories/test_tasks_repo.py,sha256=ZtOOjJTb_j8dKEpirZTQAnR9fhDDO7xQWZU710So9Bk,2769
|
|
154
|
+
tests/repositories/test_vs_repo.py,sha256=PGN5PqQBtlwMC_UFU3qMSqxtoBSNz1YvZK4yYj0O0UU,4595
|
|
155
|
+
tests/services/__init__.py,sha256=5JqK9sZ6jBuK83zDQokUhxQ0wuJJJ9DXB8pYCLkX7X4,102
|
|
156
|
+
tests/services/test_dispatcher_service.py,sha256=iALQx0I94SehG4eXqwvdswyYrPVShXFIlk-GwwbWyzw,13086
|
|
157
|
+
tests/services/test_document_service.py,sha256=Z62VjjIn1EPgDT2_2jEVI6AQoO3yOdskc_FDqlvML1Q,8085
|
|
158
|
+
tests/services/test_excel_service.py,sha256=7Gyy82MFqOVFIGL7RXMIOmal22ne-lsgAfY16azDAMM,8434
|
|
159
|
+
tests/services/test_file_processor_service.py,sha256=XzdA581hoAhevp8atqgI7jxTY1gmHE7rnMllihRS9S0,4794
|
|
160
|
+
tests/services/test_history_service.py,sha256=VF6IgogsgaFe64LNDeXMFcLrWjuGLf3Vj_srnFfkneM,7273
|
|
161
|
+
tests/services/test_jwt_service.py,sha256=3TYtuPk1ps0aa5TKGvd30Q4F7Q1FEsqK6Gr1wjW8-q8,10325
|
|
162
|
+
tests/services/test_load_documents_service.py,sha256=zDcHSXVQAdtAZCVWecTl-pYlkA4Sp8JLxKpu82LB69A,4640
|
|
163
|
+
tests/services/test_mail_service.py,sha256=PPy5XA2lYFFBNdmU1Ea-cfqszwQZrrqZSZU1OQ26lDE,2295
|
|
164
|
+
tests/services/test_profile_service.py,sha256=WzvVxeK5AYUDWJLBRB43vVDLHi64cIkPYPcynMEGZzM,14831
|
|
165
|
+
tests/services/test_prompt_manager_service.py,sha256=B6j12RNjljAKZnd7vy1CNAdZxwKiTWD5l4uxOGKVuvE,9395
|
|
166
|
+
tests/services/test_query_service.py,sha256=vq8dhteJOFiA0eGo1s5eBzasx7noZFrv96XdKFKhmS8,11331
|
|
167
|
+
tests/services/test_search_service.py,sha256=n8C5mjDDCVX4NAJvS3mKgw-WsLWu5qUA8eTOxy-g9NU,1183
|
|
168
|
+
tests/services/test_sql_service.py,sha256=bHDiPzjfM7-mbM4eEXlMVk3vcvefhlGCx3bdIrlriVM,7753
|
|
169
|
+
tests/services/test_tasks_service.py,sha256=V_WcglSX4CAtOkkKhZKl7Q92LsODHLRu66TqydiSQP4,10598
|
|
170
|
+
tests/services/test_user_feedback_service.py,sha256=HMU75j48jT-Chls78QEXoq92Hpq7TXP-m8xXIAL0rK0,15859
|
|
171
|
+
tests/services/test_user_session_context_service.py,sha256=c49RqHuoY6W_u-eR-UR05SNwDfqvRpRQWAJ6Ghyh7sQ,6799
|
|
172
|
+
tests/views/__init__.py,sha256=5JqK9sZ6jBuK83zDQokUhxQ0wuJJJ9DXB8pYCLkX7X4,102
|
|
173
|
+
tests/views/test_change_password_view.py,sha256=5dIjx6_-rNHqj9yrkz00ajMxmZENBoTwN0gNFGUzxRE,9213
|
|
174
|
+
tests/views/test_chat_token_request_view.py,sha256=jwgGaNmBPTK9irKTqsDTTTIZawpYBxfGXBUv0xxvCQ0,9850
|
|
175
|
+
tests/views/test_chat_view.py,sha256=24dySNWlpu7EXkIeFJwUUXwb5xAq3Kdv2IVzPSVSWuY,3798
|
|
176
|
+
tests/views/test_download_file_view.py,sha256=l0o5DnI29ByV7N5kK4UoTKhPmStKuiAOZKFPxCSZszE,5969
|
|
177
|
+
tests/views/test_external_chat_login_view.py,sha256=1PLOPqVJjR-7d1DV24uuA7QOYEeKsIusjw6poBYTFB8,5405
|
|
178
|
+
tests/views/test_external_login_view.py,sha256=Lf4VHxTyddx_RSTvYoxcZr8cG82bvJ0pdVqU1CJpwcg,4394
|
|
179
|
+
tests/views/test_file_store_view.py,sha256=hT2k5-ppGNphKnQwueTvyzHQUGJ1umVXpPNOpTL8GOI,4837
|
|
180
|
+
tests/views/test_forgot_password_view.py,sha256=GeaGMQpY20T9_cM_kBTrwRcx-Z1zsDbytB-KoyM9p2o,6224
|
|
181
|
+
tests/views/test_history_view.py,sha256=AxNNjVEEYVdLDNa6aZaWdSE3FMquiqqDGxvl57UYdD8,12322
|
|
182
|
+
tests/views/test_home_view.py,sha256=uqPCQnDyTm25l6YLrwzINrHMd16oyY3yrqXui1LChjg,2438
|
|
183
|
+
tests/views/test_llm_query_view.py,sha256=3Mf_mfZNW9wTG7BivwEW0OL-QXplV2zRakl5rIUOvu8,5121
|
|
184
|
+
tests/views/test_login_view.py,sha256=P-6n6LGnQ87pC9a48FMz0okVm7eukpSeIKDnMUABs3I,4812
|
|
185
|
+
tests/views/test_prompt_view.py,sha256=y8mIXc0AqOoSe2QJJX3UdiFgA1a2TYFCcIwGiupxR0U,4563
|
|
186
|
+
tests/views/test_signup_view.py,sha256=WVh11rzH2MbJWS9rvYIn9R1aCWJLnpIhIK_k7MQxi0I,6534
|
|
187
|
+
tests/views/test_tasks_review_view.py,sha256=HXbAY99rbcdg-ZoaU3kxp-jNTPgOhgiTyKmV9rUcFyQ,3743
|
|
188
|
+
tests/views/test_tasks_view.py,sha256=TNdV69Vt17uc-vBI37A7qtRNqyPho2MoW7cgGxQKecU,4551
|
|
189
|
+
tests/views/test_user_feedback_view.py,sha256=IfKOpsncmf5ciMDsGuPtro9GdKXkxhRzsysVlEEM_HA,9181
|
|
190
|
+
tests/views/test_verify_user_view.py,sha256=dxQ3ibOETEuP8M50Gmwbmzj2L6UU7PAyC91Wp9Xs0K0,4772
|
|
191
|
+
iatoolkit-0.7.14.dist-info/METADATA,sha256=dKOyYj3Eqor1XBk1Q51M-CpSbTFnEnaXDsKvE_imzho,9301
|
|
192
|
+
iatoolkit-0.7.14.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
193
|
+
iatoolkit-0.7.14.dist-info/top_level.txt,sha256=or0Ar3Su6BhTy86zRrUwMAWtsR8Nk-tFEwdC0CZpKCs,16
|
|
194
|
+
iatoolkit-0.7.14.dist-info/RECORD,,
|
tests/__init__.py
ADDED
tests/common/__init__.py
ADDED
|
File without changes
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
# Copyright (c) 2024 Fernando Libedinsky
|
|
2
|
+
# Product: IAToolkit
|
|
3
|
+
#
|
|
4
|
+
# IAToolkit is open source software.
|
|
5
|
+
|
|
6
|
+
from flask import Flask, Response
|
|
7
|
+
from unittest.mock import patch, MagicMock
|
|
8
|
+
from iatoolkit.common.auth import IAuthentication
|
|
9
|
+
import pytest
|
|
10
|
+
from datetime import datetime, timezone
|
|
11
|
+
from iatoolkit.repositories.profile_repo import ProfileRepo
|
|
12
|
+
from iatoolkit.services.jwt_service import JWTService
|
|
13
|
+
from werkzeug.exceptions import HTTPException
|
|
14
|
+
|
|
15
|
+
CURRENT_TIME = datetime.now(timezone.utc).timestamp()
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class TestAuth:
|
|
19
|
+
|
|
20
|
+
def setup_method(self):
|
|
21
|
+
self.app = Flask(__name__)
|
|
22
|
+
self.app.config['TESTING'] = True
|
|
23
|
+
|
|
24
|
+
self.profile_repo = MagicMock(spec=ProfileRepo)
|
|
25
|
+
self.jwt_service = MagicMock(spec=JWTService)
|
|
26
|
+
self.iauth_service = IAuthentication(
|
|
27
|
+
profile_repo=self.profile_repo,
|
|
28
|
+
jwt_service=self.jwt_service
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
@self.app.route('/<company_short_name>/protected')
|
|
32
|
+
def protected(company_short_name):
|
|
33
|
+
with self.app.test_request_context():
|
|
34
|
+
auth_result = self.iauth_service.check_if_user_is_logged_in(company_short_name)
|
|
35
|
+
if isinstance(auth_result, Response):
|
|
36
|
+
return auth_result
|
|
37
|
+
return "Access Granted", 200
|
|
38
|
+
|
|
39
|
+
@self.app.route('/login')
|
|
40
|
+
def login():
|
|
41
|
+
return "Login Page", 200
|
|
42
|
+
|
|
43
|
+
self.client = self.app.test_client()
|
|
44
|
+
|
|
45
|
+
def teardown_method(self):
|
|
46
|
+
patch.stopall()
|
|
47
|
+
|
|
48
|
+
# --- Pruebas para check_if_user_is_logged_in (de TestAuth original) ---
|
|
49
|
+
|
|
50
|
+
def test_allows_access_if_user_authenticated_and_active(self):
|
|
51
|
+
with patch('iatoolkit.common.auth.SessionManager.get') as mock_get, \
|
|
52
|
+
patch('iatoolkit.common.auth.SessionManager.set') as mock_set:
|
|
53
|
+
mock_get.side_effect = lambda key, default=None: {
|
|
54
|
+
'user': {'id': 1, 'username': 'test_user'},
|
|
55
|
+
'company_short_name': 'test_company',
|
|
56
|
+
'last_activity': CURRENT_TIME
|
|
57
|
+
}.get(key, default)
|
|
58
|
+
|
|
59
|
+
response = self.client.get('/test_company/protected')
|
|
60
|
+
|
|
61
|
+
assert response.status_code == 200
|
|
62
|
+
assert response.data == b"Access Granted"
|
|
63
|
+
mock_set.assert_called_with("last_activity", pytest.approx(CURRENT_TIME, 1))
|
|
64
|
+
|
|
65
|
+
def test_redirect_if_user_not_authenticated(self):
|
|
66
|
+
with patch('iatoolkit.common.auth.SessionManager.get') as mock_get:
|
|
67
|
+
mock_get.side_effect = lambda key, default=None: None if key == "user" else default
|
|
68
|
+
response = self.client.get('/test_company/protected')
|
|
69
|
+
assert response.status_code == 302
|
|
70
|
+
assert "/login" in response.headers['Location']
|
|
71
|
+
|
|
72
|
+
def test_redirect_if_last_activity_missing(self):
|
|
73
|
+
with patch('iatoolkit.common.auth.SessionManager.get') as mock_get, \
|
|
74
|
+
patch('iatoolkit.common.auth.SessionManager.clear') as mock_clear:
|
|
75
|
+
mock_get.side_effect = lambda key, default=None: {
|
|
76
|
+
'user': {'id': 1, 'username': 'test_user'},
|
|
77
|
+
'company_short_name': 'test_company'
|
|
78
|
+
}.get(key, default)
|
|
79
|
+
|
|
80
|
+
response = self.client.get('/test_company/protected')
|
|
81
|
+
|
|
82
|
+
assert response.status_code == 302
|
|
83
|
+
assert "/login" in response.headers['Location']
|
|
84
|
+
mock_clear.assert_called_once()
|
|
85
|
+
|
|
86
|
+
# --- Pruebas para verify (de TestAuthVerify original) ---
|
|
87
|
+
|
|
88
|
+
def test_verify_with_jwt_success(self):
|
|
89
|
+
with patch.object(self.iauth_service, '_authenticate_via_chat_jwt') as mock_auth_jwt, \
|
|
90
|
+
patch.object(self.iauth_service, '_authenticate_via_api_key') as mock_auth_api_key:
|
|
91
|
+
mock_auth_jwt.return_value = (123, 'ext_user_1', None)
|
|
92
|
+
|
|
93
|
+
with self.app.test_request_context():
|
|
94
|
+
result = self.iauth_service.verify('some_company')
|
|
95
|
+
|
|
96
|
+
assert result['success'] is True
|
|
97
|
+
assert result['company_id'] == 123
|
|
98
|
+
assert result['external_user_id'] == 'ext_user_1'
|
|
99
|
+
mock_auth_jwt.assert_called_once_with('some_company')
|
|
100
|
+
mock_auth_api_key.assert_not_called()
|
|
101
|
+
|
|
102
|
+
def test_verify_with_jwt_failure(self):
|
|
103
|
+
with patch.object(self.iauth_service, '_authenticate_via_chat_jwt') as mock_auth_jwt, \
|
|
104
|
+
patch.object(self.iauth_service, '_authenticate_via_api_key') as mock_auth_api_key:
|
|
105
|
+
mock_auth_jwt.return_value = (None, None, "Error de JWT")
|
|
106
|
+
|
|
107
|
+
with self.app.test_request_context():
|
|
108
|
+
result = self.iauth_service.verify('some_company')
|
|
109
|
+
|
|
110
|
+
assert result == {"error_message": "Fallo de autenticación JWT"}
|
|
111
|
+
mock_auth_api_key.assert_not_called()
|
|
112
|
+
|
|
113
|
+
def test_verify_with_api_key_success(self):
|
|
114
|
+
with patch.object(self.iauth_service, '_authenticate_via_chat_jwt') as mock_auth_jwt, \
|
|
115
|
+
patch.object(self.iauth_service, '_authenticate_via_api_key') as mock_auth_api_key, \
|
|
116
|
+
patch.object(self.iauth_service, 'check_if_user_is_logged_in') as mock_check_if_logged_in:
|
|
117
|
+
mock_auth_jwt.return_value = (None, None, None)
|
|
118
|
+
mock_auth_api_key.return_value = (456, None)
|
|
119
|
+
|
|
120
|
+
with self.app.test_request_context():
|
|
121
|
+
result = self.iauth_service.verify('some_company', body_external_user_id='body_user_2')
|
|
122
|
+
|
|
123
|
+
assert result['success'] is True
|
|
124
|
+
assert result['company_id'] == 456
|
|
125
|
+
assert result['external_user_id'] == 'body_user_2'
|
|
126
|
+
mock_auth_api_key.assert_called_once_with('some_company')
|
|
127
|
+
mock_check_if_logged_in.assert_not_called()
|
|
128
|
+
|
|
129
|
+
def test_verify_with_api_key_failure(self):
|
|
130
|
+
with patch.object(self.iauth_service, '_authenticate_via_chat_jwt') as mock_auth_jwt, \
|
|
131
|
+
patch.object(self.iauth_service, '_authenticate_via_api_key') as mock_auth_api_key:
|
|
132
|
+
mock_auth_jwt.return_value = (None, None, None)
|
|
133
|
+
mock_auth_api_key.return_value = (None, "Error de API Key")
|
|
134
|
+
|
|
135
|
+
with self.app.test_request_context():
|
|
136
|
+
result = self.iauth_service.verify('some_company')
|
|
137
|
+
|
|
138
|
+
assert result == {"error_message": "Fallo de autenticación API Key"}
|
|
139
|
+
|
|
140
|
+
def test_verify_with_session_success(self):
|
|
141
|
+
with patch.object(self.iauth_service, '_authenticate_via_chat_jwt') as mock_auth_jwt, \
|
|
142
|
+
patch.object(self.iauth_service, '_authenticate_via_api_key') as mock_auth_api_key, \
|
|
143
|
+
patch.object(self.iauth_service, 'check_if_user_is_logged_in') as mock_check_if_logged_in, \
|
|
144
|
+
patch('iatoolkit.common.auth.SessionManager.get') as mock_session_get:
|
|
145
|
+
mock_auth_jwt.return_value = (None, None, None)
|
|
146
|
+
mock_auth_api_key.return_value = (None, None)
|
|
147
|
+
mock_check_if_logged_in.return_value = None
|
|
148
|
+
mock_session_get.side_effect = lambda key, default=None: {'user_id': 789, 'company_id': 999}.get(key,
|
|
149
|
+
default)
|
|
150
|
+
|
|
151
|
+
with self.app.test_request_context():
|
|
152
|
+
result = self.iauth_service.verify('some_company')
|
|
153
|
+
|
|
154
|
+
assert result['success'] is True
|
|
155
|
+
assert result['company_id'] == 999
|
|
156
|
+
assert result['local_user_id'] == 789
|
|
157
|
+
mock_check_if_logged_in.assert_called_once_with('some_company')
|
|
158
|
+
|
|
159
|
+
def test_verify_with_session_incomplete_data(self):
|
|
160
|
+
with patch.object(self.iauth_service, '_authenticate_via_chat_jwt') as mock_auth_jwt, \
|
|
161
|
+
patch.object(self.iauth_service, '_authenticate_via_api_key') as mock_auth_api_key, \
|
|
162
|
+
patch.object(self.iauth_service, 'check_if_user_is_logged_in') as mock_check_if_logged_in, \
|
|
163
|
+
patch('iatoolkit.common.auth.SessionManager.get') as mock_session_get:
|
|
164
|
+
mock_auth_jwt.return_value = (None, None, None)
|
|
165
|
+
mock_auth_api_key.return_value = (None, None)
|
|
166
|
+
mock_check_if_logged_in.return_value = None
|
|
167
|
+
mock_session_get.side_effect = lambda key, default=None: {'user_id': 789}.get(key, default)
|
|
168
|
+
|
|
169
|
+
with self.app.test_request_context():
|
|
170
|
+
result = self.iauth_service.verify('some_company')
|
|
171
|
+
|
|
172
|
+
assert result == {"error_message": "Fallo interno en la autenticación o no autenticado"}
|
|
173
|
+
|
|
174
|
+
def test_verify_with_session_check_fails_by_exception(self):
|
|
175
|
+
with patch.object(self.iauth_service, '_authenticate_via_chat_jwt') as mock_auth_jwt, \
|
|
176
|
+
patch.object(self.iauth_service, '_authenticate_via_api_key') as mock_auth_api_key, \
|
|
177
|
+
patch.object(self.iauth_service, 'check_if_user_is_logged_in') as mock_check_if_logged_in:
|
|
178
|
+
mock_auth_jwt.return_value = (None, None, None)
|
|
179
|
+
mock_auth_api_key.return_value = (None, None)
|
|
180
|
+
mock_check_if_logged_in.side_effect = HTTPException
|
|
181
|
+
|
|
182
|
+
with self.app.test_request_context(), pytest.raises(HTTPException):
|
|
183
|
+
self.iauth_service.verify('some_company')
|
|
184
|
+
|
|
185
|
+
# --- Nuevas pruebas para _authenticate_via_api_key ---
|
|
186
|
+
|
|
187
|
+
def test_authenticate_via_api_key_success(self):
|
|
188
|
+
with self.app.test_request_context(headers={'Authorization': 'Bearer valid_key'}):
|
|
189
|
+
mock_api_entry = MagicMock()
|
|
190
|
+
mock_api_entry.company.short_name = 'test_company'
|
|
191
|
+
mock_api_entry.company_id = 123
|
|
192
|
+
self.profile_repo.get_active_api_key_entry.return_value = mock_api_entry
|
|
193
|
+
|
|
194
|
+
company_id, error = self.iauth_service._authenticate_via_api_key('test_company')
|
|
195
|
+
|
|
196
|
+
assert company_id == 123
|
|
197
|
+
assert error is None
|
|
198
|
+
self.profile_repo.get_active_api_key_entry.assert_called_once_with('valid_key')
|
|
199
|
+
|
|
200
|
+
def test_authenticate_via_api_key_no_header(self):
|
|
201
|
+
with self.app.test_request_context(headers={}):
|
|
202
|
+
company_id, error = self.iauth_service._authenticate_via_api_key('test_company')
|
|
203
|
+
assert company_id is None
|
|
204
|
+
assert error is None
|
|
205
|
+
self.profile_repo.get_active_api_key_entry.assert_not_called()
|
|
206
|
+
|
|
207
|
+
def test_authenticate_via_api_key_wrong_scheme(self):
|
|
208
|
+
with self.app.test_request_context(headers={'Authorization': 'Basic some_token'}):
|
|
209
|
+
company_id, error = self.iauth_service._authenticate_via_api_key('test_company')
|
|
210
|
+
assert company_id is None
|
|
211
|
+
assert error is None
|
|
212
|
+
self.profile_repo.get_active_api_key_entry.assert_not_called()
|
|
213
|
+
|
|
214
|
+
def test_authenticate_via_api_key_inactive_key(self):
|
|
215
|
+
with self.app.test_request_context(headers={'Authorization': 'Bearer inactive_key'}):
|
|
216
|
+
self.profile_repo.get_active_api_key_entry.return_value = None
|
|
217
|
+
company_id, error = self.iauth_service._authenticate_via_api_key('test_company')
|
|
218
|
+
assert company_id is None
|
|
219
|
+
assert error == "API Key inválida o inactiva"
|
|
220
|
+
|
|
221
|
+
def test_authenticate_via_api_key_company_mismatch(self):
|
|
222
|
+
with self.app.test_request_context(headers={'Authorization': 'Bearer valid_key'}):
|
|
223
|
+
mock_api_entry = MagicMock()
|
|
224
|
+
mock_api_entry.company.short_name = 'other_company'
|
|
225
|
+
self.profile_repo.get_active_api_key_entry.return_value = mock_api_entry
|
|
226
|
+
|
|
227
|
+
company_id, error = self.iauth_service._authenticate_via_api_key('test_company')
|
|
228
|
+
assert company_id is None
|
|
229
|
+
assert error == "API Key no es válida para la compañía test_company"
|
|
230
|
+
|
|
231
|
+
def test_authenticate_via_api_key_repo_exception(self):
|
|
232
|
+
with self.app.test_request_context(headers={'Authorization': 'Bearer any_key'}):
|
|
233
|
+
self.profile_repo.get_active_api_key_entry.side_effect = Exception("DB error")
|
|
234
|
+
company_id, error = self.iauth_service._authenticate_via_api_key('test_company')
|
|
235
|
+
assert company_id is None
|
|
236
|
+
assert error == "Error interno del servidor al validar API Key"
|
|
237
|
+
|
|
238
|
+
# --- Nuevas pruebas para _authenticate_via_chat_jwt ---
|
|
239
|
+
|
|
240
|
+
def test_authenticate_via_chat_jwt_success(self):
|
|
241
|
+
with self.app.test_request_context(headers={'X-Chat-Token': 'valid_jwt'}):
|
|
242
|
+
self.jwt_service.validate_chat_jwt.return_value = {'company_id': 123, 'external_user_id': 'ext_user'}
|
|
243
|
+
company_id, external_user_id, error = self.iauth_service._authenticate_via_chat_jwt('test_company')
|
|
244
|
+
assert company_id == 123
|
|
245
|
+
assert external_user_id == 'ext_user'
|
|
246
|
+
assert error is None
|
|
247
|
+
self.jwt_service.validate_chat_jwt.assert_called_once_with('valid_jwt', 'test_company')
|
|
248
|
+
|
|
249
|
+
def test_authenticate_via_chat_jwt_no_header(self):
|
|
250
|
+
with self.app.test_request_context(headers={}):
|
|
251
|
+
company_id, external_user_id, error = self.iauth_service._authenticate_via_chat_jwt('test_company')
|
|
252
|
+
assert company_id is None
|
|
253
|
+
assert external_user_id is None
|
|
254
|
+
assert error is None
|
|
255
|
+
self.jwt_service.validate_chat_jwt.assert_not_called()
|
|
256
|
+
|
|
257
|
+
def test_authenticate_via_chat_jwt_validation_fails(self):
|
|
258
|
+
with self.app.test_request_context(headers={'X-Chat-Token': 'invalid_jwt'}):
|
|
259
|
+
self.jwt_service.validate_chat_jwt.return_value = None
|
|
260
|
+
company_id, external_user_id, error = self.iauth_service._authenticate_via_chat_jwt('test_company')
|
|
261
|
+
assert company_id is None
|
|
262
|
+
assert external_user_id is None
|
|
263
|
+
assert error == "Token de chat expirado, debes reingresar al chat"
|
|
264
|
+
|
|
265
|
+
def test_authenticate_via_chat_jwt_incomplete_payload_no_company_id(self):
|
|
266
|
+
with self.app.test_request_context(headers={'X-Chat-Token': 'valid_jwt'}):
|
|
267
|
+
self.jwt_service.validate_chat_jwt.return_value = {'external_user_id': 'ext_user'}
|
|
268
|
+
company_id, external_user_id, error = self.iauth_service._authenticate_via_chat_jwt('test_company')
|
|
269
|
+
assert company_id is None
|
|
270
|
+
assert external_user_id is None
|
|
271
|
+
assert error == "Token de chat con formato interno incorrecto"
|
|
272
|
+
|
|
273
|
+
def test_authenticate_via_chat_jwt_incomplete_payload_no_external_id(self):
|
|
274
|
+
with self.app.test_request_context(headers={'X-Chat-Token': 'valid_jwt'}):
|
|
275
|
+
self.jwt_service.validate_chat_jwt.return_value = {'company_id': 123}
|
|
276
|
+
company_id, external_user_id, error = self.iauth_service._authenticate_via_chat_jwt('test_company')
|
|
277
|
+
assert company_id is None
|
|
278
|
+
assert external_user_id is None
|
|
279
|
+
assert error == "Token de chat con formato interno incorrecto"
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Copyright (c) 2024 Fernando Libedinsky
|
|
2
|
+
# Product: IAToolkit
|
|
3
|
+
#
|
|
4
|
+
# IAToolkit is open source software.
|
|
5
|
+
|
|
6
|
+
from flask import Flask
|
|
7
|
+
from unittest.mock import patch
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TestRoutes:
|
|
11
|
+
def setup_method(self):
|
|
12
|
+
# Configurar la aplicación Flask para pruebas
|
|
13
|
+
self.app = Flask(__name__)
|
|
14
|
+
self.app.config['VERSION'] = "1.0.0"
|
|
15
|
+
self.app.secret_key = 'test_secret'
|
|
16
|
+
|
|
17
|
+
# Concentramos todos los mocks y patches aquí:
|
|
18
|
+
|
|
19
|
+
# Patch para el SessionManager (por ejemplo para evitar lecturas de sesión reales)
|
|
20
|
+
self.session_manager_patch = patch("common.routes.SessionManager")
|
|
21
|
+
self.mock_session_manager = self.session_manager_patch.start()
|
|
22
|
+
# Para este ejemplo, no es necesario configurar un return_value, pero se podría definir según se requiera
|
|
23
|
+
|
|
24
|
+
# Patch para la función flash, reemplazándola para que no intente enviar mensajes reales
|
|
25
|
+
self.flash_patch = patch("common.routes.flash")
|
|
26
|
+
self.mock_flash = self.flash_patch.start()
|
|
27
|
+
|
|
28
|
+
# Patch para render_template, que es usado por la ruta "/about" y otros
|
|
29
|
+
self.render_template_patch = patch("common.routes.render_template", return_value="<html>About</html>")
|
|
30
|
+
self.mock_render_template = self.render_template_patch.start()
|
|
31
|
+
|
|
32
|
+
# Registrar las rutas en la aplicación
|
|
33
|
+
from iatoolkit.common.routes import register_routes
|
|
34
|
+
register_routes(self.app)
|
|
35
|
+
|
|
36
|
+
# Crear el cliente de pruebas
|
|
37
|
+
self.client = self.app.test_client()
|
|
38
|
+
|
|
39
|
+
def teardown_method(self, method):
|
|
40
|
+
patch.stopall()
|
|
41
|
+
|
|
42
|
+
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Copyright (c) 2024 Fernando Libedinsky
|
|
2
|
+
# Product: IAToolkit
|
|
3
|
+
#
|
|
4
|
+
# IAToolkit is open source software.
|
|
5
|
+
|
|
6
|
+
import unittest
|
|
7
|
+
from unittest.mock import patch
|
|
8
|
+
from iatoolkit.common.session_manager import SessionManager
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class TestSessionManager(unittest.TestCase):
|
|
12
|
+
|
|
13
|
+
def setUp(self):
|
|
14
|
+
"""
|
|
15
|
+
Configura los patches y mocks comunes para las pruebas.
|
|
16
|
+
"""
|
|
17
|
+
# Parchear el objeto 'session' como un diccionario en todos los tests
|
|
18
|
+
self.session_patcher = patch("iatoolkit.common.session_manager.session", new_callable=dict)
|
|
19
|
+
self.mock_session = self.session_patcher.start() # Iniciar el patch y obtener el mock
|
|
20
|
+
|
|
21
|
+
def tearDown(self):
|
|
22
|
+
"""
|
|
23
|
+
Detiene todos los patches después de cada prueba.
|
|
24
|
+
"""
|
|
25
|
+
patch.stopall() # Detener cualquier parche activo y limpiar el entorno
|
|
26
|
+
|
|
27
|
+
def test_set(self):
|
|
28
|
+
"""Prueba que el método set almacena un valor en la sesión."""
|
|
29
|
+
SessionManager.set("key", "value")
|
|
30
|
+
self.assertEqual(self.mock_session["key"], "value")
|
|
31
|
+
|
|
32
|
+
def test_get_existing_key(self):
|
|
33
|
+
"""Prueba que el método get devuelve el valor correcto si la clave existe."""
|
|
34
|
+
self.mock_session["key"] = "value"
|
|
35
|
+
result = SessionManager.get("key")
|
|
36
|
+
self.assertEqual(result, "value")
|
|
37
|
+
|
|
38
|
+
def test_get_non_existing_key_with_default(self):
|
|
39
|
+
"""Prueba que el método get devuelve el valor predeterminado si la clave no existe."""
|
|
40
|
+
result = SessionManager.get("non_existing_key", default="default_value")
|
|
41
|
+
self.assertEqual(result, "default_value")
|
|
42
|
+
|
|
43
|
+
def test_remove_existing_key(self):
|
|
44
|
+
"""Prueba que el método remove elimina correctamente una clave existente."""
|
|
45
|
+
self.mock_session["key"] = "value"
|
|
46
|
+
SessionManager.remove("key")
|
|
47
|
+
self.assertNotIn("key", self.mock_session)
|
|
48
|
+
|
|
49
|
+
def test_remove_non_existing_key(self):
|
|
50
|
+
"""Prueba que el método remove no lanza errores si la clave no existe."""
|
|
51
|
+
SessionManager.remove("non_existing_key")
|
|
52
|
+
# No debería hacer nada, y la sesión debe permanecer vacía
|
|
53
|
+
self.assertEqual(len(self.mock_session), 0)
|
|
54
|
+
|
|
55
|
+
def test_clear(self):
|
|
56
|
+
"""Prueba que el método clear elimina todos los elementos de la sesión."""
|
|
57
|
+
self.mock_session.update({"key1": "value1", "key2": "value2"})
|
|
58
|
+
SessionManager.clear()
|
|
59
|
+
self.assertEqual(len(self.mock_session), 0)
|