diff --git a/addons/website_slides/tests/__init__.py b/addons/website_slides/tests/__init__.py index 3810dd0fad5..a0f9220e40c 100644 --- a/addons/website_slides/tests/__init__.py +++ b/addons/website_slides/tests/__init__.py @@ -3,9 +3,10 @@ from . import common from . import test_embed_detection -from . import test_karma -from . import test_resources +from . import test_gamification_karma from . import test_security -from . import test_slide_utils +from . import test_slide_channel +from . import test_slide_resource +from . import test_slide_slide from . import test_statistics from . import test_ui_wslides diff --git a/addons/website_slides/tests/common.py b/addons/website_slides/tests/common.py index 73111d1eda1..d3288dc5669 100644 --- a/addons/website_slides/tests/common.py +++ b/addons/website_slides/tests/common.py @@ -1,44 +1,65 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo.tests import common -from odoo.addons.mail.tests.common import mail_new_test_user +from odoo.addons.mail.tests.common import mail_new_test_user, MailCommon -class SlidesCase(common.TransactionCase): +class SlidesCase(MailCommon): @classmethod def setUpClass(cls): super(SlidesCase, cls).setUpClass() cls.user_officer = mail_new_test_user( - cls.env, name='Ophélie Officer', login='user_officer', email='officer@example.com', - groups='base.group_user,website_slides.group_website_slides_officer' + cls.env, + email='officer@example.com', + groups='base.group_user,website_slides.group_website_slides_officer', + login='user_officer', + name='Ophélie Officer', + notification_type='email', ) cls.user_manager = mail_new_test_user( - cls.env, name='Manuel Manager', login='user_manager', email='manager@example.com', - groups='base.group_user,website_slides.group_website_slides_manager' + cls.env, + email='manager@example.com', + login='user_manager', + groups='base.group_user,website_slides.group_website_slides_manager', + name='Manuel Manager', + notification_type='email', ) cls.user_emp = mail_new_test_user( - cls.env, name='Eglantine Employee', login='user_emp', email='employee@example.com', - groups='base.group_user' + cls.env, + email='employee@example.com', + groups='base.group_user', + login='user_emp', + name='Eglantine Employee', + notification_type='email', ) cls.user_portal = mail_new_test_user( - cls.env, name='Patrick Portal', login='user_portal', email='portal@example.com', - groups='base.group_portal' + cls.env, + email='portal@example.com', + groups='base.group_portal', + login='user_portal', + name='Patrick Portal', + notification_type='email', ) cls.user_public = mail_new_test_user( - cls.env, name='Pauline Public', login='user_public', email='public@example.com', - groups='base.group_public' + cls.env, + email='public@example.com', + groups='base.group_public', + login='user_public', + name='Pauline Public', + notification_type='email', ) cls.customer = cls.env['res.partner'].create({ + 'country_id': cls.env.ref('base.be').id, + 'email': 'customer@customer.example.com', + 'mobile': '0456001122', 'name': 'Caroline Customer', - 'email': 'customer@example.com', }) cls.channel = cls.env['slide.channel'].with_user(cls.user_officer).create({ diff --git a/addons/website_slides/tests/test_embed_detection.py b/addons/website_slides/tests/test_embed_detection.py index 5c61ffaa00d..14340313cc0 100644 --- a/addons/website_slides/tests/test_embed_detection.py +++ b/addons/website_slides/tests/test_embed_detection.py @@ -6,6 +6,7 @@ from odoo.tests import HttpCase class TestEmbedDetection(HttpCase, common.SlidesCase): + @classmethod def setUpClass(cls): super(TestEmbedDetection, cls).setUpClass() diff --git a/addons/website_slides/tests/test_karma.py b/addons/website_slides/tests/test_gamification_karma.py similarity index 86% rename from addons/website_slides/tests/test_karma.py rename to addons/website_slides/tests/test_gamification_karma.py index a9453da8caf..d7e0643e681 100644 --- a/addons/website_slides/tests/test_karma.py +++ b/addons/website_slides/tests/test_gamification_karma.py @@ -7,7 +7,7 @@ from odoo.tests.common import users from odoo.tools import mute_logger -@tagged('functional') +@tagged('gamification') class TestKarmaGain(common.SlidesCase): def setUp(self): @@ -25,20 +25,20 @@ class TestKarmaGain(common.SlidesCase): 'karma_gen_channel_rank': 10, }) - self.slide_2_0 = self.env['slide.slide'].with_user(self.user_officer).create({ - 'name': 'How to travel through space and time', - 'channel_id': self.channel_2.id, - 'slide_category': 'document', - 'is_published': True, - 'completion_time': 2.0, - }) - self.slide_2_1 = self.env['slide.slide'].with_user(self.user_officer).create({ - 'name': 'How to duplicate yourself', - 'channel_id': self.channel_2.id, - 'slide_category': 'document', - 'is_published': True, - 'completion_time': 2.0, - }) + self.slide_2_0, self.slide_2_1 = self.env['slide.slide'].with_user(self.user_officer).create([ + {'name': 'How to travel through space and time', + 'channel_id': self.channel_2.id, + 'slide_category': 'document', + 'is_published': True, + 'completion_time': 2.0, + }, + {'name': 'How to duplicate yourself', + 'channel_id': self.channel_2.id, + 'slide_category': 'document', + 'is_published': True, + 'completion_time': 2.0, + } + ]) @mute_logger('odoo.models') @users('user_emp', 'user_portal', 'user_officer') diff --git a/addons/website_slides/tests/test_security.py b/addons/website_slides/tests/test_security.py index 1f5eecc3143..9dddaa7e4e3 100644 --- a/addons/website_slides/tests/test_security.py +++ b/addons/website_slides/tests/test_security.py @@ -2,9 +2,8 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo.addons.website_slides.tests import common -from odoo.exceptions import AccessError, UserError +from odoo.exceptions import AccessError from odoo.tests import tagged -from odoo.tests.common import users from odoo.tools import mute_logger diff --git a/addons/website_slides/tests/test_slide_utils.py b/addons/website_slides/tests/test_slide_channel.py similarity index 65% rename from addons/website_slides/tests/test_slide_utils.py rename to addons/website_slides/tests/test_slide_channel.py index e46130a61e1..21085e4fe4b 100644 --- a/addons/website_slides/tests/test_slide_utils.py +++ b/addons/website_slides/tests/test_slide_channel.py @@ -165,98 +165,3 @@ class TestSequencing(slides_common.SlidesCase): self.assertEqual(self.category.sequence, 4) self.assertEqual(self.slide_2.sequence, 5) self.assertEqual([s.id for s in self.channel.slide_ids], [self.slide.id, new_category.id, self.slide_3.id, self.category.id, self.slide_2.id]) - - -class TestFromURL(slides_common.SlidesCase): - def test_video_youtube(self): - youtube_urls = { - 'W0JQcpGLSFw': [ - 'https://youtu.be/W0JQcpGLSFw', - 'https://www.youtube.com/watch?v=W0JQcpGLSFw', - 'https://www.youtube.com/watch?v=W0JQcpGLSFw&list=PL1-aSABtP6ACZuppkBqXFgzpNb2nVctZx', - ], - 'vmhB-pt7EfA': [ # id starts with v, it is important - 'https://youtu.be/vmhB-pt7EfA', - 'https://www.youtube.com/watch?feature=youtu.be&v=vmhB-pt7EfA', - 'https://www.youtube.com/watch?v=vmhB-pt7EfA&list=PL1-aSABtP6ACZuppkBqXFgzpNb2nVctZx&index=7', - ], - 'hlhLv0GN1hA': [ - 'https://www.youtube.com/v/hlhLv0GN1hA', - 'https://www.youtube.com/embed/hlhLv0GN1hA', - 'https://www.youtube-nocookie.com/embed/hlhLv0GN1hA', - 'https://m.youtube.com/watch?v=hlhLv0GN1hA', - ], - } - - Slide = self.env['slide.slide'].with_context(website_slides_skip_fetch_metadata=True) - - # test various YouTube URL formats - for youtube_id, urls in youtube_urls.items(): - for url in urls: - with self.subTest(url=url, id=youtube_id): - slide = Slide.create({ - 'name': 'dummy', - 'channel_id': self.channel.id, - 'url': url, - 'slide_category': 'video' - }) - self.assertEqual('youtube', slide.video_source_type) - self.assertEqual(youtube_id, slide.youtube_id) - - def test_video_google_drive(self): - google_drive_urls = { - '1qU5nHVNbz_r84P_IS5kDzoCuC1h5ZAZR': [ - 'https://drive.google.com/file/d/1qU5nHVNbz_r84P_IS5kDzoCuC1h5ZAZR/view?usp=sharing', - 'https://drive.google.com/file/d/1qU5nHVNbz_r84P_IS5kDzoCuC1h5ZAZR', - ], - } - - Slide = self.env['slide.slide'].with_context(website_slides_skip_fetch_metadata=True) - - # test various Google Drive URL formats - for google_drive_id, urls in google_drive_urls.items(): - for url in urls: - with self.subTest(url=url, id=google_drive_id): - slide = Slide.create({ - 'name': 'dummy', - 'channel_id': self.channel.id, - 'url': url, - 'slide_category': 'video' - }) - self.assertEqual('google_drive', slide.video_source_type) - self.assertEqual(google_drive_id, slide.google_drive_id) - - def test_video_vimeo(self): - vimeo_urls = { - # regular URL from Vimeo - '545859999': [ - 'https://vimeo.com/545859999', - 'https://vimeo.com/545859999?autoplay=1', - ], - # test channel URL from Vimeo - '551979139': [ - 'https://vimeo.com/channels/staffpicks/551979139', - 'https://vimeo.com/channels/staffpicks/551979139?autoplay=1', - ], - # test URL from Vimeo with setting 'with URL only' - # we need to store both the ID and the token, see '_compute_embed_code' method for details - '545859999/94dd03ddb0': [ - 'https://vimeo.com/545859999/94dd03ddb0', - 'https://vimeo.com/545859999/94dd03ddb0?autoplay=1', - ], - } - - Slide = self.env['slide.slide'].with_context(website_slides_skip_fetch_metadata=True) - - # test various Vimeo URL formats - for vimeo_id, urls in vimeo_urls.items(): - for url in urls: - with self.subTest(url=url, id=vimeo_id): - slide = Slide.create({ - 'name': 'dummy', - 'channel_id': self.channel.id, - 'url': url, - 'slide_category': 'video' - }) - self.assertEqual('vimeo', slide.video_source_type) - self.assertEqual(vimeo_id, slide.vimeo_id) diff --git a/addons/website_slides/tests/test_resources.py b/addons/website_slides/tests/test_slide_resource.py similarity index 90% rename from addons/website_slides/tests/test_resources.py rename to addons/website_slides/tests/test_slide_resource.py index 561a3a6d3aa..a10298dd737 100644 --- a/addons/website_slides/tests/test_resources.py +++ b/addons/website_slides/tests/test_slide_resource.py @@ -14,19 +14,21 @@ class TestResources(common.SlidesCase): @users('user_officer') @mute_logger('odoo') def test_constraints(self): - self.link = self.env["slide.slide.resource"].create({ + link = self.env["slide.slide.resource"].create({ 'name': 'Test Link', 'resource_type': 'url', 'link': 'https://www.example.com', 'slide_id': self.slide.id, }) + self.assertFalse(link.data) - self.resource = self.env["slide.slide.resource"].create({ + resource = self.env["slide.slide.resource"].create({ 'name': 'Test Resource', 'resource_type': 'file', 'data': '1111', 'slide_id': self.slide.id, }) + self.assertFalse(resource.link) self.assertEqual(len(self.slide.slide_resource_ids), 2) with self.assertRaises(ValidationError, msg="Cannot have a type link with a file"): diff --git a/addons/website_slides/tests/test_slide_slide.py b/addons/website_slides/tests/test_slide_slide.py new file mode 100644 index 00000000000..da2c9483094 --- /dev/null +++ b/addons/website_slides/tests/test_slide_slide.py @@ -0,0 +1,99 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.addons.website_slides.tests import common as slides_common + + +class TestFromURL(slides_common.SlidesCase): + def test_video_youtube(self): + youtube_urls = { + 'W0JQcpGLSFw': [ + 'https://youtu.be/W0JQcpGLSFw', + 'https://www.youtube.com/watch?v=W0JQcpGLSFw', + 'https://www.youtube.com/watch?v=W0JQcpGLSFw&list=PL1-aSABtP6ACZuppkBqXFgzpNb2nVctZx', + ], + 'vmhB-pt7EfA': [ # id starts with v, it is important + 'https://youtu.be/vmhB-pt7EfA', + 'https://www.youtube.com/watch?feature=youtu.be&v=vmhB-pt7EfA', + 'https://www.youtube.com/watch?v=vmhB-pt7EfA&list=PL1-aSABtP6ACZuppkBqXFgzpNb2nVctZx&index=7', + ], + 'hlhLv0GN1hA': [ + 'https://www.youtube.com/v/hlhLv0GN1hA', + 'https://www.youtube.com/embed/hlhLv0GN1hA', + 'https://www.youtube-nocookie.com/embed/hlhLv0GN1hA', + 'https://m.youtube.com/watch?v=hlhLv0GN1hA', + ], + } + + Slide = self.env['slide.slide'].with_context(website_slides_skip_fetch_metadata=True) + + # test various YouTube URL formats + for youtube_id, urls in youtube_urls.items(): + for url in urls: + with self.subTest(url=url, id=youtube_id): + slide = Slide.create({ + 'name': 'dummy', + 'channel_id': self.channel.id, + 'url': url, + 'slide_category': 'video' + }) + self.assertEqual('youtube', slide.video_source_type) + self.assertEqual(youtube_id, slide.youtube_id) + + def test_video_google_drive(self): + google_drive_urls = { + '1qU5nHVNbz_r84P_IS5kDzoCuC1h5ZAZR': [ + 'https://drive.google.com/file/d/1qU5nHVNbz_r84P_IS5kDzoCuC1h5ZAZR/view?usp=sharing', + 'https://drive.google.com/file/d/1qU5nHVNbz_r84P_IS5kDzoCuC1h5ZAZR', + ], + } + + Slide = self.env['slide.slide'].with_context(website_slides_skip_fetch_metadata=True) + + # test various Google Drive URL formats + for google_drive_id, urls in google_drive_urls.items(): + for url in urls: + with self.subTest(url=url, id=google_drive_id): + slide = Slide.create({ + 'name': 'dummy', + 'channel_id': self.channel.id, + 'url': url, + 'slide_category': 'video' + }) + self.assertEqual('google_drive', slide.video_source_type) + self.assertEqual(google_drive_id, slide.google_drive_id) + + def test_video_vimeo(self): + vimeo_urls = { + # regular URL from Vimeo + '545859999': [ + 'https://vimeo.com/545859999', + 'https://vimeo.com/545859999?autoplay=1', + ], + # test channel URL from Vimeo + '551979139': [ + 'https://vimeo.com/channels/staffpicks/551979139', + 'https://vimeo.com/channels/staffpicks/551979139?autoplay=1', + ], + # test URL from Vimeo with setting 'with URL only' + # we need to store both the ID and the token, see '_compute_embed_code' method for details + '545859999/94dd03ddb0': [ + 'https://vimeo.com/545859999/94dd03ddb0', + 'https://vimeo.com/545859999/94dd03ddb0?autoplay=1', + ], + } + + Slide = self.env['slide.slide'].with_context(website_slides_skip_fetch_metadata=True) + + # test various Vimeo URL formats + for vimeo_id, urls in vimeo_urls.items(): + for url in urls: + with self.subTest(url=url, id=vimeo_id): + slide = Slide.create({ + 'name': 'dummy', + 'channel_id': self.channel.id, + 'url': url, + 'slide_category': 'video' + }) + self.assertEqual('vimeo', slide.video_source_type) + self.assertEqual(vimeo_id, slide.vimeo_id)