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