iatoolkit 0.8.1__py3-none-any.whl → 0.9.0__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.

Files changed (71) hide show
  1. iatoolkit/__init__.py +6 -34
  2. {iatoolkit-0.8.1.dist-info → iatoolkit-0.9.0.dist-info}/METADATA +1 -1
  3. {iatoolkit-0.8.1.dist-info → iatoolkit-0.9.0.dist-info}/RECORD +5 -71
  4. {iatoolkit-0.8.1.dist-info → iatoolkit-0.9.0.dist-info}/top_level.txt +0 -1
  5. tests/__init__.py +0 -5
  6. tests/common/__init__.py +0 -0
  7. tests/common/test_auth.py +0 -279
  8. tests/common/test_routes.py +0 -42
  9. tests/common/test_session_manager.py +0 -59
  10. tests/common/test_util.py +0 -444
  11. tests/companies/__init__.py +0 -5
  12. tests/conftest.py +0 -36
  13. tests/infra/__init__.py +0 -5
  14. tests/infra/connectors/__init__.py +0 -5
  15. tests/infra/connectors/test_google_drive_connector.py +0 -107
  16. tests/infra/connectors/test_local_file_connector.py +0 -85
  17. tests/infra/connectors/test_s3_connector.py +0 -95
  18. tests/infra/test_call_service.py +0 -92
  19. tests/infra/test_database_manager.py +0 -59
  20. tests/infra/test_gemini_adapter.py +0 -137
  21. tests/infra/test_google_chat_app.py +0 -68
  22. tests/infra/test_llm_client.py +0 -165
  23. tests/infra/test_llm_proxy.py +0 -122
  24. tests/infra/test_mail_app.py +0 -94
  25. tests/infra/test_openai_adapter.py +0 -105
  26. tests/infra/test_redis_session_manager_service.py +0 -117
  27. tests/repositories/__init__.py +0 -5
  28. tests/repositories/test_database_manager.py +0 -87
  29. tests/repositories/test_document_repo.py +0 -76
  30. tests/repositories/test_llm_query_repo.py +0 -340
  31. tests/repositories/test_models.py +0 -38
  32. tests/repositories/test_profile_repo.py +0 -142
  33. tests/repositories/test_tasks_repo.py +0 -76
  34. tests/repositories/test_vs_repo.py +0 -107
  35. tests/services/__init__.py +0 -5
  36. tests/services/test_dispatcher_service.py +0 -274
  37. tests/services/test_document_service.py +0 -181
  38. tests/services/test_excel_service.py +0 -208
  39. tests/services/test_file_processor_service.py +0 -121
  40. tests/services/test_history_service.py +0 -164
  41. tests/services/test_jwt_service.py +0 -255
  42. tests/services/test_load_documents_service.py +0 -112
  43. tests/services/test_mail_service.py +0 -70
  44. tests/services/test_profile_service.py +0 -379
  45. tests/services/test_prompt_manager_service.py +0 -190
  46. tests/services/test_query_service.py +0 -243
  47. tests/services/test_search_service.py +0 -39
  48. tests/services/test_sql_service.py +0 -160
  49. tests/services/test_tasks_service.py +0 -252
  50. tests/services/test_user_feedback_service.py +0 -389
  51. tests/services/test_user_session_context_service.py +0 -132
  52. tests/views/__init__.py +0 -5
  53. tests/views/test_change_password_view.py +0 -191
  54. tests/views/test_chat_token_request_view.py +0 -188
  55. tests/views/test_chat_view.py +0 -98
  56. tests/views/test_download_file_view.py +0 -149
  57. tests/views/test_external_chat_login_view.py +0 -120
  58. tests/views/test_external_login_view.py +0 -102
  59. tests/views/test_file_store_view.py +0 -128
  60. tests/views/test_forgot_password_view.py +0 -142
  61. tests/views/test_history_view.py +0 -336
  62. tests/views/test_home_view.py +0 -61
  63. tests/views/test_llm_query_view.py +0 -154
  64. tests/views/test_login_view.py +0 -114
  65. tests/views/test_prompt_view.py +0 -111
  66. tests/views/test_signup_view.py +0 -140
  67. tests/views/test_tasks_review_view.py +0 -104
  68. tests/views/test_tasks_view.py +0 -130
  69. tests/views/test_user_feedback_view.py +0 -214
  70. tests/views/test_verify_user_view.py +0 -110
  71. {iatoolkit-0.8.1.dist-info → iatoolkit-0.9.0.dist-info}/WHEEL +0 -0
