19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:32:02 +01:00
parent 62d197ac8b
commit 184bb0e321
667 changed files with 691406 additions and 239886 deletions

View file

@ -1,2 +1,5 @@
from . import test_spreadsheet_dashboard
from . import test_dashboard_data
from . import test_dashboard_share
from . import test_dashboard_controllers
from . import test_share_dashboard_tour
from . import test_share_controllers

View file

@ -0,0 +1,34 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import Command
from odoo.tests.common import TransactionCase, new_test_user
class DashboardTestCommon(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.group = cls.env["res.groups"].create({"name": "test group"})
cls.user = new_test_user(cls.env, login="Raoul")
cls.user.group_ids |= cls.group + cls.env.ref('base.group_allow_export', raise_if_not_found=False)
def create_dashboard(self, group=None):
dashboard_group = group or self.env["spreadsheet.dashboard.group"].create({
"name": "Dashboard group"
})
dashboard = self.env["spreadsheet.dashboard"].create(
{
"name": "a dashboard",
"group_ids": [Command.set(self.group.ids)],
"dashboard_group_id": dashboard_group.id,
}
)
return dashboard
def share_dashboard(self, dashboard):
share = self.env["spreadsheet.dashboard.share"].create(
{
"dashboard_id": dashboard.id,
"spreadsheet_data": dashboard.spreadsheet_data,
}
)
return share

View file

@ -0,0 +1,62 @@
from odoo.tests.common import HttpCase
from .common import DashboardTestCommon
class TestDashboardController(DashboardTestCommon, HttpCase):
def test_load_with_user_locale(self):
self.authenticate(self.user.login, self.user.password)
dashboard = self.create_dashboard().with_user(self.user)
self.user.lang = 'en_US'
response = self.url_open(f'/spreadsheet/dashboard/data/{dashboard.id}')
data = response.json()
locale = data['snapshot']['settings']['locale']
self.assertEqual(locale['code'], 'en_US')
self.assertEqual(len(data['revisions']), 0)
self.env.ref('base.lang_fr').active = True
self.user.lang = 'fr_FR'
response = self.url_open(f'/spreadsheet/dashboard/data/{dashboard.id}')
data = response.json()
locale = data['snapshot']['settings']['locale']
self.assertEqual(locale['code'], 'fr_FR')
self.assertEqual(len(data['revisions']), 0)
def test_load_with_company_currency(self):
self.authenticate(self.user.login, self.user.password)
dashboard = self.create_dashboard().with_user(self.user)
response = self.url_open(f'/spreadsheet/dashboard/data/{dashboard.id}')
data = response.json()
self.assertEqual(
data['default_currency'],
self.env['res.currency'].get_company_currency_for_spreadsheet()
)
def test_translation_namespace(self):
dashboard = self.create_dashboard()
self.env['ir.model.data'].create({
'name': 'test_translation_namespace',
'module': 'spreadsheet_dashboard',
'res_id': dashboard.id,
'model': dashboard._name,
})
self.authenticate(self.user.login, self.user.password)
response = self.url_open('/spreadsheet/dashboard/data/%s' % dashboard.id)
data = response.json()
self.assertEqual(data["translation_namespace"], "spreadsheet_dashboard")
def test_get_sample_dashboard(self):
self.authenticate(self.user.login, self.user.password)
sample_dashboard_path = 'spreadsheet_dashboard/tests/data/sample_dashboard.json'
dashboard = self.create_dashboard()
dashboard.sample_dashboard_file_path = sample_dashboard_path
dashboard.main_data_model_ids = [(4, self.env.ref('base.model_res_bank').id)]
self.env['res.bank'].sudo().search([]).action_archive()
response = self.url_open(f'/spreadsheet/dashboard/data/{dashboard.id}')
self.assertEqual(response.json(), {
'is_sample': True,
'snapshot': {'sheets': []},
})

View file

@ -1,14 +0,0 @@
from odoo.addons.spreadsheet.tests.validate_spreadsheet_data import (
ValidateSpreadsheetData,
)
from odoo.tests.common import tagged
@tagged("-at_install", "post_install")
class TestSpreadsheetDashboardData(ValidateSpreadsheetData):
def test_validate_dashboard_data(self):
"""validate fields and models used in dashboards"""
dashboards = self.env["spreadsheet.dashboard"].search([])
for dashboard in dashboards:
with self.subTest(dashboard.name):
self.validate_spreadsheet_data(dashboard.raw, dashboard.name)

View file

@ -0,0 +1,41 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from .common import DashboardTestCommon
from odoo.exceptions import AccessError
EXCEL_FILES = [
{
"content": '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"/>',
"path": "[Content_Types].xml",
}
]
class DashboardSharing(DashboardTestCommon):
def test_share_url(self):
dashboard = self.create_dashboard()
share_vals = {
"spreadsheet_data": dashboard.spreadsheet_data,
"dashboard_id": dashboard.id,
"excel_files": EXCEL_FILES,
}
url = self.env["spreadsheet.dashboard.share"].action_get_share_url(share_vals)
share = self.env["spreadsheet.dashboard.share"].search(
[("dashboard_id", "=", dashboard.id)]
)
self.assertEqual(url, share.full_url)
self.assertEqual(share.dashboard_id, dashboard)
self.assertTrue(share.excel_export)
def test_can_create_own(self):
dashboard = self.create_dashboard()
with self.with_user(self.user.login):
share = self.share_dashboard(dashboard)
self.assertTrue(share)
self.assertTrue(share.create_uid, self.user)
def test_cannot_read_others(self):
dashboard = self.create_dashboard()
share = self.share_dashboard(dashboard)
with self.assertRaises(AccessError):
share.with_user(self.user).access_token

View file

@ -0,0 +1,103 @@
import json
import base64
from odoo.tests.common import HttpCase, new_test_user
from odoo.tools import mute_logger
from .common import DashboardTestCommon
class TestShareController(DashboardTestCommon, HttpCase):
@classmethod
@mute_logger('odoo.tests', 'odoo.addons.auth_signup.models.res_users')
def setUpClass(cls):
super().setUpClass()
cls.alex = new_test_user(cls.env, login='AlexPort', groups='base.group_user,base.group_allow_export')
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.group_ids -= 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")
self.authenticate('AlexPort', 'AlexPort')
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_no_export(self):
dashboard = self.create_dashboard()
share = self.share_dashboard(dashboard)
share.excel_export = base64.b64encode(b"test")
self.authenticate('AlexPort', 'AlexPort')
response = self.url_open(f"/dashboard/download/{share.id}/{share.access_token}")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, b"test")
self.alex.group_ids -= self.env.ref('base.group_allow_export', raise_if_not_found=False) # revoke export right
with mute_logger('odoo.http'): # mute 400 warning
response = self.url_open(f"/dashboard/download/{share.id}/{share.access_token}")
self.assertEqual(response.status_code, 422)
def test_download_dashboard_wrong_token(self):
dashboard = self.create_dashboard()
share = self.share_dashboard(dashboard)
share.excel_export = base64.b64encode(b"test")
self.authenticate('AlexPort', 'AlexPort')
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()
self.authenticate('AlexPort', 'AlexPort')
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.group_ids -= 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)

