From 5c4ac1d01624124fba1cb5e4757ef4c3b04ee384 Mon Sep 17 00:00:00 2001 From: Arnaud Joset Date: Sat, 3 Apr 2021 07:22:17 +0000 Subject: [PATCH] [FIX] calendar: solve undeterministic bug on event acceptance Before this fix, the runbot would fails randomly during the nightly multi-build in test_accept_meeting_unauthenticated and test_accept_meeting_authenticated. ```py odoo.addons.calendar.tests.test_calendar_controller:36 FAIL: TestCalendarController.test_accept_meeting_unauthenticated Traceback (most recent call last): File "/data/build/odoo/addons/calendar/tests/test_calendar_controller.py", line 36, in test_accept_meeting_unauthenticated self.assertEqual(self.event.attendee_ids[1].state, "accepted", "Attendee should have accepted") AssertionError: 'needsAction' != 'accepted' - needsAction + accepted : Attendee should have accepted ``` There was a hard coded index of a record in a many2one field and sometimes, the record order changed. The asserted value was not the one expected and therefore, the test failed. closes odoo/odoo#69263 Taskid: 2497816 X-original-commit: 4632ee9a02e366dcb7da6b46f23a3cd367412ccb Signed-off-by: Christophe Monniez (moc) --- addons/calendar/tests/test_calendar_controller.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/addons/calendar/tests/test_calendar_controller.py b/addons/calendar/tests/test_calendar_controller.py index 32dc7abc77a..abdc9e961ee 100644 --- a/addons/calendar/tests/test_calendar_controller.py +++ b/addons/calendar/tests/test_calendar_controller.py @@ -27,21 +27,23 @@ class TestCalendarController(HttpCase): def test_accept_meeting_unauthenticated(self): self.event.write({"partner_ids": [(4, self.other_user.partner_id.id)]}) - token = self.event.attendee_ids[1].access_token + attendee = self.event.attendee_ids.filtered(lambda att: att.partner_id.id == self.other_user.partner_id.id) + token = attendee.access_token url = "/calendar/meeting/accept?token=%s&id=%d" % (token, self.event.id) res = self.url_open(url) self.assertEqual(res.status_code, 200, "Response should = OK") - self.event.attendee_ids[1].invalidate_cache() - self.assertEqual(self.event.attendee_ids[1].state, "accepted", "Attendee should have accepted") + attendee.invalidate_cache() + self.assertEqual(attendee.state, "accepted", "Attendee should have accepted") def test_accept_meeting_authenticated(self): self.event.write({"partner_ids": [(4, self.other_user.partner_id.id)]}) - token = self.event.attendee_ids[1].access_token + attendee = self.event.attendee_ids.filtered(lambda att: att.partner_id.id == self.other_user.partner_id.id) + token = attendee.access_token url = "/calendar/meeting/accept?token=%s&id=%d" % (token, self.event.id) self.authenticate("test_user_2", "P@ssw0rd!") res = self.url_open(url) self.assertEqual(res.status_code, 200, "Response should = OK") - self.event.attendee_ids[1].invalidate_cache() - self.assertEqual(self.event.attendee_ids[1].state, "accepted", "Attendee should have accepted") + attendee.invalidate_cache() + self.assertEqual(attendee.state, "accepted", "Attendee should have accepted")