test: flaky MR report test

all test records are on same day so sorting was random in report rows.
This commit is contained in:
Ankush Menat 2022-03-10 17:37:29 +05:30 committed by Ankush Menat
parent 7dd10367f4
commit 6c54be0dcd

View File

@ -17,8 +17,8 @@ class TestRequestedItemsToOrderAndReceive(FrappeTestCase):
def setUp(self) -> None:
create_item("Test MR Report Item")
self.setup_material_request() # to order and receive
self.setup_material_request(order=True) # to receive (ordered)
self.setup_material_request(order=True, receive=True) # complete (ordered & received)
self.setup_material_request(order=True, days=1) # to receive (ordered)
self.setup_material_request(order=True, receive=True, days=2) # complete (ordered & received)
self.filters = frappe._dict(
company="_Test Company", from_date=today(), to_date=add_days(today(), 30),
@ -32,9 +32,8 @@ class TestRequestedItemsToOrderAndReceive(FrappeTestCase):
data = get_data(self.filters)
self.assertEqual(len(data), 2) # MRs today should be fetched
self.filters.from_date = add_days(today(), 1)
data = get_data(self.filters)
self.assertEqual(len(data), 0) # MRs today should not be fetched as from date is tomorrow
data = get_data(self.filters.update({"from_date": add_days(today(), 10)}))
self.assertEqual(len(data), 0) # MRs today should not be fetched as from date is in future
def test_ordered_received_material_requests(self):
data = get_data(self.filters)
@ -44,19 +43,19 @@ class TestRequestedItemsToOrderAndReceive(FrappeTestCase):
self.assertEqual(data[0].ordered_qty, 0.0)
self.assertEqual(data[1].ordered_qty, 57.0)
def setup_material_request(self, order=False, receive=False):
def setup_material_request(self, order=False, receive=False, days=0):
po = None
test_records = frappe.get_test_records('Material Request')
mr = frappe.copy_doc(test_records[0])
mr.transaction_date = today()
mr.schedule_date = add_days(today(), 1)
mr.transaction_date = add_days(today(), days)
mr.schedule_date = add_days(mr.transaction_date, 1)
for row in mr.items:
row.item_code = "Test MR Report Item"
row.item_name = "Test MR Report Item"
row.description = "Test MR Report Item"
row.uom = "Nos"
row.schedule_date = add_days(today(), 1)
row.schedule_date = mr.schedule_date
mr.submit()
if order or receive: