Skip to content

Commit d897600

Browse files
committed
refactored tests
1 parent 92df337 commit d897600

File tree

1 file changed

+33
-23
lines changed

1 file changed

+33
-23
lines changed

evap/results/tests/test_views.py

+33-23
Original file line numberDiff line numberDiff line change
@@ -752,16 +752,16 @@ def test_private_evaluation(self):
752752
class TestResultsTextanswerVisibility(WebTest):
753753

754754
fixtures = ["minimal_test_data_results"]
755-
general_textanswers = [
755+
general_textanswers = {
756756
".general_orig_published.",
757757
".general_orig_deleted.",
758758
".general_changed_published.",
759759
".general_orig_published_changed.",
760760
".general_additional_orig_published.",
761761
".general_additional_orig_deleted.",
762-
]
762+
}
763763

764-
contributor_textanswers = [
764+
contributor_textanswers = {
765765
".contributor_orig_published.",
766766
".contributor_orig_private.",
767767
".responsible_contributor_orig_published.",
@@ -772,13 +772,27 @@ class TestResultsTextanswerVisibility(WebTest):
772772
".responsible_contributor_orig_unreviewed.",
773773
".responsible_contributor_additional_orig_published.",
774774
".responsible_contributor_additional_orig_deleted.",
775-
]
775+
}
776776

777-
standard_general_textanswers = [ # subset of general_textanswers
777+
standard_general_textanswers = {
778778
".general_orig_published.",
779779
".general_changed_published.",
780780
".general_additional_orig_published.",
781-
]
781+
}
782+
783+
# subset of textanswers. These are never shown in results page
784+
general_textanswers_never_shown = {
785+
".general_orig_deleted.",
786+
".general_orig_published_changed.",
787+
".general_additional_orig_deleted.",
788+
}
789+
contributor_textanswers_never_shown = {
790+
".responsible_contributor_orig_deleted.",
791+
".responsible_contributor_orig_published_changed.",
792+
".responsible_contributor_orig_unreviewed.",
793+
".responsible_contributor_additional_orig_deleted.",
794+
}
795+
all_textanswers = general_textanswers | contributor_textanswers
782796

783797
@classmethod
784798
def setUpTestData(cls):
@@ -791,9 +805,8 @@ def check_with_view(
791805
expected_visible_textanswers,
792806
general=ViewGeneralResults,
793807
contributor=ViewContributorResults,
794-
all_textanswers=general_textanswers + contributor_textanswers,
795808
):
796-
textanswers_not_in = list(set(all_textanswers) - set(expected_visible_textanswers))
809+
expected_not_visible_textanswers = self.all_textanswers - set(expected_visible_textanswers)
797810
for general_view, contributor_view in product(general, contributor):
798811
page = self.app.get(
799812
f"/results/semester/1/evaluation/1?view_general_results={general_view.value}&view_contributor_results={contributor_view.value}",
@@ -802,24 +815,21 @@ def check_with_view(
802815

803816
for answer in expected_visible_textanswers:
804817
self.assertIn(answer, page)
805-
for answer in textanswers_not_in:
818+
for answer in (
819+
expected_not_visible_textanswers
820+
| self.general_textanswers_never_shown
821+
| self.contributor_textanswers_never_shown
822+
):
806823
self.assertNotIn(answer, page)
807824

808825
def test_manager(self):
809826
user = self.manager
810827
self.check_with_view(user, [])
811-
with run_in_staff_mode(self): # in staff mode, the manager can see everything except deleted or changed
812-
visible_contributor_textanswers = [
813-
".contributor_orig_published.",
814-
".contributor_orig_private.",
815-
".responsible_contributor_orig_published.",
816-
".responsible_contributor_changed_published.",
817-
".responsible_contributor_orig_private.",
818-
".responsible_contributor_additional_orig_published.",
819-
]
828+
with run_in_staff_mode(self): # in staff mode, the manager can see every possible answer
829+
visible_contributor_textanswers = self.contributor_textanswers - self.contributor_textanswers_never_shown
820830
self.check_with_view(
821831
user,
822-
self.standard_general_textanswers + visible_contributor_textanswers,
832+
self.standard_general_textanswers | visible_contributor_textanswers,
823833
[ViewGeneralResults.FULL],
824834
[ViewContributorResults.FULL],
825835
)
@@ -841,16 +851,16 @@ def test_responsible(self):
841851

842852
def test_responsible_contributor(self):
843853
844-
visible_contributor_textanswers = [
854+
visible_contributor_textanswers = {
845855
".responsible_contributor_orig_published.",
846856
".responsible_contributor_changed_published.",
847857
".responsible_contributor_orig_private.",
848858
".responsible_contributor_additional_orig_published.",
849-
]
859+
}
850860
self.check_with_view(user, [], [ViewGeneralResults.RATINGS], [ViewContributorResults.RATINGS])
851861
self.check_with_view(
852862
user,
853-
self.standard_general_textanswers + visible_contributor_textanswers,
863+
self.standard_general_textanswers | visible_contributor_textanswers,
854864
[ViewGeneralResults.FULL],
855865
[ViewContributorResults.FULL, ViewContributorResults.PERSONAL],
856866
)
@@ -862,7 +872,7 @@ def test_contributor_general_textanswers(self):
862872

863873
def test_contributor(self):
864874
865-
visible_contributor_textanswers = [".contributor_orig_published.", ".contributor_orig_private."]
875+
visible_contributor_textanswers = {".contributor_orig_published.", ".contributor_orig_private."}
866876
self.check_with_view(user, [], contributor=[ViewContributorResults.RATINGS])
867877
self.check_with_view(
868878
user,

0 commit comments

Comments
 (0)