|
13 | 13 | ) |
14 | 14 | from notifier.formatter import convert_syntax |
15 | 15 | from notifier.types import CachedUserConfig, PostInfo |
| 16 | +from notifier.digest import make_categories_digest |
| 17 | + |
16 | 18 |
|
17 | 19 | fake_user_config: CachedUserConfig = { # TODO Subscriptions |
18 | 20 | "user_id": "1000", |
@@ -179,6 +181,97 @@ def test_full_interpolation_en() -> None: |
179 | 181 | assert "{" not in digest |
180 | 182 |
|
181 | 183 |
|
| 184 | +def test_categories_digest_duplication_bug() -> None: |
| 185 | + """Test that categories only show their own posts, not all posts.""" |
| 186 | + |
| 187 | + digester = Digester(str(Path.cwd() / "config" / "lang.toml")) |
| 188 | + lexicon = digester.make_lexicon("en") |
| 189 | + |
| 190 | + # Create posts in two different categories |
| 191 | + posts_category_1: List[PostInfo] = [ |
| 192 | + { |
| 193 | + "id": "post-1", |
| 194 | + "posted_timestamp": 100, |
| 195 | + "title": "Post in Category 1", |
| 196 | + "snippet": "Content for category 1", |
| 197 | + "username": "User1", |
| 198 | + "wiki_id": "test-wiki", |
| 199 | + "wiki_name": "Test Wiki", |
| 200 | + "wiki_secure": 1, |
| 201 | + "category_id": "cat-1", |
| 202 | + "category_name": "Category 1", |
| 203 | + "thread_id": "thread-1", |
| 204 | + "thread_timestamp": 100, |
| 205 | + "thread_title": "Thread 1", |
| 206 | + "thread_creator": "User1", |
| 207 | + "parent_post_id": None, |
| 208 | + "parent_posted_timestamp": None, |
| 209 | + "parent_title": None, |
| 210 | + "parent_username": None, |
| 211 | + "flag_user_subscribed_to_thread": True, |
| 212 | + "flag_user_subscribed_to_post": False, |
| 213 | + "flag_user_started_thread": False, |
| 214 | + "flag_user_posted_parent": False, |
| 215 | + } |
| 216 | + ] |
| 217 | + |
| 218 | + posts_category_2: List[PostInfo] = [ |
| 219 | + { |
| 220 | + "id": "post-2", |
| 221 | + "posted_timestamp": 200, |
| 222 | + "title": "Post in Category 2", |
| 223 | + "snippet": "Content for category 2", |
| 224 | + "username": "User2", |
| 225 | + "wiki_id": "test-wiki", |
| 226 | + "wiki_name": "Test Wiki", |
| 227 | + "wiki_secure": 1, |
| 228 | + "category_id": "cat-2", |
| 229 | + "category_name": "Category 2", |
| 230 | + "thread_id": "thread-2", |
| 231 | + "thread_timestamp": 200, |
| 232 | + "thread_title": "Thread 2", |
| 233 | + "thread_creator": "User2", |
| 234 | + "parent_post_id": None, |
| 235 | + "parent_posted_timestamp": None, |
| 236 | + "parent_title": None, |
| 237 | + "parent_username": None, |
| 238 | + "flag_user_subscribed_to_thread": True, |
| 239 | + "flag_user_subscribed_to_post": False, |
| 240 | + "flag_user_started_thread": False, |
| 241 | + "flag_user_posted_parent": False, |
| 242 | + } |
| 243 | + ] |
| 244 | + |
| 245 | + all_posts = posts_category_1 + posts_category_2 |
| 246 | + categories_digest = make_categories_digest(all_posts, lexicon) |
| 247 | + assert len(categories_digest) == 2 |
| 248 | + category_1_digest = ( |
| 249 | + categories_digest[0] |
| 250 | + if "Category 1" in categories_digest[0] |
| 251 | + else categories_digest[1] |
| 252 | + ) |
| 253 | + category_2_digest = ( |
| 254 | + categories_digest[1] |
| 255 | + if "Category 2" in categories_digest[1] |
| 256 | + else categories_digest[0] |
| 257 | + ) |
| 258 | + |
| 259 | + assert "Content for category 1" in category_1_digest |
| 260 | + assert "Content for category 2" not in category_1_digest |
| 261 | + |
| 262 | + assert "Content for category 2" in category_2_digest |
| 263 | + assert "Content for category 1" not in category_2_digest |
| 264 | + |
| 265 | + assert ( |
| 266 | + "1 plural(1|notification|notifications) in 1 plural(1|thread|threads)" |
| 267 | + in category_1_digest |
| 268 | + ) |
| 269 | + assert ( |
| 270 | + "1 plural(1|notification|notifications) in 1 plural(1|thread|threads)" |
| 271 | + in category_2_digest |
| 272 | + ) |
| 273 | + |
| 274 | + |
182 | 275 | def test_full_interpolation_all_languages() -> None: |
183 | 276 | """Verify that there's no leftover interpolation in any language's digest.""" |
184 | 277 |
|
|
0 commit comments