File: test_utm.py

package info (click to toggle)
odoo 18.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 878,716 kB
  • sloc: javascript: 927,937; python: 685,670; xml: 388,524; sh: 1,033; sql: 415; makefile: 26
file content (85 lines) | stat: -rw-r--r-- 2,915 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo.addons.test_mass_mailing.tests import common
from odoo.tests import tagged, users


@tagged("utm")
class TestUTM(common.TestMassMailCommon):

    @users("employee")
    def test_utm_source_mixin_name(self):
        """ Test name management with source mixin, as name should be unique
        and automatically incremented """
        sources = self.env["utm.test.source.mixin"].create([
            {
                'name': 'Test',
                'title': 'Test',
            }
            for idx in range(5)]
        )
        self.assertListEqual(
            sources.mapped('name'),
            ["Test", "Test [2]", "Test [3]", "Test [4]", "Test [5]"]
        )

    @users("employee")
    def test_utm_source_mixin_name_brackets(self):
        """ Test with brackets """
        false_dupes = self.env["utm.test.source.mixin"].create([
            {
                'name': 'NewTest [2]',
                'title': 'NewTest',
            }
            for idx in range(3)] + [
            {
                'name': 'NewTest [3]',
                'title': 'NewTest',
            }, {
                'name': 'NewTest',
                'title': 'NewTest',
            }]
        )
        self.assertListEqual(
            false_dupes.mapped('name'),
            ["NewTest [2]", "NewTest", "NewTest [3]", "NewTest [4]", "NewTest [5]"]
        )

        new_source = self.env["utm.test.source.mixin"].create({
            "name": "OtherTest [2]",
        })
        self.assertEqual(new_source.name, "OtherTest [2]")

    @users("employee")
    def test_utm_source_mixin_name_cross_model(self):
        """ Uniqueness of source should be ensured cross models. For this purpose
        we use two models using the utm.source.mixin, allowing to check conflict
        management between models. """
        source_1 = self.env["utm.test.source.mixin"].create({
            "name": "Test",
            "title": "Test",
        })
        self.assertEqual(source_1.name, "Test")
        self.assertEqual(source_1.title, "Test")

        source_other_1 = self.env["utm.test.source.mixin.other"].create({
            "name": "Test",
            "title": "Test",
        })
        self.assertEqual(source_other_1.name, "Test [2]")
        self.assertEqual(source_other_1.title, "Test")

        source_other_2 = self.env["utm.test.source.mixin.other"].create({
            "name": "New",
            "title": "New",
        })
        self.assertEqual(source_other_2.name, "New")
        self.assertEqual(source_other_2.title, "New")

        source_other_2.write({"name": "Test"})
        self.assertEqual(source_other_2.name, "Test [3]")
        self.assertEqual(source_other_2.title, "New")

        source_2 = source_1.copy()
        self.assertEqual(source_2.name, "Test [4]")
        self.assertEqual(source_2.title, "Test")