Monolista: correggi date SAM e soglie delle picking list
This commit is contained in:
62
tests/test_sam_date_origin.py
Normal file
62
tests/test_sam_date_origin.py
Normal file
@@ -0,0 +1,62 @@
|
||||
"""Diagnostic anchor from the SAM print: serial 43570 means 15 April 2019."""
|
||||
import os
|
||||
import unittest
|
||||
from datetime import date, datetime
|
||||
|
||||
from inventory_service import inventory_cutoff
|
||||
from storico_pickinglist import _format_date
|
||||
|
||||
|
||||
class SamDateOriginTest(unittest.TestCase):
|
||||
def test_inventory_exclusive_midnight_matches_sam_anchor(self):
|
||||
_, cutoff, serial = inventory_cutoff("15/04/2019", today=date(2026, 11, 6))
|
||||
self.assertEqual(cutoff, datetime(2019, 4, 16))
|
||||
self.assertEqual(serial, 43571)
|
||||
|
||||
def test_native_datetime_preserved(self):
|
||||
self.assertEqual(_format_date(datetime(2019, 4, 15, 18)), "15/04/2019")
|
||||
|
||||
def test_history_formats_sam_numeric_anchor(self):
|
||||
self.assertEqual(_format_date(43570.0), "15/04/2019")
|
||||
|
||||
def test_document_244_changes_day_at_midnight_not_noon(self):
|
||||
for fraction in (0, 0.49999, 0.5, 0.99999):
|
||||
with self.subTest(fraction=fraction):
|
||||
self.assertEqual(_format_date(46289 + fraction), "24/09/2026")
|
||||
self.assertEqual(_format_date(46290), "25/09/2026")
|
||||
|
||||
def test_non_serial_inputs_are_not_shifted(self):
|
||||
for value, expected in ((None, ""), (date(2024, 2, 29), "29/02/2024"),
|
||||
("20260924", "24/09/2026"),
|
||||
("2026-09-24T23:59:59", "24/09/2026")):
|
||||
with self.subTest(value=value):
|
||||
self.assertEqual(_format_date(value), expected)
|
||||
|
||||
@unittest.skipUnless(os.getenv("SAM_DATE_TEST_LOCAL") == "1", "opt-in local SQL Server test")
|
||||
def test_actual_master_and_detail_filters_on_local_sql_server(self):
|
||||
import pyodbc
|
||||
from gestione_pickinglist import SQL_PL, SQL_PL_DETAILS
|
||||
|
||||
cn = pyodbc.connect("DRIVER={ODBC Driver 17 for SQL Server};SERVER=localhost;"
|
||||
"DATABASE=tempdb;Trusted_Connection=yes;", timeout=5)
|
||||
self.addCleanup(cn.close)
|
||||
# No warehouse objects: replace only the source and clock of each real query.
|
||||
source = """(SELECT n AS Documento, n AS DataDocumento, 'x' AS Pallet,
|
||||
1 AS Lotto, 1 AS Articolo, 1 AS Descrizione, 1 AS Qta, 1 AS CodNazione,
|
||||
1 AS NAZIONE, 1 AS Stato, 1 AS PalletCella, 1 AS Magazzino, 1 AS Area,
|
||||
1 AS Cella, 1 AS OrdinePrelievoGruppo, 1 AS Ordinamento, 0 AS IDStato
|
||||
FROM (VALUES (CAST(? AS float))) v(n)) sample"""
|
||||
for days in (10, 15, 20, 30):
|
||||
first = 46289 - days + 1 # 24 September is the final included day.
|
||||
for clock in ("00:00:00", "11:59:59", "12:00:00", "23:59:59"):
|
||||
for serial, inside in ((first - 0.001, False), (first, True), (46289.99, True)):
|
||||
for query in (SQL_PL, SQL_PL_DETAILS):
|
||||
sql = query.replace("dbo.py_ViewPackingListPrelievo", source)
|
||||
sql = sql.replace("GETDATE()", "CONVERT(datetime2, ?, 126)")
|
||||
sql = sql.replace(":days", "?").replace(":Documento", "?")
|
||||
params = [serial]
|
||||
if query == SQL_PL_DETAILS:
|
||||
params.append(serial)
|
||||
params.extend(["2026-09-24T" + clock, days])
|
||||
with self.subTest(days=days, clock=clock, serial=serial, detail=query==SQL_PL_DETAILS):
|
||||
self.assertEqual(bool(cn.execute(sql, *params).fetchall()), inside)
|
||||
Reference in New Issue
Block a user