summaryrefslogtreecommitdiff
path: root/addons/google_calendar/tests/test_sync_common.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/google_calendar/tests/test_sync_common.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/google_calendar/tests/test_sync_common.py')
-rw-r--r--addons/google_calendar/tests/test_sync_common.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/addons/google_calendar/tests/test_sync_common.py b/addons/google_calendar/tests/test_sync_common.py
new file mode 100644
index 00000000..d3d6062d
--- /dev/null
+++ b/addons/google_calendar/tests/test_sync_common.py
@@ -0,0 +1,63 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from datetime import datetime, date
+from dateutil.relativedelta import relativedelta
+from unittest.mock import MagicMock, patch
+
+from odoo.tests.common import SavepointCase
+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
+from odoo.addons.google_account.models.google_service import TIMEOUT
+
+
+def patch_api(func):
+ @patch.object(GoogleSync, '_google_insert', MagicMock())
+ @patch.object(GoogleSync, '_google_delete', MagicMock())
+ @patch.object(GoogleSync, '_google_patch', MagicMock())
+ 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(SavepointCase):
+
+ def setUp(self):
+ super().setUp()
+ self.google_service = GoogleCalendarService(self.env['google.service'])
+
+ def assertGoogleEventDeleted(self, google_id):
+ GoogleSync._google_delete.assert_called()
+ args, kwargs = 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()