c5466a4171
adapt to new naming of parsing methods, remove unused paths in parser module, all module import logwatcher.config instead of importing logwatcher, rename test functions
54 lines
2.9 KiB
Python
54 lines
2.9 KiB
Python
from datetime import datetime
|
|
|
|
import pytest
|
|
|
|
from logwatcher.config import DATETIME_FORMAT, FRENCH_TIMEZONE
|
|
from logwatcher.models import LogEntry
|
|
|
|
|
|
def test_valid_log_entry():
|
|
LogEntry(
|
|
server_ip="192.168.13.27",
|
|
mdc_server_name="MDC_720",
|
|
start_time=datetime.strptime("18/07/2026 11:34:41", DATETIME_FORMAT).astimezone(FRENCH_TIMEZONE),
|
|
store_name="PECCOUD",
|
|
error_time=datetime.strptime("18/07/2026 11:35:58", DATETIME_FORMAT).astimezone(FRENCH_TIMEZONE),
|
|
error_message="Erreur FTP SDUpdatePrixISF : Requested action not taken",
|
|
raw_line="\\\\192.168.13.27\\e\\MDC_720\\Logs\\26\\07\\18\\20260718113428.txt [18/07/2026 11:34:41] DOSSIER EN COURS : PECCOUD [18/07/2026 11:35:58] Erreur FTP SDUpdatePrixISF : Requested action not taken"
|
|
)
|
|
|
|
def test_log_entry_invalid_dates():
|
|
with pytest.raises(ValueError, match="Error in date-times"):
|
|
LogEntry(
|
|
server_ip="192.168.13.27",
|
|
mdc_server_name="MDC_720",
|
|
start_time=datetime.strptime("18/07/2026 11:35:58", DATETIME_FORMAT).astimezone(FRENCH_TIMEZONE),
|
|
store_name="PECCOUD",
|
|
error_time=datetime.strptime("18/07/2026 11:34:41", DATETIME_FORMAT).astimezone(FRENCH_TIMEZONE),
|
|
error_message="Erreur FTP SDUpdatePrixISF : Requested action not taken",
|
|
raw_line="\\\\192.168.13.27\\e\\MDC_720\\Logs\\26\\07\\18\\20260718113428.txt [18/07/2026 11:34:41] DOSSIER EN COURS : PECCOUD [18/07/2026 11:35:58] Erreur FTP SDUpdatePrixISF : Requested action not taken"
|
|
)
|
|
|
|
def test_equals_models():
|
|
log_entry_1 = LogEntry(
|
|
server_ip="192.168.13.27",
|
|
mdc_server_name="MDC_720",
|
|
start_time=datetime.strptime("18/07/2026 11:34:41", DATETIME_FORMAT).astimezone(FRENCH_TIMEZONE),
|
|
store_name="PECCOUD",
|
|
error_time=datetime.strptime("18/07/2026 11:35:58", DATETIME_FORMAT).astimezone(FRENCH_TIMEZONE),
|
|
error_message="Erreur FTP SDUpdatePrixISF : Requested action not taken",
|
|
raw_line="\\\\192.168.13.27\\e\\MDC_720\\Logs\\26\\07\\18\\20260718113428.txt [18/07/2026 11:34:41] DOSSIER EN COURS : PECCOUD [18/07/2026 11:35:58] Erreur FTP SDUpdatePrixISF : Requested action not taken"
|
|
)
|
|
|
|
log_entry_2 = LogEntry(
|
|
server_ip="192.168.13.27",
|
|
mdc_server_name="MDC_720",
|
|
start_time=datetime.strptime("18/07/2026 11:34:41", DATETIME_FORMAT).astimezone(FRENCH_TIMEZONE),
|
|
store_name="PECCOUD",
|
|
error_time=datetime.strptime("18/07/2026 11:35:58", DATETIME_FORMAT).astimezone(FRENCH_TIMEZONE),
|
|
error_message="Erreur FTP SDUpdatePrixISF : Requested action not taken",
|
|
raw_line="\\\\192.168.13.27\\e\\MDC_720\\Logs\\26\\07\\18\\20260718113428.txt [18/07/2026 11:34:41] DOSSIER EN COURS : PECCOUD [18/07/2026 11:35:58] Erreur FTP SDUpdatePrixISF : Requested action not taken"
|
|
)
|
|
|
|
assert log_entry_1 == log_entry_2
|