[IMP] website_slides: quickly lint tests

Purpose is to make a quick reordering / linting of tests while passing by.

Task-2607416

Part-of: odoo/odoo#74171
This commit is contained in:
Thibault Delavallée
2022-02-28 11:07:37 +00:00
parent fc1f3476d4
commit c0d56da9b0
8 changed files with 159 additions and 131 deletions
+4 -3
View File
@@ -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
+35 -14
View File
@@ -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({
@@ -6,6 +6,7 @@ from odoo.tests import HttpCase
class TestEmbedDetection(HttpCase, common.SlidesCase):
@classmethod
def setUpClass(cls):
super(TestEmbedDetection, cls).setUpClass()
@@ -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')
+1 -2
View File
@@ -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
@@ -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)
@@ -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"):
@@ -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)