|
| 1 | +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
| 2 | +from odoo.tests import common |
| 3 | + |
| 4 | +class TestDocumentPageFollowers(common.TransactionCase): |
| 5 | + |
| 6 | + def setUp(self): |
| 7 | + super().setUp() |
| 8 | + |
| 9 | + self.user_1 = self.env["res.users"].create({ |
| 10 | + "name": "Test User 1", |
| 11 | + "login": "test_user_1", |
| 12 | + "email": "user1@test.com", |
| 13 | + }) |
| 14 | + |
| 15 | + self.user_2 = self.env["res.users"].create({ |
| 16 | + "name": "Test User 2", |
| 17 | + "login": "test_user_2", |
| 18 | + "email": "user2@test.com", |
| 19 | + }) |
| 20 | + |
| 21 | + self.category = self.env["document.page"].create({ |
| 22 | + "name": "Test Category", |
| 23 | + "type": "category", |
| 24 | + }) |
| 25 | + |
| 26 | + self.content_page = self.env["document.page"].create({ |
| 27 | + "name": "Test Content Page", |
| 28 | + "type": "content", |
| 29 | + "parent_id": self.category.id, |
| 30 | + }) |
| 31 | + |
| 32 | + def test_auto_subscribe_new_page(self): |
| 33 | + """When creating a page in a category with followers, they are subscribed""" |
| 34 | + |
| 35 | + self.category.message_subscribe(partner_ids=[ |
| 36 | + self.user_1.partner_id.id, |
| 37 | + self.user_2.partner_id.id |
| 38 | + ]) |
| 39 | + |
| 40 | + new_page = self.env["document.page"].create({ |
| 41 | + "name": "New Auto-Subscribed Page", |
| 42 | + "type": "content", |
| 43 | + "parent_id": self.category.id, |
| 44 | + }) |
| 45 | + |
| 46 | + followers = new_page.message_partner_ids.ids |
| 47 | + |
| 48 | + self.assertIn(self.user_1.partner_id.id, followers) |
| 49 | + self.assertIn(self.user_2.partner_id.id, followers) |
| 50 | + |
| 51 | + def test_follow_category_subscribes_documents(self): |
| 52 | + """Follow a category should subscribe to its existing pages""" |
| 53 | + self.category.message_subscribe([self.user_1.partner_id.id]) |
| 54 | + |
| 55 | + self.assertIn( |
| 56 | + self.user_1.partner_id.id, |
| 57 | + self.content_page.parent_id.message_partner_ids.ids |
| 58 | + ) |
| 59 | + |
| 60 | + def test_unfollow_category_unsubscribes_documents(self): |
| 61 | + """Unfollowing a category should unsubscribe from its existing pages""" |
| 62 | + self.category.message_subscribe([self.user_1.partner_id.id]) |
| 63 | + self.category.message_unsubscribe([self.user_1.partner_id.id]) |
| 64 | + |
| 65 | + self.assertNotIn( |
| 66 | + self.user_1.partner_id.id, |
| 67 | + self.content_page.parent_id.message_partner_ids.ids |
| 68 | + ) |
| 69 | + |
| 70 | + def test_no_auto_subscribe_without_category(self): |
| 71 | + """Pages without a category should not have automatic subscriptions""" |
| 72 | + new_page = self.env["document.page"].create({ |
| 73 | + "name": "Orphan Page", |
| 74 | + "type": "content" |
| 75 | + }) |
| 76 | + |
| 77 | + self.assertFalse(new_page.message_partner_ids) |
0 commit comments