[FIX] google_calendar: accepting recurrent event tests

The `test_accepting_recurrent_event_*` tests make sure that accepting recurrent events on google side reflect in odoo.
The test was failing because of the following:
when retrieving the invited attendee, the test used `self.assertEqual(event.attendee_ids[1].state, expected_states[i])` assuming that organizer will be at index `0` and invited user at index `1`.
However the list of `event.attendee_ids` is ordered by create_date.
And we create both organizer and attendee with the same command at the same time: `partner_ids=[Command.set([self.organizer_user.partner_id.id, self.attendee_user.partner_id.id])]`
So we might have organizer at index `1` and invited attendee at index `0`. This resulted in the indeterministic behavior of the test.

To fix this issue:
This commit changes how the invited attendee is retrieved, making sure that we always get the right attendee.

fixes runbot-61527

closes odoo/odoo#162279

X-original-commit: 6db2614283abfc035343f021b9cfc52609aa9d44
Signed-off-by: Ahmad Almaghraby (alah) <alah@odoo.com>
This commit is contained in:
ahmad(alah)
2024-04-18 21:06:44 +00:00
parent d7f6c42f9c
commit 73627b45eb
@@ -98,6 +98,8 @@ class TestSyncGoogle2Odoo(TestSyncGoogle):
{"email": self.organizer_user.partner_id.email, "responseStatus": "accepted"},
{"email": self.attendee_user.partner_id.email, "responseStatus": response_status},
]
updated_event_id = updated_event_google_values['id']
updated_event_google_values['id'] = updated_event_id[:updated_event_id.index('_') + 1] + 'R' + updated_event_id[updated_event_id.index('_') + 1:]
recurrence_google_values["recurrence"] = [rrule1]
updated_event_google_values["recurrence"] = [rrule2]
return [
@@ -1969,8 +1971,11 @@ class TestSyncGoogle2Odoo(TestSyncGoogle):
expected_states = ["needsAction", "needsAction", "accepted", "needsAction"]
with self.mock_datetime_and_now("2024-04-22"):
self.attendee_user.sudo()._sync_google_calendar(self.google_service)
for i, event in enumerate(recurrence.calendar_event_ids.sorted("start")):
self.assertEqual(event.attendee_ids[1].state, expected_states[i])
attendees = self.env['calendar.attendee'].search([
('partner_id', '=', self.attendee_user.partner_id.id)
]).sorted(key=lambda r: r.event_id.start)
for i, expected_state in enumerate(expected_states):
self.assertEqual(attendees[i].state, expected_state)
@patch.object(GoogleCalendarService, 'get_events')
def test_accepting_recurrent_event_with_this_event_option_synced_by_organizer(self, mock_get_events):
@@ -1994,8 +1999,11 @@ class TestSyncGoogle2Odoo(TestSyncGoogle):
expected_states = ["needsAction", "needsAction", "accepted", "needsAction"]
with self.mock_datetime_and_now("2024-04-22"):
self.organizer_user.sudo()._sync_google_calendar(self.google_service)
for i, event in enumerate(recurrence.calendar_event_ids.sorted("start")):
self.assertEqual(event.attendee_ids[1].state, expected_states[i])
attendees = self.env['calendar.attendee'].search([
('partner_id', '=', self.attendee_user.partner_id.id)
]).sorted(key=lambda r: r.event_id.start)
for i, expected_state in enumerate(expected_states):
self.assertEqual(attendees[i].state, expected_state)
@patch.object(GoogleCalendarService, 'get_events')
def test_accepting_recurrent_event_with_all_events_option_synced_by_attendee(self, mock_get_events):
@@ -2019,8 +2027,11 @@ class TestSyncGoogle2Odoo(TestSyncGoogle):
expected_states = ["accepted", "accepted", "accepted", "accepted"]
with self.mock_datetime_and_now("2024-04-22"):
self.attendee_user.sudo()._sync_google_calendar(self.google_service)
for i, event in enumerate(recurrence.calendar_event_ids.sorted("start")):
self.assertEqual(event.attendee_ids[1].state, expected_states[i])
attendees = self.env['calendar.attendee'].search([
('partner_id', '=', self.attendee_user.partner_id.id)
]).sorted(key=lambda r: r.event_id.start)
for i, expected_state in enumerate(expected_states):
self.assertEqual(attendees[i].state, expected_state)
@patch.object(GoogleCalendarService, 'get_events')
def test_accepting_recurrent_event_with_all_events_option_synced_by_organizer(self, mock_get_events):
@@ -2044,8 +2055,11 @@ class TestSyncGoogle2Odoo(TestSyncGoogle):
expected_states = ["accepted", "accepted", "accepted", "accepted"]
with self.mock_datetime_and_now("2024-04-22"):
self.organizer_user.sudo()._sync_google_calendar(self.google_service)
for i, event in enumerate(recurrence.calendar_event_ids.sorted("start")):
self.assertEqual(event.attendee_ids[1].state, expected_states[i])
attendees = self.env['calendar.attendee'].search([
('partner_id', '=', self.attendee_user.partner_id.id)
]).sorted(key=lambda r: r.event_id.start)
for i, expected_state in enumerate(expected_states):
self.assertEqual(attendees[i].state, expected_state)
@patch.object(GoogleCalendarService, 'get_events')
def test_accepting_recurrent_event_with_following_events_option_synced_by_attendee(self, mock_get_events):
@@ -2075,8 +2089,11 @@ class TestSyncGoogle2Odoo(TestSyncGoogle):
expected_states = ["needsAction", "needsAction", "accepted", "accepted"]
with self.mock_datetime_and_now("2024-04-22"):
self.attendee_user.sudo()._sync_google_calendar(self.google_service)
for i, event in enumerate(recurrence.calendar_event_ids.sorted("start")):
self.assertEqual(event.attendee_ids[1].state, expected_states[i])
attendees = self.env['calendar.attendee'].search([
('partner_id', '=', self.attendee_user.partner_id.id)
]).sorted(key=lambda r: r.event_id.start)
for i, expected_state in enumerate(expected_states):
self.assertEqual(attendees[i].state, expected_state)
@patch.object(GoogleCalendarService, 'get_events')
def test_accepting_recurrent_event_with_all_following_option_synced_by_organizer(self, mock_get_events):
@@ -2106,5 +2123,8 @@ class TestSyncGoogle2Odoo(TestSyncGoogle):
expected_states = ["needsAction", "needsAction", "accepted", "accepted"]
with self.mock_datetime_and_now("2024-04-22"):
self.organizer_user.sudo()._sync_google_calendar(self.google_service)
for i, event in enumerate(recurrence.calendar_event_ids.sorted("start")):
self.assertEqual(event.attendee_ids[1].state, expected_states[i])
attendees = self.env['calendar.attendee'].search([
('partner_id', '=', self.attendee_user.partner_id.id)
]).sorted(key=lambda r: r.event_id.start)
for i, expected_state in enumerate(expected_states):
self.assertEqual(attendees[i].state, expected_state)