Before this commit: The google synchronization dis not properly synced event in some conditions. Some use cases were not properly tested. Recurrent events were regularly badly synchronized with Google. Several issues occured: - events not follow recurrence were duplicated on both Google or Odoo and sometimes deleted when the recurrence was reapplied. - the base_event (first event of the recurrence) was duplicated - miscalculation of the event google_id when they were part of a recurrence but did not followed the rrule. - improper data handling from google. Odoo objets were created with incorrect values - attendee state was not properly sync from Odoo to Google - whole recurrence deletions from google were not properly sync in Odoo - when time fields of a recurrence were modified on Google, modifications were ignored on Odoo - Event timezone were not properly saved on the recurrency. (Odoo saves it on the recurrency and Google on the event) - Odoo considered that all public events are writable bu Odoo users. That would trigger errors as Google implement an access right model on public events - lack of tests - a lot of weird behaviors resulting from these problems. closes odoo/odoo#68412 Taskid: 2456498 Opw: 2299834 X-original-commit: dcfc8b7896f079e8e4474392807d9c53cb7e94f3 Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com> Co-authored-by: Lucas Lefèvre <lul@odoo.com> Co-authored-by: Arnaud Joset <arj@odoo.com>
60 lines
2.5 KiB
Python
60 lines
2.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from odoo.tests.common import TransactionCase
|
|
from odoo.addons.google_calendar.utils.google_calendar import GoogleCalendarService
|
|
from odoo.addons.google_calendar.models.res_users import User
|
|
from odoo.addons.google_calendar.models.google_sync import GoogleSync
|
|
|
|
def patch_api(func):
|
|
@patch.object(GoogleSync, '_google_insert', MagicMock(spec=GoogleSync._google_insert))
|
|
@patch.object(GoogleSync, '_google_delete', MagicMock(spec=GoogleSync._google_delete))
|
|
@patch.object(GoogleSync, '_google_patch', MagicMock(spec=GoogleSync._google_patch))
|
|
def patched(self, *args, **kwargs):
|
|
return func(self, *args, **kwargs)
|
|
return patched
|
|
|
|
@patch.object(User, '_get_google_calendar_token', lambda user: 'dummy-token')
|
|
class TestSyncGoogle(TransactionCase):
|
|
|
|
def setUp(self):
|
|
super().setUp()
|
|
self.google_service = GoogleCalendarService(self.env['google.service'])
|
|
|
|
def assertGoogleEventDeleted(self, google_id):
|
|
GoogleSync._google_delete.assert_called()
|
|
args, dummy = GoogleSync._google_delete.call_args
|
|
self.assertEqual(args[1], google_id, "Event should have been deleted")
|
|
|
|
def assertGoogleEventNotDeleted(self):
|
|
GoogleSync._google_delete.assert_not_called()
|
|
|
|
def assertGoogleEventInserted(self, values, timeout=None):
|
|
expected_args = (values,)
|
|
expected_kwargs = {'timeout': timeout} if timeout else {}
|
|
GoogleSync._google_insert.assert_called_once()
|
|
args, kwargs = GoogleSync._google_insert.call_args
|
|
self.assertEqual(args[1:], expected_args) # skip Google service arg
|
|
self.assertEqual(kwargs, expected_kwargs)
|
|
|
|
def assertGoogleEventNotInserted(self):
|
|
GoogleSync._google_insert.assert_not_called()
|
|
|
|
def assertGoogleEventPatched(self, google_id, values, timeout=None):
|
|
expected_args = (google_id, values)
|
|
expected_kwargs = {'timeout': timeout} if timeout else {}
|
|
GoogleSync._google_patch.assert_called_once()
|
|
args, kwargs = GoogleSync._google_patch.call_args
|
|
self.assertEqual(args[1:], expected_args) # skip Google service arg
|
|
self.assertEqual(kwargs, expected_kwargs)
|
|
|
|
def assertGoogleEventNotPatched(self):
|
|
GoogleSync._google_patch.assert_not_called()
|
|
|
|
def assertGoogleAPINotCalled(self):
|
|
self.assertGoogleEventNotPatched()
|
|
self.assertGoogleEventNotInserted()
|
|
self.assertGoogleEventNotDeleted()
|