View file

@ -0,0 +1,20 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from .common import DashboardTestCommon
from odoo.tests import tagged
from odoo.tests.common import HttpCase
@tagged("post_install", "-at_install")
class TestDashboardShareTour(DashboardTestCommon, HttpCase):
def test_open_public_dashboard(self):
"""check the public spreadsheet page can be opened without error"""
dashboard = self.create_dashboard()
share = self.share_dashboard(dashboard)
# web_tour is not part of the public dashboard assets bundle.
# We can't use the start_tour helper method.
self.browser_js(
"/dashboard/share/%s/%s" % (share.id, share.access_token),
"console.log('test successful');",
ready="odoo.isReady",
)

View file

@ -1,10 +1,11 @@
import base64
import json
from odoo.tests.common import TransactionCase, Form
from odoo.exceptions import UserError, ValidationError
from odoo.exceptions import UserError
from .common import DashboardTestCommon
class TestSpreadsheetDashboard(TransactionCase):
class TestSpreadsheetDashboard(DashboardTestCommon):
def test_create_with_default_values(self):
group = self.env["spreadsheet.dashboard.group"].create(
{"name": "a group"}
@ -17,8 +18,8 @@ class TestSpreadsheetDashboard(TransactionCase):
)
self.assertEqual(dashboard.group_ids, self.env.ref("base.group_user"))
self.assertEqual(
dashboard.raw,
b'{"version": 1, "sheets": [{"id": "sheet1", "name": "Sheet1"}]}',
json.loads(dashboard.spreadsheet_data),
dashboard._empty_spreadsheet_data()
)
def test_copy_name(self):
@ -37,21 +38,6 @@ class TestSpreadsheetDashboard(TransactionCase):
copy = dashboard.copy({"name": "a copy"})
self.assertEqual(copy.name, "a copy")
def test_write_raw_data(self):
group = self.env["spreadsheet.dashboard.group"].create(
{"name": "a group"}
)
dashboard = self.env["spreadsheet.dashboard"].create(
{
"name": "a dashboard",
"dashboard_group_id": group.id,
}
)
data = b'{"version": 1, "sheets": [{"id": "sheet1", "name": "Sheet1"}]}'
dashboard.raw = data
self.assertEqual(dashboard.data, base64.encodebytes(data))
def test_unlink_prevent_spreadsheet_group(self):
group = self.env["spreadsheet.dashboard.group"].create(
{"name": "a_group"}
@ -65,13 +51,37 @@ class TestSpreadsheetDashboard(TransactionCase):
with self.assertRaises(UserError, msg="You cannot delete a_group as it is used in another module"):
group.unlink()
def test_onchange_json_data(self):
group = self.env["spreadsheet.dashboard.group"].create(
{"name": "a group"}
)
spreadsheet_form = Form(self.env['spreadsheet.dashboard'])
spreadsheet_form.name = 'Test spreadsheet'
spreadsheet_form.dashboard_group_id = group
spreadsheet_form.data = base64.b64encode(json.dumps({'key': 'value'}).encode('utf-8'))
with self.assertRaises(ValidationError, msg='Invalid JSON Data'):
spreadsheet_form.data = base64.b64encode('invalid json'.encode('utf-8'))
def test_unpublish_dashboard(self):
group = self.env["spreadsheet.dashboard.group"].create({
"name": "Dashboard group"
})
dashboard = self.create_dashboard(group)
self.assertEqual(group.published_dashboard_ids, dashboard)
dashboard.is_published = False
self.assertFalse(group.published_dashboard_ids)
def test_publish_dashboard(self):
group = self.env["spreadsheet.dashboard.group"].create({
"name": "Dashboard group"
})
dashboard = self.create_dashboard(group)
dashboard.is_published = False
self.assertFalse(group.published_dashboard_ids)
dashboard.is_published = True
self.assertEqual(group.published_dashboard_ids, dashboard)
def test_toggle_favorite(self):
dashboard = self.create_dashboard().with_user(self.user)
self.assertFalse(dashboard.is_favorite)
self.assertNotIn(self.user, dashboard.favorite_user_ids)
dashboard.with_user(self.user).action_toggle_favorite()
self.assertTrue(dashboard.is_favorite)
self.assertIn(self.user, dashboard.favorite_user_ids)
dashboard.with_user(self.user).action_toggle_favorite()
self.assertFalse(dashboard.is_favorite)
self.assertNotIn(self.user, dashboard.favorite_user_ids)