Use SystemGroup filtered order export

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-21 14:41:39 +03:30
parent 09f0a2a24a
commit f11f40f5f0
3 changed files with 16 additions and 125 deletions

View File

@@ -128,8 +128,6 @@ class SystemGroupLoginTests(unittest.TestCase):
recent_customer_orders("ada", "wrong")
def test_report_filter_uses_date_and_code_prefixes(self):
import json
state = report_filter_state(date(2026, 3, 21), ["ICJ/", "RMJ/"])
expr = state["expression"]
self.assertEqual(expr["operator"], 2)
@@ -144,54 +142,19 @@ class SystemGroupLoginTests(unittest.TestCase):
)
self.assertEqual(report_filter_state(date(2026, 3, 21), [])["expression"]["expressions"][0]["filterItemName"], "ord.Date")
class Resp:
def __init__(self, text, url, content=None):
self.text = text
self.url = url
self.content = text.encode() if content is None else content
self.headers = {"Content-Type": "text/csv"}
self.status_code = 200
seen = {}
def raise_for_status(self):
return None
class Client:
def fetch_customer_orders(self, filter_state=None):
seen["filter_state"] = filter_state
return "note,code\n", "text/csv"
class Sess:
def __init__(self):
self.posts = []
self.gets = []
def get(self, url, timeout, allow_redirects=True):
self.gets.append(url)
if url.endswith("CSV"):
return Resp("note,code\n", url, b"note,code\n")
return Resp(
'<form action="./ReportViewer.aspx?PageID=9" method="post">'
'<input type="hidden" name="__VIEWSTATE" value="" />'
'</form>',
"http://crm.example/ReportViewer.aspx?PageID=9",
)
def post(self, url, data, headers, timeout, allow_redirects=True):
self.posts.append(data)
return Resp(
'{"ExportUrlBase":"/Reserved.ReportViewerWebControl.axd?Format="}',
url,
)
sess = Sess()
client = SimpleNamespace(base_url="http://crm.example/", timeout=5, session=sess)
with patch(
"lithium_systemgroup.client.customer_orders_report_path_from_env",
return_value="ReportViewer.aspx?x=1",
):
body, ctype = export_filtered_customer_orders(client, date(2026, 3, 21), ["KR"])
body, ctype = export_filtered_customer_orders(Client(), date(2026, 3, 21), ["KR"])
self.assertEqual(body, "note,code\n")
self.assertEqual(ctype, "text/csv")
posted = json.loads(sess.posts[0]["reportViewer_GenericFilterTemplate_Filter_ord_ClientState"])
self.assertEqual(posted["expression"]["expressions"][1]["filterItemName"], "pp.code")
self.assertEqual(posted["expression"]["expressions"][1]["operands"][0]["value"], "KR")
self.assertIn("PageID=", sess.gets[0])
self.assertIn("TimeStamp=", sess.gets[0])
posted = seen["filter_state"]["expression"]["expressions"][1]
self.assertEqual(posted["filterItemName"], "pp.code")
self.assertEqual(posted["operands"][0]["value"], "KR")
def test_filtered_export_logs_in_first(self):
calls = []