6
6
from pathlib import Path
7
7
from loguru import logger
8
8
import json
9
+ import pytz
10
+ import datetime
9
11
10
12
11
13
###################### get_informo
@@ -151,13 +153,24 @@ async def test_save_informo_minio(mock_upload_objs, mock_check_s3_file_exists, m
151
153
# Llamar a la función
152
154
await save_informo (mock_settings_minio , mock_data )
153
155
156
+ date_from_file = mock_data ["pms" ]["fecha_hora" ]
157
+ dt = datetime .datetime .strptime (date_from_file , "%d/%m/%Y %H:%M:%S" )
158
+ formated_date = dt .strftime ("%Y-%m-%dT%H%M" )
159
+ # Get the timezone from Madrid and formated the dates for the object_name of the files
160
+ europe_timezone = pytz .timezone ("Europe/Madrid" )
161
+ current_datetime = datetime .datetime .now (europe_timezone ).replace (second = 0 )
162
+ print (current_datetime )
163
+ formatted_date_slash = current_datetime .strftime (
164
+ "%Y/%m/%d"
165
+ )
166
+
154
167
# Verificar que se llamó a check_s3_file_exists con los argumentos correctos
155
168
mock_check_s3_file_exists .assert_called_once_with (
156
169
endpoint_url = mock_settings_minio .storage .config .minio .endpoint ,
157
170
aws_secret_access_key = mock_settings_minio .storage .config .minio .secret_key ,
158
171
aws_access_key_id = mock_settings_minio .storage .config .minio .access_key ,
159
172
bucket_name = mock_settings_minio .storage .config .minio .bucket ,
160
- object_name = "raw/informo/2024/10/09/informo_2024-10-09T1430 .json"
173
+ object_name = f "raw/informo/{ formatted_date_slash } /informo_ { formated_date } .json"
161
174
)
162
175
163
176
# Verificar que se llamó a upload_objs para subir el archivo
@@ -175,15 +188,25 @@ async def test_save_informo_local(mock_open_func, mock_check_local_file_exists,
175
188
176
189
# Llamar a la función
177
190
await save_informo (mock_settings_local , mock_data )
191
+ date_from_file = mock_data ["pms" ]["fecha_hora" ]
192
+ dt = datetime .datetime .strptime (date_from_file , "%d/%m/%Y %H:%M:%S" )
193
+ formated_date = dt .strftime ("%Y-%m-%dT%H%M" )
194
+ # Get the timezone from Madrid and formated the dates for the object_name of the files
195
+ europe_timezone = pytz .timezone ("Europe/Madrid" )
196
+ current_datetime = datetime .datetime .now (europe_timezone ).replace (second = 0 )
197
+ print (current_datetime )
198
+ formatted_date_slash = current_datetime .strftime (
199
+ "%Y/%m/%d"
200
+ )
178
201
179
202
# Verificar que se llamó a check_local_file_exists con los argumentos correctos
180
203
mock_check_local_file_exists .assert_called_once_with (
181
- Path ("/tmp/raw/informo/2024/10/09 " ),
182
- "informo_2024-10-09T1430 .json"
204
+ Path (f "/tmp/raw/informo/{ formatted_date_slash } " ),
205
+ f"informo_ { formated_date } .json"
183
206
)
184
207
185
208
# Verificar que se abrió el archivo correctamente para escribir los datos
186
- mock_open_func .assert_called_once_with (Path ("/tmp/raw/informo/2024/10/09 " ) / "informo_2024-10-09T1430 .json" , "w" )
209
+ mock_open_func .assert_called_once_with (Path (f "/tmp/raw/informo/{ formatted_date_slash } " ) / f"informo_ { formated_date } .json" , "w" )
187
210
188
211
# Verificar que se escribió el contenido JSON en el archivo
189
212
mock_open_func ().write .assert_called_once_with (json .dumps (mock_data ))
0 commit comments