-
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX]document_page_portal: added test cases
- Loading branch information
Davit Lomauridze
committed
Aug 13, 2024
1 parent
5465728
commit a9558fe
Showing
1 changed file
with
82 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,103 @@ | ||
# Copyright 2020 - TODAY, Marcel Savegnago - Escodoo | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
|
||
from unittest.mock import MagicMock, patch | ||
|
||
import odoo.tests | ||
from odoo.http import request | ||
from odoo.tests import common | ||
from odoo.tests.common import tagged | ||
|
||
from odoo.addons.document_page_portal.controllers.portal import CustomerPortal | ||
|
||
|
||
@odoo.tests.tagged("post_install", "-at_install") | ||
class TestPortalDocumentPage(odoo.tests.HttpCase): | ||
def test_01_document_page_portal_tour(self): | ||
# Create a public document | ||
self.env["document.page"].create( | ||
{ | ||
"name": "Test Public Page 1", | ||
"content": "Test content", | ||
"is_public": True, | ||
} | ||
) | ||
# Test the portal tour with a public document | ||
self.browser_js( | ||
"/", | ||
"odoo.__DEBUG__.services['web_tour.tour']" | ||
".run('document_page_portal_tour')", | ||
"odoo.__DEBUG__.services['web_tour.tour']" | ||
".tours.document_page_portal_tour.ready", | ||
login="portal", | ||
) | ||
|
||
def test_02_document_page_portal_tour(self): | ||
def test_02_document_page_portal_search_tour(self): | ||
# Test the portal search functionality via a tour | ||
self.browser_js( | ||
"/", | ||
"odoo.__DEBUG__.services['web_tour.tour']" | ||
".run('document_page_portal_search_tour')", | ||
"odoo.__DEBUG__.services['web_tour.tour']" | ||
".tours.document_page_portal_search_tour.ready", | ||
login="portal", | ||
) | ||
|
||
|
||
@tagged("post_install", "-at_install") | ||
class TestCustomerPortal(common.TransactionCase): | ||
def setUp(self): | ||
super(TestCustomerPortal, self).setUp() | ||
self.customer_portal = CustomerPortal() | ||
|
||
def test_prepare_portal_layout_values(self): | ||
with patch.object(request.env["document.page"], "search_count", return_value=5): | ||
values = self.customer_portal._prepare_portal_layout_values() | ||
self.assertEqual(values["document_page_count"], 5) | ||
|
||
def test_get_archive_groups(self): | ||
model = "document.page" | ||
domain = [("type", "=", "content")] | ||
fields = ["name", "create_date"] | ||
groupby = "create_date" | ||
order = "create_date desc" | ||
|
||
mock_read_group = MagicMock( | ||
return_value=[ | ||
{"create_date": "2023-01-01/2023-12-31", "create_date_count": 10} | ||
] | ||
) | ||
|
||
with patch.object(request.env[model], "_read_group_raw", mock_read_group): | ||
groups = self.customer_portal._get_archive_groups( | ||
model, domain, fields, groupby, order | ||
) | ||
self.assertEqual(len(groups), 1) | ||
self.assertEqual(groups[0]["item_count"], 10) | ||
|
||
def test_document_page_get_page_view_values(self): | ||
document_page = MagicMock() | ||
access_token = "test_token" | ||
|
||
with patch.object( | ||
CustomerPortal, "_get_page_view_values", return_value={"key": "value"} | ||
): | ||
result = self.customer_portal._document_page_get_page_view_values( | ||
document_page, access_token | ||
) | ||
self.assertEqual(result["key"], "value") | ||
self.assertEqual(result["page_name"], "document_page") | ||
self.assertEqual(result["document_page"], document_page) | ||
|
||
@patch("odoo.http.request") | ||
def test_portal_my_knowledge_document_pages(self, mock_request): | ||
mock_request.env = MagicMock() | ||
mock_request.render = MagicMock() | ||
|
||
# Mock necessary methods and properties | ||
self.customer_portal._prepare_portal_layout_values = MagicMock(return_value={}) | ||
self.customer_portal._get_archive_groups = MagicMock(return_value=[]) | ||
mock_request.env["document.page"].search_count = MagicMock(return_value=10) | ||
mock_request.env["document.page"].search = MagicMock(return_value=[]) | ||
|
||
self.customer_portal.portal_my_knowledge_document_pages() | ||
mock_request.render.assert_called_once() | ||
|
||
@patch("odoo.http.request") | ||
def test_document_pages_followup(self, mock_request): | ||
mock_request.render = MagicMock() | ||
self.customer_portal._document_check_access = MagicMock() | ||
self.customer_portal._document_page_get_page_view_values = MagicMock( | ||
return_value={} | ||
) | ||
|
||
mock_request.render.assert_called_once() |