iatoolkit/__init__.py CHANGED
@@ -4,37 +4,21 @@ IAToolkit Package
4
4
 
5
5
  # Expose main classes and functions at the top level of the package
6
6
 
7
- # Assuming 'toolkit.py' contains the IAToolkit class
8
- from .iatoolkit import IAToolkit, create_app
9
- from .iatoolkit import current_iatoolkit
7
+ # main IAToolkit class
8
+ from .iatoolkit import IAToolkit, current_iatoolkit, create_app
10
9
 
11
- # Assuming 'app_factory.py' contains create_app and register_company
10
+ # for registering the client companies
12
11
  from .company_registry import register_company
13
-
14
- # Assuming 'base_company.py' contains BaseCompany
15
12
  from .base_company import BaseCompany
13
+ from iatoolkit.repositories.database_manager import DatabaseManager
16
14
 
17
15
  # --- Services ---
18
- # Assuming they are in a 'services' sub-package
19
16
  from iatoolkit.services.sql_service import SqlService
20
- from iatoolkit.services.excel_service import ExcelService
21
- from iatoolkit.services.dispatcher_service import Dispatcher
22
17
  from iatoolkit.services.document_service import DocumentService
23
18
  from iatoolkit.services.search_service import SearchService
24
19
  from iatoolkit.services.load_documents_service import LoadDocumentsService
25
- from iatoolkit.repositories.profile_repo import ProfileRepo
26
- from iatoolkit.repositories.llm_query_repo import LLMQueryRepo
27
-
28
- from iatoolkit.services.query_service import QueryService
29
- from iatoolkit.services.prompt_manager_service import PromptService
30
- from iatoolkit.repositories.database_manager import DatabaseManager
31
-
20
+ from iatoolkit.services.excel_service import ExcelService
32
21
  from iatoolkit.infra.call_service import CallServiceClient
33
- from iatoolkit.common.util import Utility
34
-
35
-
36
- from iatoolkit.repositories.models import Base, Company, Function, TaskType, Prompt, PromptCategory
37
-
38
22
 
