File: test_share_controllers.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-- 3,553 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
import json
import base64

from odoo.tests.common import HttpCase
from odoo.tools import mute_logger

from .common import DashboardTestCommon

class TestShareController(DashboardTestCommon, HttpCase):
    def test_dashboard_share_portal(self):
        dashboard = self.create_dashboard()
        share = self.share_dashboard(dashboard)
        response = self.url_open(f"/dashboard/share/{share.id}/{share.access_token}")
        self.assertEqual(response.status_code, 200)

    def test_dashboard_share_portal_wrong_token(self):
        dashboard = self.create_dashboard()
        share = self.share_dashboard(dashboard)
        with mute_logger('odoo.http'):
            response = self.url_open(f"/dashboard/share/{share.id}/a-random-token")
        self.assertEqual(response.status_code, 403)

    def test_public_dashboard_data(self):
        dashboard = self.create_dashboard()
        share = self.share_dashboard(dashboard)
        response = self.url_open(f"/dashboard/data/{share.id}/{share.access_token}")
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json(), json.loads(dashboard.spreadsheet_data))

    def test_public_dashboard_data_wrong_token(self):
        dashboard = self.create_dashboard()
        share = self.share_dashboard(dashboard)
        with mute_logger('odoo.http'):  # mute 403 warning
            response = self.url_open(f"/dashboard/data/{share.id}/a-random-token")
        self.assertEqual(response.status_code, 403)

    def test_public_dashboard_revoked_access(self):
        dashboard = self.create_dashboard()
        with self.with_user(self.user.login):
            share = self.share_dashboard(dashboard)

        response = self.url_open(f"/dashboard/data/{share.id}/{share.access_token}")
        self.assertEqual(response.status_code, 200) # access granted

        self.user.groups_id -= self.group # revoke access

        with mute_logger('odoo.http'):  # mute 403 warning
            response = self.url_open(f"/dashboard/data/{share.id}/{share.access_token}")
        self.assertEqual(response.status_code, 403)

    def test_download_dashboard(self):
        dashboard = self.create_dashboard()
        share = self.share_dashboard(dashboard)
        share.excel_export = base64.b64encode(b"test")
        response = self.url_open(f"/dashboard/download/{share.id}/{share.access_token}")
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, b"test")

    def test_download_dashboard_wrong_token(self):
        dashboard = self.create_dashboard()
        share = self.share_dashboard(dashboard)
        share.excel_export = base64.b64encode(b"test")
        with mute_logger('odoo.http'):  # mute 403 warning
            response = self.url_open(f"/dashboard/download/{share.id}/a-random-token")
        self.assertEqual(response.status_code, 403)

    def test_download_dashboard_revoked_access(self):
        dashboard = self.create_dashboard()
        with self.with_user(self.user.login):
            share = self.share_dashboard(dashboard)
        share.excel_export = base64.b64encode(b"test")
        response = self.url_open(f"/dashboard/download/{share.id}/{share.access_token}")
        self.assertEqual(response.status_code, 200) # access granted

        self.user.groups_id -= self.group # revoke access

        with mute_logger('odoo.http'):  # mute 403 warning
            response = self.url_open(f"/dashboard/download/{share.id}/{share.access_token}")
        self.assertEqual(response.status_code, 403)