Sign in before filtering the order export
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -331,6 +331,9 @@ def _load_order_export(client, day: date, prefixes: list[str]) -> tuple[str, str
|
|||||||
"""Prefer the filtered export. A failed post still returns the full CSV."""
|
"""Prefer the filtered export. A failed post still returns the full CSV."""
|
||||||
if getattr(client, "session", None) is None:
|
if getattr(client, "session", None) is None:
|
||||||
return client.fetch_customer_orders()
|
return client.fetch_customer_orders()
|
||||||
|
# The report GET redirects to login until the client has signed in.
|
||||||
|
if hasattr(client, "login") and not getattr(client, "_logged_in", False):
|
||||||
|
client.login()
|
||||||
try:
|
try:
|
||||||
return export_filtered_customer_orders(client, day, prefixes)
|
return export_filtered_customer_orders(client, day, prefixes)
|
||||||
except (_FilterMiss, OSError):
|
except (_FilterMiss, OSError):
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from slips.crm_orders import (
|
|||||||
SESSION_TTL_SECONDS,
|
SESSION_TTL_SECONDS,
|
||||||
CrmAuthError,
|
CrmAuthError,
|
||||||
CrmOrdersError,
|
CrmOrdersError,
|
||||||
|
_load_order_export,
|
||||||
code_matches,
|
code_matches,
|
||||||
export_filtered_customer_orders,
|
export_filtered_customer_orders,
|
||||||
format_jalali,
|
format_jalali,
|
||||||
@@ -192,6 +193,32 @@ class SystemGroupLoginTests(unittest.TestCase):
|
|||||||
self.assertIn("PageID=", sess.gets[0])
|
self.assertIn("PageID=", sess.gets[0])
|
||||||
self.assertIn("TimeStamp=", sess.gets[0])
|
self.assertIn("TimeStamp=", sess.gets[0])
|
||||||
|
|
||||||
|
def test_filtered_export_logs_in_first(self):
|
||||||
|
calls = []
|
||||||
|
|
||||||
|
class Client:
|
||||||
|
def __init__(self):
|
||||||
|
self.session = object()
|
||||||
|
self._logged_in = False
|
||||||
|
|
||||||
|
def login(self):
|
||||||
|
calls.append("login")
|
||||||
|
self._logged_in = True
|
||||||
|
|
||||||
|
def fetch_customer_orders(self):
|
||||||
|
calls.append("full")
|
||||||
|
return "full", "text/csv"
|
||||||
|
|
||||||
|
client = Client()
|
||||||
|
with patch(
|
||||||
|
"slips.crm_orders.export_filtered_customer_orders",
|
||||||
|
return_value=("filtered", "text/csv"),
|
||||||
|
) as filtered:
|
||||||
|
body, ctype = _load_order_export(client, date(2026, 3, 21), ["KR"])
|
||||||
|
self.assertEqual(calls, ["login"])
|
||||||
|
self.assertEqual((body, ctype), ("filtered", "text/csv"))
|
||||||
|
filtered.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
class CrmSessionTests(TestCase):
|
class CrmSessionTests(TestCase):
|
||||||
def test_session_lasts_thirty_days_and_slides(self):
|
def test_session_lasts_thirty_days_and_slides(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user