Files
odoo_source/addons/calendar/tests/test_calendar_controller.py
T
Arnaud Joset 5c4ac1d016 [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) <moc@odoo.com>
2021-04-14 15:16:31 +00:00

50 lines
2.2 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from datetime import datetime
from odoo.tests.common import HttpCase, new_test_user, tagged
@tagged("post_install", "-at_install")
class TestCalendarController(HttpCase):
def setUp(self):
super().setUp()
self.user = new_test_user(self.env, "test_user_1", email="test_user_1@nowhere.com", tz="UTC")
self.other_user = new_test_user(self.env, "test_user_2", email="test_user_2@nowhere.com", password="P@ssw0rd!", tz="UTC")
self.partner = self.user.partner_id
self.event = (
self.env["calendar.event"]
.create(
{
"name": "Doom's day",
"start": datetime(2019, 10, 25, 8, 0),
"stop": datetime(2019, 10, 27, 18, 0),
"partner_ids": [(4, self.partner.id)],
}
)
.with_context(mail_notrack=True)
)
def test_accept_meeting_unauthenticated(self):
self.event.write({"partner_ids": [(4, self.other_user.partner_id.id)]})
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")
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)]})
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")
attendee.invalidate_cache()
self.assertEqual(attendee.state, "accepted", "Attendee should have accepted")