39
23
  __all__ = [
40
24
  'IAToolkit',
@@ -42,23 +26,11 @@ __all__ = [
42
26
  'current_iatoolkit',
43
27
  'register_company',
44
28
  'BaseCompany',
29
+ 'DatabaseManager',
45
30
  'SqlService',
46
31
  'ExcelService',
47
- 'Dispatcher',
48
32
  'DocumentService',
49
33
  'SearchService',
50
- 'QueryService',
51
34
  'LoadDocumentsService',
52
- 'ProfileRepo',
53
- 'LLMQueryRepo',
54
- 'PromptService',
55
- 'DatabaseManager',
56
35
  'CallServiceClient',
57
- 'Utility',
58
- 'Company',
59
- 'Function',
60
- 'TaskType',
61
- 'Base',
62
- 'Prompt',
63
- 'PromptCategory'
64
36
  ]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: iatoolkit
3
- Version: 0.8.1
3
+ Version: 0.9.0
4
4
  Summary: IAToolkit
5
5
  Author: Fernando Libedinsky
6
6
  License-Expression: MIT
@@ -1,4 +1,4 @@
1
- iatoolkit/__init__.py,sha256=yi7Uw68KajDWUUo-v4xV31Nt7hjr_-2gCXbkhdiDl44,1887
1
+ iatoolkit/__init__.py,sha256=Ob7CfSEh2idRDKFnCGx4NPZhDZyIenHibhcTtCsq-68,1042
2
2
  iatoolkit/base_company.py,sha256=gM3X7xedNaVLodOObvjUN9eJKPO5-HmSLaBFa9jowCk,4277
3
3
  iatoolkit/cli_commands.py,sha256=G5L9xQXZ0lVFXQWBaE_KEZHyfuiT6PL1nTQRoSdnBzc,2302
4
4
  iatoolkit/company_registry.py,sha256=tduqt3oV8iDX_IB1eA7KIgvIxE4edTcy-3qZIXh3Lzw,2549
@@ -103,73 +103,7 @@ iatoolkit/views/tasks_review_view.py,sha256=keLsLCyOTTlcoIapnB_lbuSvLwrPVZVpBiFC
103
103
  iatoolkit/views/tasks_view.py,sha256=a3anTXrJTTvbQuc6PSpOzidLKQFL4hWa7PI2Cppcz8w,4110
104
104
  iatoolkit/views/user_feedback_view.py,sha256=G37zmP8P4LvZrSymNJ5iFXhLZg1A3BEwRfTpH1Iam5w,2652
105
105
  iatoolkit/views/verify_user_view.py,sha256=a3q4wHJ8mKAEmgbNTOcnX4rMikROjOR3mHvCr30qGGA,2351
106
- tests/__init__.py,sha256=5JqK9sZ6jBuK83zDQokUhxQ0wuJJJ9DXB8pYCLkX7X4,102
107
- tests/conftest.py,sha256=S000Ry-rWczEDsndTtOvsj2zf2EYgjHi78oVn60hoOU,1094
108
- tests/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
109
- tests/common/test_auth.py,sha256=WViWPG3E8OldgZyPbl-lp5rosjgPQb9MlADGLr1rq4k,14338
110
- tests/common/test_routes.py,sha256=_Fz8mYqxp8YZ39CSng0CQOIRs9fOfgC42iU9XiHLMzU,1560
111
- tests/common/test_session_manager.py,sha256=8FLa8Z7ueLYNnJeJyTgCm8pp1DY6QvC0b0ZxZC2vpKc,2388
112
- tests/common/test_util.py,sha256=SMh0pSIv8K-bCeMZeYBbCD70o6MpOUXHQH6kZFLLN5c,20653
113
- tests/companies/__init__.py,sha256=5JqK9sZ6jBuK83zDQokUhxQ0wuJJJ9DXB8pYCLkX7X4,102
114
- tests/infra/__init__.py,sha256=5JqK9sZ6jBuK83zDQokUhxQ0wuJJJ9DXB8pYCLkX7X4,102
115
- tests/infra/test_call_service.py,sha256=p5kFqXFojSmHucLTyika2u3wvpQwJRCrAlVOPeohoVE,3747
116
- tests/infra/test_database_manager.py,sha256=SMU_pcCsW89b6GyykAU2LEO8UaHL9gO5rdeWGFP3A6g,2503
117
- tests/infra/test_gemini_adapter.py,sha256=gMjSgxh854sC08vYQpH6QSIX9w921U3g_Jrt_HU1i1Y,6292
118
- tests/infra/test_google_chat_app.py,sha256=D1iUaGy8Z-PHufJuQ607lGEUOFueedoziXR8J9b7qmM,2363
119
- tests/infra/test_llm_client.py,sha256=i5uRPy3k2csoNOg16dlVAaZq93MDTk5OxLgRPrsyDow,7619
120
- tests/infra/test_llm_proxy.py,sha256=Y9F8ozVsnPLOiIt_Minr_VvANEz0x0JIPvFaWJBCLgk,5753
121
- tests/infra/test_mail_app.py,sha256=6Mhj3HbnQ_sVaQc7wgTpIEFb2GAzc4kkFNWgPWBCmp0,3727
122
- tests/infra/test_openai_adapter.py,sha256=4CLLIOqQLaC_zpc3clyoA9fiMu5uJmfDoPqs7hEw4Qo,4319
123
- tests/infra/test_redis_session_manager_service.py,sha256=NbrUVxmEmWIZc9TtnFd1IiWwm1N0Ih0y7chP7z5Mx34,4914
124
- tests/infra/connectors/__init__.py,sha256=5JqK9sZ6jBuK83zDQokUhxQ0wuJJJ9DXB8pYCLkX7X4,102
125
- tests/infra/connectors/test_google_drive_connector.py,sha256=UxbR64xiDpFyeE18--BHiKgvwEuaWt9b4Cf6bL6LreM,4434
126
- tests/infra/connectors/test_local_file_connector.py,sha256=-1wpjXt2DOn_NbSUerdGFd-g-NI3rWS5vDoL3PFqxGA,3459
127
- tests/infra/connectors/test_s3_connector.py,sha256=2hsJvKPyTWQj6kkNjtpRwsLNdvW3O5N5JlhzUM67x5Q,3512
128
- tests/repositories/__init__.py,sha256=5JqK9sZ6jBuK83zDQokUhxQ0wuJJJ9DXB8pYCLkX7X4,102
129
- tests/repositories/test_database_manager.py,sha256=C6pqzxPCtk0DcZE7VNaFCT5ahONO7mWFKDo1bxb-9sU,3990
130
- tests/repositories/test_document_repo.py,sha256=sqNL5yVM_8phPaxcYR3FupuTWN5RNG8yLfeDxR07uIM,2543
131
- tests/repositories/test_llm_query_repo.py,sha256=Vdu85MI_L7Nh5ksNz9X3d4hORp9hXaXPwH1AUbuN5YE,13228
132
- tests/repositories/test_models.py,sha256=CJbz3U89BgPKmP61pwGdwDW8vHvPROKwYfqcg4lx-_Q,1627
133
- tests/repositories/test_profile_repo.py,sha256=Ex9R5JH2uyam8dt8Nl-1yiNYYj72Ma9A3Jlo_JkwktI,4981
134
- tests/repositories/test_tasks_repo.py,sha256=ZtOOjJTb_j8dKEpirZTQAnR9fhDDO7xQWZU710So9Bk,2769
135
- tests/repositories/test_vs_repo.py,sha256=PGN5PqQBtlwMC_UFU3qMSqxtoBSNz1YvZK4yYj0O0UU,4595
136
- tests/services/__init__.py,sha256=5JqK9sZ6jBuK83zDQokUhxQ0wuJJJ9DXB8pYCLkX7X4,102
137
- tests/services/test_dispatcher_service.py,sha256=iALQx0I94SehG4eXqwvdswyYrPVShXFIlk-GwwbWyzw,13086
138
- tests/services/test_document_service.py,sha256=Z62VjjIn1EPgDT2_2jEVI6AQoO3yOdskc_FDqlvML1Q,8085
139
- tests/services/test_excel_service.py,sha256=7Gyy82MFqOVFIGL7RXMIOmal22ne-lsgAfY16azDAMM,8434
140
- tests/services/test_file_processor_service.py,sha256=XzdA581hoAhevp8atqgI7jxTY1gmHE7rnMllihRS9S0,4794
141
- tests/services/test_history_service.py,sha256=VF6IgogsgaFe64LNDeXMFcLrWjuGLf3Vj_srnFfkneM,7273
142
- tests/services/test_jwt_service.py,sha256=3TYtuPk1ps0aa5TKGvd30Q4F7Q1FEsqK6Gr1wjW8-q8,10325
143
- tests/services/test_load_documents_service.py,sha256=zDcHSXVQAdtAZCVWecTl-pYlkA4Sp8JLxKpu82LB69A,4640
144
- tests/services/test_mail_service.py,sha256=PPy5XA2lYFFBNdmU1Ea-cfqszwQZrrqZSZU1OQ26lDE,2295
145
- tests/services/test_profile_service.py,sha256=WzvVxeK5AYUDWJLBRB43vVDLHi64cIkPYPcynMEGZzM,14831
146
- tests/services/test_prompt_manager_service.py,sha256=B6j12RNjljAKZnd7vy1CNAdZxwKiTWD5l4uxOGKVuvE,9395
147
- tests/services/test_query_service.py,sha256=vq8dhteJOFiA0eGo1s5eBzasx7noZFrv96XdKFKhmS8,11331
148
- tests/services/test_search_service.py,sha256=n8C5mjDDCVX4NAJvS3mKgw-WsLWu5qUA8eTOxy-g9NU,1183
149
- tests/services/test_sql_service.py,sha256=bHDiPzjfM7-mbM4eEXlMVk3vcvefhlGCx3bdIrlriVM,7753
150
- tests/services/test_tasks_service.py,sha256=V_WcglSX4CAtOkkKhZKl7Q92LsODHLRu66TqydiSQP4,10598
151
- tests/services/test_user_feedback_service.py,sha256=HMU75j48jT-Chls78QEXoq92Hpq7TXP-m8xXIAL0rK0,15859
152
- tests/services/test_user_session_context_service.py,sha256=c49RqHuoY6W_u-eR-UR05SNwDfqvRpRQWAJ6Ghyh7sQ,6799
153
- tests/views/__init__.py,sha256=5JqK9sZ6jBuK83zDQokUhxQ0wuJJJ9DXB8pYCLkX7X4,102
154
- tests/views/test_change_password_view.py,sha256=5dIjx6_-rNHqj9yrkz00ajMxmZENBoTwN0gNFGUzxRE,9213
155
- tests/views/test_chat_token_request_view.py,sha256=jwgGaNmBPTK9irKTqsDTTTIZawpYBxfGXBUv0xxvCQ0,9850
156
- tests/views/test_chat_view.py,sha256=24dySNWlpu7EXkIeFJwUUXwb5xAq3Kdv2IVzPSVSWuY,3798
157
- tests/views/test_download_file_view.py,sha256=l0o5DnI29ByV7N5kK4UoTKhPmStKuiAOZKFPxCSZszE,5969
158
- tests/views/test_external_chat_login_view.py,sha256=1PLOPqVJjR-7d1DV24uuA7QOYEeKsIusjw6poBYTFB8,5405
159
- tests/views/test_external_login_view.py,sha256=Lf4VHxTyddx_RSTvYoxcZr8cG82bvJ0pdVqU1CJpwcg,4394
160
- tests/views/test_file_store_view.py,sha256=hT2k5-ppGNphKnQwueTvyzHQUGJ1umVXpPNOpTL8GOI,4837
161
- tests/views/test_forgot_password_view.py,sha256=GeaGMQpY20T9_cM_kBTrwRcx-Z1zsDbytB-KoyM9p2o,6224
162
- tests/views/test_history_view.py,sha256=AxNNjVEEYVdLDNa6aZaWdSE3FMquiqqDGxvl57UYdD8,12322
163
- tests/views/test_home_view.py,sha256=uqPCQnDyTm25l6YLrwzINrHMd16oyY3yrqXui1LChjg,2438
164
- tests/views/test_llm_query_view.py,sha256=3Mf_mfZNW9wTG7BivwEW0OL-QXplV2zRakl5rIUOvu8,5121
165
- tests/views/test_login_view.py,sha256=P-6n6LGnQ87pC9a48FMz0okVm7eukpSeIKDnMUABs3I,4812
166
- tests/views/test_prompt_view.py,sha256=y8mIXc0AqOoSe2QJJX3UdiFgA1a2TYFCcIwGiupxR0U,4563
167
- tests/views/test_signup_view.py,sha256=WVh11rzH2MbJWS9rvYIn9R1aCWJLnpIhIK_k7MQxi0I,6534
168
- tests/views/test_tasks_review_view.py,sha256=HXbAY99rbcdg-ZoaU3kxp-jNTPgOhgiTyKmV9rUcFyQ,3743
169
- tests/views/test_tasks_view.py,sha256=TNdV69Vt17uc-vBI37A7qtRNqyPho2MoW7cgGxQKecU,4551
170
- tests/views/test_user_feedback_view.py,sha256=IfKOpsncmf5ciMDsGuPtro9GdKXkxhRzsysVlEEM_HA,9181
171
- tests/views/test_verify_user_view.py,sha256=dxQ3ibOETEuP8M50Gmwbmzj2L6UU7PAyC91Wp9Xs0K0,4772
172
- iatoolkit-0.8.1.dist-info/METADATA,sha256=3jM0LUTEQLziEwLaP2Cao3WePdsFE_UEPxGY4mEbCKw,9300
173
- iatoolkit-0.8.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
174
- iatoolkit-0.8.1.dist-info/top_level.txt,sha256=or0Ar3Su6BhTy86zRrUwMAWtsR8Nk-tFEwdC0CZpKCs,16
175
- iatoolkit-0.8.1.dist-info/RECORD,,
106
+ iatoolkit-0.9.0.dist-info/METADATA,sha256=ekZoeb9neMd9mTJjRlLpwS_LUf2txpZOtMDTJk1wANM,9300
107
+ iatoolkit-0.9.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
108
+ iatoolkit-0.9.0.dist-info/top_level.txt,sha256=V_w4QvDx0b1RXiy8zTCrD1Bp7AZkFe3_O0-9fMiwogg,10
109
+ iatoolkit-0.9.0.dist-info/RECORD,,
tests/__init__.py DELETED
@@ -1,5 +0,0 @@
1
- # Copyright (c) 2024 Fernando Libedinsky
2
- # Product: IAToolkit
3
- #
4
- # IAToolkit is open source software.
5
-
tests/common/__init__.py DELETED
File without changes
tests/common/test_auth.py DELETED
@@ -1,279 +0,0 @@
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"
@@ -1,42 +0,0 @@
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
-
@@ -1,59 +0,0 @@
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)