From c07ce2ad9ee29210cb91a9eb9e97a378b43a0bc3 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Wed, 15 Apr 2015 13:11:27 -0400 Subject: [PATCH 1/2] Simplify test_only_expected_fields_are_displayed Use sets to accomplish the same result. --- .../tests/studio/test_studio_settings.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/common/test/acceptance/tests/studio/test_studio_settings.py b/common/test/acceptance/tests/studio/test_studio_settings.py index aefd5ba1a6..6df42e9eaa 100644 --- a/common/test/acceptance/tests/studio/test_studio_settings.py +++ b/common/test/acceptance/tests/studio/test_studio_settings.py @@ -397,10 +397,17 @@ class AdvancedSettingsValidationTest(StudioCourseTest): When I view the Advanced Settings screen for the course The total number of fields displayed matches the number I expect And the actual fields displayed match the fields I expect to see + + Note that this test will NOT fail if fields that we expect to see are + not displayed, only if fields show up that we did not expect to see. """ expected_fields = self.advanced_settings.expected_settings_names displayed_fields = self.advanced_settings.displayed_settings_names - self.assertEqual(len(expected_fields), len(displayed_fields)) - for field in displayed_fields: - if field not in expected_fields: - self.fail("Field '{}' not expected for Advanced Settings display.".format(field)) + unexpectedly_displayed = set(displayed_fields) - set(expected_fields) + self.assertEquals( + len(unexpectedly_displayed), + 0, + "The following fields were unexpectedly displayed: {fields}".format( + fields=", ".join(unexpectedly_displayed) + ) + ) From 294e24dd8fc4ed7c088ec94be1156a582204ecc6 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Thu, 16 Apr 2015 10:07:40 -0400 Subject: [PATCH 2/2] Strict comparison between expected_fields and displayed_fields --- .../acceptance/tests/studio/test_studio_settings.py | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/common/test/acceptance/tests/studio/test_studio_settings.py b/common/test/acceptance/tests/studio/test_studio_settings.py index 6df42e9eaa..285da25338 100644 --- a/common/test/acceptance/tests/studio/test_studio_settings.py +++ b/common/test/acceptance/tests/studio/test_studio_settings.py @@ -397,17 +397,7 @@ class AdvancedSettingsValidationTest(StudioCourseTest): When I view the Advanced Settings screen for the course The total number of fields displayed matches the number I expect And the actual fields displayed match the fields I expect to see - - Note that this test will NOT fail if fields that we expect to see are - not displayed, only if fields show up that we did not expect to see. """ expected_fields = self.advanced_settings.expected_settings_names displayed_fields = self.advanced_settings.displayed_settings_names - unexpectedly_displayed = set(displayed_fields) - set(expected_fields) - self.assertEquals( - len(unexpectedly_displayed), - 0, - "The following fields were unexpectedly displayed: {fields}".format( - fields=", ".join(unexpectedly_displayed) - ) - ) + self.assertEquals(set(displayed_fields), set(expected_fields))