File: test_website_event.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 (79 lines) | stat: -rw-r--r-- 2,982 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
# Part of Odoo. See LICENSE file for full copyright and licensing details.
# -*- coding: utf-8 -*-

from odoo.tests import tagged
from odoo.tests.common import TransactionCase
from odoo.tools.image import base64_to_image
from io import BytesIO
from PIL import Image
import base64


@tagged('post_install', '-at_install')
class TestWebsiteEvent(TransactionCase):

    def test_event_app_name(self):
        website0 = self.env['website'].create({'name': 'Foo'})
        self.assertEqual(website0.events_app_name, 'Foo Events')

        website1 = self.env['website'].create({'name': 'Foo', 'events_app_name': 'Bar Events'})
        self.assertEqual(website1.events_app_name, 'Bar Events')

        website2 = self.env['website'].create({'name': 'Foo'})
        self.assertEqual(website2.events_app_name, 'Foo Events')
        website2.write({'name': 'Bar'})
        self.assertEqual(website2.events_app_name, 'Foo Events')

    def test_compute_app_icon(self):

        # Generate image data for JPEG
        jpeg_image = Image.new('RGB', (60, 30), color=(73, 109, 137))
        jpeg_io = BytesIO()
        jpeg_image.save(jpeg_io, format='JPEG')
        jpeg_image_data = jpeg_io.getvalue()

        # Generate image data for JPG
        jpg_image = Image.new('RGB', (60, 30), color=(73, 109, 137))
        jpg_io = BytesIO()
        jpg_image.save(jpg_io, format='JPEG')
        jpg_image_data = jpg_io.getvalue()

        # Generate image data for PNG
        png_image = Image.new('RGB', (60, 30), color=(73, 109, 137))
        png_io = BytesIO()
        png_image.save(png_io, format='PNG')
        png_image_data = png_io.getvalue()

        # Generate image data for SVG
        svg_image_data = b"""<svg xmlns="http://www.w3.org/2000/svg" width="60" height="30" version="1.1">
                            <rect width="100%" height="100%" fill="rgb(73, 109, 137)"/>
                            </svg>
                        """
        # Image data and their respective expected types
        image_data = {
            'png': png_image_data,
            'jpg': jpg_image_data,
            'jpeg': jpeg_image_data,
            'svg': svg_image_data
        }

        for expected_type, image_data in image_data.items():
            # Create a website record
            website = self.env['website'].create({
                'name': 'Test Website',
                'favicon': base64.b64encode(image_data)
            })

            # Call the method to compute app_icon
            website._compute_app_icon()

            if expected_type in ['jpeg', 'png', 'jpg']:
                # Check if app_icon is set
                self.assertTrue(website.app_icon)

                # Check if app_icon is a valid image
                image = base64_to_image(website.app_icon)
                self.assertEqual(image.format.lower(), 'png')
            else:
                # For SVG images, ensure that the app_icon is not set
                self.assertFalse(website.app_icon)