|
1 | 1 | import pytest |
2 | 2 | from h_matchers import Any |
3 | 3 |
|
| 4 | +from h.models import ModerationStatus |
4 | 5 | from h.presenters.annotation_searchindex import AnnotationSearchIndexPresenter |
5 | 6 | from h.util.datetime import utc_iso8601 |
6 | 7 |
|
@@ -43,33 +44,32 @@ def test_asdict(self, DocumentSearchIndexPresenter, pyramid_request, factories): |
43 | 44 | "hidden": False, |
44 | 45 | } |
45 | 46 |
|
46 | | - @pytest.mark.parametrize("is_moderated", [True, False]) |
47 | | - @pytest.mark.parametrize("replies_moderated", [True, False]) |
| 47 | + @pytest.mark.parametrize( |
| 48 | + "moderation_status,should_be_hidden", |
| 49 | + [ |
| 50 | + (None, False), |
| 51 | + (ModerationStatus.APPROVED, False), |
| 52 | + (ModerationStatus.PENDING, True), |
| 53 | + (ModerationStatus.DENIED, True), |
| 54 | + (ModerationStatus.SPAM, True), |
| 55 | + ], |
| 56 | + ) |
48 | 57 | def test_it_marks_annotation_hidden_correctly( |
49 | 58 | self, |
50 | 59 | pyramid_request, |
51 | | - moderation_service, |
52 | | - is_moderated, |
53 | | - replies_moderated, |
| 60 | + moderation_status, |
| 61 | + should_be_hidden, |
54 | 62 | factories, |
55 | 63 | ): |
56 | 64 | annotation = factories.Annotation() |
57 | | - replies = factories.Annotation.create_batch(2, references=[annotation.id]) |
58 | | - |
59 | | - # Configure moderation return value |
60 | | - moderated_ids = [] |
61 | | - if is_moderated: |
62 | | - moderated_ids.append(annotation.id) |
63 | | - if replies_moderated: |
64 | | - moderated_ids.extend([reply.id for reply in replies]) |
65 | | - moderation_service.all_hidden.return_value = moderated_ids |
| 65 | + annotation.moderation_status = moderation_status |
66 | 66 |
|
67 | 67 | annotation_dict = AnnotationSearchIndexPresenter( |
68 | 68 | annotation, pyramid_request |
69 | 69 | ).asdict() |
70 | 70 |
|
71 | 71 | # We are hidden if both we, and all of our replies are moderated |
72 | | - assert annotation_dict["hidden"] == bool(is_moderated and replies_moderated) |
| 72 | + assert annotation_dict["hidden"] == should_be_hidden |
73 | 73 |
|
74 | 74 | @pytest.mark.parametrize("is_nipsaed", [True, False]) |
75 | 75 | def test_it_marks_annotation_nipsad_correctly( |
|
0 commit comments