mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-14 01:41:26 -06:00
91 lines
3.3 KiB
Python
91 lines
3.3 KiB
Python
from odoo.tests import tagged
|
|
from odoo.tests.common import TransactionCase
|
|
|
|
|
|
@tagged("post_install", "-at_install")
|
|
class TestDocumentPrintControl(TransactionCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
super().setUpClass()
|
|
|
|
cls.printable_tag = cls.env["document.page.tag"].create(
|
|
{
|
|
"name": "Printable Tag",
|
|
"is_printable": True,
|
|
}
|
|
)
|
|
|
|
cls.non_printable_tag = cls.env["document.page.tag"].create(
|
|
{
|
|
"name": "Non-Printable Tag",
|
|
"is_printable": False,
|
|
}
|
|
)
|
|
|
|
cls.doc_without_tags = cls.env["document.page"].create(
|
|
{
|
|
"name": "Document without tags",
|
|
"content": "Test content without tags",
|
|
}
|
|
)
|
|
|
|
cls.doc_with_printable_tag = cls.env["document.page"].create(
|
|
{
|
|
"name": "Document with printable tag",
|
|
"content": "Test content with printable tag",
|
|
"tag_ids": [(4, cls.printable_tag.id)],
|
|
}
|
|
)
|
|
|
|
cls.doc_with_non_printable_tag = cls.env["document.page"].create(
|
|
{
|
|
"name": "Document with non-printable tag",
|
|
"content": "Test content with non-printable tag",
|
|
"tag_ids": [(4, cls.non_printable_tag.id)],
|
|
}
|
|
)
|
|
|
|
cls.doc_with_mixed_tags = cls.env["document.page"].create(
|
|
{
|
|
"name": "Document with mixed tags",
|
|
"content": "Test content with mixed tags",
|
|
"tag_ids": [(4, cls.printable_tag.id), (4, cls.non_printable_tag.id)],
|
|
}
|
|
)
|
|
|
|
def test_printable_without_tags(self):
|
|
"""Documents without tags should be printable by default"""
|
|
self.assertTrue(self.doc_without_tags.is_printable)
|
|
|
|
def test_printable_with_allowed_tags(self):
|
|
"""Documents with only printable tags should be printable"""
|
|
self.assertTrue(self.doc_with_printable_tag.is_printable)
|
|
|
|
def test_not_printable_with_restricted_tags(self):
|
|
"""Documents with non-printable tags should not be printable"""
|
|
self.assertFalse(self.doc_with_non_printable_tag.is_printable)
|
|
|
|
def test_not_printable_with_mixed_tags(self):
|
|
"""Documents with mixed tags should not be printable"""
|
|
self.assertFalse(self.doc_with_mixed_tags.is_printable)
|
|
|
|
def test_print_action_allowed_documents(self):
|
|
"""Print action should return report for printable documents"""
|
|
result = self.doc_with_printable_tag.action_print_document_page()
|
|
self.assertIsNotNone(result)
|
|
self.assertIn("context", result)
|
|
self.assertIn("report_action", result["context"])
|
|
self.assertIn("report_name", result["context"]["report_action"])
|
|
|
|
def test_print_action_restricted_documents(self):
|
|
"""Print action should return None for non-printable documents"""
|
|
result = self.doc_with_non_printable_tag.action_print_document_page()
|
|
self.assertIsNone(result)
|
|
|
|
def test_tag_default_is_printable(self):
|
|
"""Tags created without is_printable should default to True"""
|
|
tag = self.env["document.page.tag"].create(
|
|
{"name": "Test Tag Without is_printable"}
|
|
)
|
|
self.assertTrue(tag.is_printable)
|