Purpose ======= This commit is used to merge 2 models into 1: `slide.slide.resource` and `slide.slide.link` Specifications ============== These models are merged in order to create a unique table for the *Additional Resources* of a Content. In order to do that, we merged the models into `slide.slide.resource` that will contain either a link or a file. task-2597345 See odoo/enterprise#20480 See odoo/upgrade#2784 Part-of: odoo/odoo#75646
54 lines
1.9 KiB
Python
54 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from psycopg2 import IntegrityError
|
|
|
|
from odoo.addons.website_slides.tests import common
|
|
from odoo.exceptions import ValidationError
|
|
from odoo.tests.common import users
|
|
from odoo.tools import mute_logger
|
|
|
|
|
|
class TestResources(common.SlidesCase):
|
|
|
|
@users('user_officer')
|
|
@mute_logger('odoo')
|
|
def test_constraints(self):
|
|
self.link = self.env["slide.slide.resource"].create({
|
|
'name': 'Test Link',
|
|
'resource_type': 'url',
|
|
'link': 'https://www.example.com',
|
|
'slide_id': self.slide.id,
|
|
})
|
|
|
|
self.resource = self.env["slide.slide.resource"].create({
|
|
'name': 'Test Resource',
|
|
'resource_type': 'file',
|
|
'data': '1111',
|
|
'slide_id': self.slide.id,
|
|
})
|
|
|
|
self.assertEqual(len(self.slide.slide_resource_ids), 2)
|
|
with self.assertRaises(ValidationError, msg="Cannot have a type link with a file"):
|
|
self.env["slide.slide.resource"].create({
|
|
'name': 'Raise Error Test Resource',
|
|
'resource_type': 'url',
|
|
'link': '1111',
|
|
'data': '1111',
|
|
'slide_id': self.slide.id,
|
|
})
|
|
self.assertEqual(len(self.slide.slide_resource_ids), 2)
|
|
with self.assertRaises(IntegrityError, msg="Cannot have a type file with a link"):
|
|
self.env["slide.slide.resource"].create({
|
|
'name': 'Raise Error Test File With Link',
|
|
'resource_type': 'file',
|
|
'link': '1111',
|
|
'slide_id': self.slide.id,
|
|
})
|
|
with self.assertRaises(IntegrityError, msg="Cannot have an empty link"):
|
|
self.env["slide.slide.resource"].create({
|
|
'name': 'Raise Error Test Empty URL',
|
|
'resource_type': 'url',
|
|
'slide_id': self.slide.id,
|
|
})
|