From 8a95a8e520cfcd64ec404e794d5e95c042c5c51b Mon Sep 17 00:00:00 2001 From: Ayub khan Date: Wed, 21 Aug 2019 16:26:12 +0500 Subject: [PATCH] BOM-95 assertItemsEqual with six.assertCountEqual --- .../tests/test_migrate_transcripts.py | 4 +-- .../commands/tests/test_reindex_courses.py | 3 ++- .../commands/tests/test_reindex_library.py | 2 +- .../views/tests/test_course_index.py | 2 +- .../course_modes/tests/test_models.py | 5 ++-- .../terrain/stubs/tests/test_edxnotes.py | 3 ++- .../third_party_auth/api/tests/test_views.py | 6 ++--- .../xblock_django/tests/test_api.py | 15 ++++++----- .../tests/test_mixed_modulestore.py | 2 +- .../test_split_modulestore_bulk_operations.py | 17 ++++++++----- common/lib/xmodule/xmodule/tests/__init__.py | 3 ++- .../xmodule/xmodule/tests/test_capa_module.py | 4 +-- .../lib/xmodule/xmodule/tests/test_export.py | 4 ++- .../tests/lms/test_lms_courseware.py | 3 ++- .../tests/studio/test_studio_container.py | 5 ++-- .../tests/studio/test_studio_outline.py | 3 ++- lms/djangoapps/badges/tests/test_models.py | 2 +- lms/djangoapps/bulk_email/tests/test_email.py | 23 +++++++++++------ lms/djangoapps/ccx/api/v0/tests/test_views.py | 12 ++++----- lms/djangoapps/certificates/tests/test_api.py | 6 +++-- .../commands/tests/test_dump_course.py | 3 ++- .../tests/test_submitting_problems.py | 4 +-- .../courseware/tests/test_video_handlers.py | 2 +- .../courseware/tests/test_video_mongo.py | 2 +- .../django_comment_client/tests/test_utils.py | 10 +++++--- lms/djangoapps/edxnotes/tests.py | 25 +++++++++++++------ .../instructor_task/tests/test_base.py | 5 ++-- .../shoppingcart/tests/test_models.py | 4 +-- .../djangoapps/catalog/tests/test_utils.py | 2 +- .../commands/tests/test_dump_to_neo4j.py | 5 ++-- .../enrollments/tests/test_views.py | 5 ++-- .../lang_pref/tests/test_middleware.py | 3 ++- .../djangoapps/programs/tests/test_utils.py | 3 ++- .../tests/test_send_upgrade_reminder.py | 4 ++- .../site_configuration/tests/test_helpers.py | 16 ++++++++---- .../djangoapps/theming/tests/test_commands.py | 11 +++++--- .../djangoapps/theming/tests/test_helpers.py | 5 ++-- .../accounts/tests/test_retirement_views.py | 5 ++-- .../user_api/accounts/tests/test_views.py | 3 ++- .../djangoapps/user_api/tests/test_views.py | 7 +++--- openedx/core/lib/api/test_utils.py | 3 ++- .../tests/test_course_expiration.py | 10 ++++---- pavelib/paver_tests/test_assets.py | 9 ++++--- 43 files changed, 167 insertions(+), 103 deletions(-) diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_migrate_transcripts.py b/cms/djangoapps/contentstore/management/commands/tests/test_migrate_transcripts.py index fb701fd815..d2b3c77d4a 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_migrate_transcripts.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_migrate_transcripts.py @@ -187,7 +187,7 @@ class TestMigrateTranscripts(ModuleStoreTestCase): Test migrating transcripts """ translations = self.video_descriptor.available_translations(self.video_descriptor.get_transcripts_info()) - self.assertItemsEqual(translations, ['hr', 'ge']) + six.assertCountEqual(self, translations, ['hr', 'ge']) self.assertFalse(api.is_transcript_available(self.video_descriptor.edx_video_id, 'hr')) self.assertFalse(api.is_transcript_available(self.video_descriptor.edx_video_id, 'ge')) @@ -202,7 +202,7 @@ class TestMigrateTranscripts(ModuleStoreTestCase): Test migrating transcripts multiple times """ translations = self.video_descriptor.available_translations(self.video_descriptor.get_transcripts_info()) - self.assertItemsEqual(translations, ['hr', 'ge']) + six.assertCountEqual(self, translations, ['hr', 'ge']) self.assertFalse(api.is_transcript_available(self.video_descriptor.edx_video_id, 'hr')) self.assertFalse(api.is_transcript_available(self.video_descriptor.edx_video_id, 'ge')) diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_reindex_courses.py b/cms/djangoapps/contentstore/management/commands/tests/test_reindex_courses.py index 35d8725116..339bc5f769 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_reindex_courses.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_reindex_courses.py @@ -4,6 +4,7 @@ from __future__ import absolute_import import ddt import mock from django.core.management import CommandError, call_command +import six from six import text_type from contentstore.courseware_index import SearchIndexingError @@ -104,7 +105,7 @@ class TestReindexCourse(ModuleStoreTestCase): patched_yes_no.assert_called_once_with(ReindexCommand.CONFIRMATION_PROMPT, default='no') expected_calls = self._build_calls(self.first_course, self.second_course) - self.assertItemsEqual(patched_index.mock_calls, expected_calls) + six.assertCountEqual(self, patched_index.mock_calls, expected_calls) def test_given_all_key_prompts_and_reindexes_all_courses_cancelled(self): """ Test that does not reindex anything when --all key is given and cancelled """ diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_reindex_library.py b/cms/djangoapps/contentstore/management/commands/tests/test_reindex_library.py index 5104cf0185..88ce8753d9 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_reindex_library.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_reindex_library.py @@ -104,7 +104,7 @@ class TestReindexLibrary(ModuleStoreTestCase): patched_yes_no.assert_called_once_with(ReindexCommand.CONFIRMATION_PROMPT, default='no') expected_calls = self._build_calls(self.first_lib, self.second_lib) - self.assertItemsEqual(patched_index.mock_calls, expected_calls) + six.assertCountEqual(self, patched_index.mock_calls, expected_calls) def test_given_all_key_prompts_and_reindexes_all_libraries_cancelled(self): """ Test that does not reindex anything when --all key is given and cancelled """ diff --git a/cms/djangoapps/contentstore/views/tests/test_course_index.py b/cms/djangoapps/contentstore/views/tests/test_course_index.py index b22fc2d0fa..e9af42c822 100644 --- a/cms/djangoapps/contentstore/views/tests/test_course_index.py +++ b/cms/djangoapps/contentstore/views/tests/test_course_index.py @@ -554,7 +554,7 @@ class TestCourseOutline(CourseTestCase): [component for component in advanced_modules if component in deprecated_block_types] ) - self.assertItemsEqual(info['blocks'], expected_blocks) + six.assertCountEqual(self, info['blocks'], expected_blocks) self.assertEqual( info['advance_settings_url'], reverse_course_url('advanced_settings_handler', course_id) diff --git a/common/djangoapps/course_modes/tests/test_models.py b/common/djangoapps/course_modes/tests/test_models.py index 7dbc967b33..9a2df874c7 100644 --- a/common/djangoapps/course_modes/tests/test_models.py +++ b/common/djangoapps/course_modes/tests/test_models.py @@ -15,6 +15,7 @@ from django.test import TestCase, override_settings from django.utils.timezone import now from mock import patch from opaque_keys.edx.locator import CourseLocator +import six from six.moves import zip from course_modes.helpers import enrollment_mode_display @@ -399,11 +400,11 @@ class CourseModeModelTest(TestCase): # Check the selectable modes, which should exclude credit selectable_modes = CourseMode.modes_for_course_dict(self.course_key) - self.assertItemsEqual(list(selectable_modes.keys()), expected_selectable_modes) + six.assertCountEqual(self, list(selectable_modes.keys()), expected_selectable_modes) # When we get all unexpired modes, we should see credit as well all_modes = CourseMode.modes_for_course_dict(self.course_key, only_selectable=False) - self.assertItemsEqual(list(all_modes.keys()), available_modes) + six.assertCountEqual(self, list(all_modes.keys()), available_modes) def _enrollment_display_modes_dicts(self, dict_type): """ diff --git a/common/djangoapps/terrain/stubs/tests/test_edxnotes.py b/common/djangoapps/terrain/stubs/tests/test_edxnotes.py index 32e1e66d22..de9f744bd7 100644 --- a/common/djangoapps/terrain/stubs/tests/test_edxnotes.py +++ b/common/djangoapps/terrain/stubs/tests/test_edxnotes.py @@ -9,6 +9,7 @@ from uuid import uuid4 import ddt import requests +import six import six.moves.urllib.parse # pylint: disable=import-error from six.moves import range @@ -192,7 +193,7 @@ class StubEdxNotesServiceTest(unittest.TestCase): updated_note = self._get_notes()[0] self.assertEqual("new test text", updated_note["text"]) self.assertEqual(note["id"], updated_note["id"]) - self.assertItemsEqual(note, updated_note) + six.assertCountEqual(self, note, updated_note) response = requests.get(self._get_url("api/v1/annotations/does_not_exist")) self.assertEqual(response.status_code, 404) diff --git a/common/djangoapps/third_party_auth/api/tests/test_views.py b/common/djangoapps/third_party_auth/api/tests/test_views.py index 95786a50dc..3ce1433544 100644 --- a/common/djangoapps/third_party_auth/api/tests/test_views.py +++ b/common/djangoapps/third_party_auth/api/tests/test_views.py @@ -133,7 +133,7 @@ class UserViewsMixin(object): self.assertEqual(response.status_code, expect_result) if expect_result == 200: self.assertIn("active", response.data) - self.assertItemsEqual(response.data["active"], self.expected_active(target_user)) + six.assertCountEqual(self, response.data["active"], self.expected_active(target_user)) @ddt.data( # A server with a valid API key can query any user's list of providers @@ -149,7 +149,7 @@ class UserViewsMixin(object): self.assertEqual(response.status_code, expect_result) if expect_result == 200: self.assertIn("active", response.data) - self.assertItemsEqual(response.data["active"], self.expected_active(target_user)) + six.assertCountEqual(self, response.data["active"], self.expected_active(target_user)) @ddt.data( (True, ALICE_USERNAME, 200, True), @@ -352,7 +352,7 @@ class UserMappingViewAPITests(TpaAPITestCase): if expect_code == 200: for item in ['results', 'count', 'num_pages']: self.assertIn(item, response.data) - self.assertItemsEqual(response.data['results'], expect_result) + six.assertCountEqual(self, response.data['results'], expect_result) @unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms') diff --git a/common/djangoapps/xblock_django/tests/test_api.py b/common/djangoapps/xblock_django/tests/test_api.py index a98617f806..5a0500782b 100644 --- a/common/djangoapps/xblock_django/tests/test_api.py +++ b/common/djangoapps/xblock_django/tests/test_api.py @@ -3,6 +3,8 @@ Tests related to XBlock support API. """ from __future__ import absolute_import +import six + from openedx.core.djangolib.testing.utils import CacheIsolationTestCase from xblock_django.api import authorable_xblocks, deprecated_xblocks, disabled_xblocks from xblock_django.models import XBlockConfiguration, XBlockStudioConfiguration, XBlockStudioConfigurationFlag @@ -45,23 +47,23 @@ class XBlockSupportTestCase(CacheIsolationTestCase): """ Tests the deprecated_xblocks method """ deprecated_xblock_names = [block.name for block in deprecated_xblocks()] - self.assertItemsEqual(["poll", "survey"], deprecated_xblock_names) + six.assertCountEqual(self, ["poll", "survey"], deprecated_xblock_names) XBlockConfiguration(name="poll", enabled=True, deprecated=False).save() deprecated_xblock_names = [block.name for block in deprecated_xblocks()] - self.assertItemsEqual(["survey"], deprecated_xblock_names) + six.assertCountEqual(self, ["survey"], deprecated_xblock_names) def test_disabled_blocks(self): """ Tests the disabled_xblocks method """ disabled_xblock_names = [block.name for block in disabled_xblocks()] - self.assertItemsEqual(["survey"], disabled_xblock_names) + six.assertCountEqual(self, ["survey"], disabled_xblock_names) XBlockConfiguration(name="poll", enabled=False, deprecated=True).save() disabled_xblock_names = [block.name for block in disabled_xblocks()] - self.assertItemsEqual(["survey", "poll"], disabled_xblock_names) + six.assertCountEqual(self, ["survey", "poll"], disabled_xblock_names) def test_authorable_blocks_empty_model(self): """ @@ -79,7 +81,7 @@ class XBlockSupportTestCase(CacheIsolationTestCase): Tests authorable_xblocks when name is not specified. """ authorable_xblock_names = [block.name for block in authorable_xblocks()] - self.assertItemsEqual(["done", "problem", "problem", "html"], authorable_xblock_names) + six.assertCountEqual(self, ["done", "problem", "problem", "html"], authorable_xblock_names) # Note that "survey" is disabled in XBlockConfiguration, but it is still returned by # authorable_xblocks because it is marked as enabled and unsupported in XBlockStudioConfiguration. @@ -87,7 +89,8 @@ class XBlockSupportTestCase(CacheIsolationTestCase): # is a whitelist and uses a combination of xblock type and template (and in addition has a global feature flag), # it is expected that Studio code will need to filter by both disabled_xblocks and authorable_xblocks. authorable_xblock_names = [block.name for block in authorable_xblocks(allow_unsupported=True)] - self.assertItemsEqual( + six.assertCountEqual( + self, ["survey", "done", "problem", "problem", "problem", "html", "split_module"], authorable_xblock_names ) diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py b/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py index 4029ed57a7..27b0b5e809 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py @@ -1836,7 +1836,7 @@ class TestMixedModuleStore(CommonMixedModuleStoreSetup): with check_mongo_calls(max_find, max_send): found_orphans = self.store.get_orphans(self.course_locations[self.MONGO_COURSEID].course_key) - self.assertItemsEqual(found_orphans, orphan_locations) + six.assertCountEqual(self, found_orphans, orphan_locations) @ddt.data(ModuleStoreEnum.Type.mongo) def test_get_non_orphan_parents(self, default_ms): diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_split_modulestore_bulk_operations.py b/common/lib/xmodule/xmodule/modulestore/tests/test_split_modulestore_bulk_operations.py index c95b9fa7c9..872033d390 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_split_modulestore_bulk_operations.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_split_modulestore_bulk_operations.py @@ -7,6 +7,7 @@ from __future__ import absolute_import import copy import unittest +import six import ddt from bson.objectid import ObjectId from mock import MagicMock, Mock, call @@ -169,7 +170,8 @@ class TestBulkWriteMixinClosed(TestBulkWriteMixin): self.bulk.update_structure(self.course_key.replace(branch='b'), other_structure) self.assertConnCalls() self.bulk._end_bulk_operation(self.course_key) - self.assertItemsEqual( + six.assertCountEqual( + self, [ call.insert_structure(self.structure, self.course_key), call.insert_structure(other_structure, self.course_key) @@ -205,7 +207,8 @@ class TestBulkWriteMixinClosed(TestBulkWriteMixin): self.bulk.update_definition(self.course_key.replace(branch='b'), other_definition) self.bulk.insert_course_index(self.course_key, {'versions': {'a': self.definition['_id'], 'b': other_definition['_id']}}) self.bulk._end_bulk_operation(self.course_key) - self.assertItemsEqual( + six.assertCountEqual( + self, [ call.insert_definition(self.definition, self.course_key), call.insert_definition(other_definition, self.course_key), @@ -236,7 +239,8 @@ class TestBulkWriteMixinClosed(TestBulkWriteMixin): self.bulk.update_definition(self.course_key.replace(branch='b'), other_definition) self.assertConnCalls() self.bulk._end_bulk_operation(self.course_key) - self.assertItemsEqual( + six.assertCountEqual( + self, [ call.insert_definition(self.definition, self.course_key), call.insert_definition(other_definition, self.course_key) @@ -272,7 +276,8 @@ class TestBulkWriteMixinClosed(TestBulkWriteMixin): self.bulk.update_structure(self.course_key.replace(branch='b'), other_structure) self.bulk.insert_course_index(self.course_key, {'versions': {'a': self.structure['_id'], 'b': other_structure['_id']}}) self.bulk._end_bulk_operation(self.course_key) - self.assertItemsEqual( + six.assertCountEqual( + self, [ call.insert_structure(self.structure, self.course_key), call.insert_structure(other_structure, self.course_key), @@ -392,7 +397,7 @@ class TestBulkWriteMixinFindMethods(TestBulkWriteMixin): expected = matching + db_indexes self.conn.find_matching_course_indexes.return_value = db_indexes result = self.bulk.find_matching_course_indexes(branch, search_targets) - self.assertItemsEqual(result, expected) + six.assertCountEqual(self, result, expected) for item in unmatching: self.assertNotIn(item, result) @@ -580,7 +585,7 @@ class TestBulkWriteMixinFindMethods(TestBulkWriteMixin): self.conn.find_ancestor_structures.return_value = db_match + db_unmatch results = self.bulk.find_ancestor_structures(original_version, block_id) self.conn.find_ancestor_structures.assert_called_once_with(original_version, block_id) - self.assertItemsEqual(active_match + db_match, results) + six.assertCountEqual(self, active_match + db_match, results) @ddt.ddt diff --git a/common/lib/xmodule/xmodule/tests/__init__.py b/common/lib/xmodule/xmodule/tests/__init__.py index a1c8322616..6aab74ede0 100644 --- a/common/lib/xmodule/xmodule/tests/__init__.py +++ b/common/lib/xmodule/xmodule/tests/__init__.py @@ -395,7 +395,8 @@ class CourseComparisonTest(TestCase): } # Split Mongo and Old-Mongo disagree about what the block_id of courses is, so skip those in # this comparison - self.assertItemsEqual( + six.assertCountEqual( + self, [map_key(item.location) for item in expected_items if item.scope_ids.block_type != 'course'], [key for key in actual_item_map.keys() if key[0] != 'course'], ) diff --git a/common/lib/xmodule/xmodule/tests/test_capa_module.py b/common/lib/xmodule/xmodule/tests/test_capa_module.py index c695d7b6ab..b2544f1642 100644 --- a/common/lib/xmodule/xmodule/tests/test_capa_module.py +++ b/common/lib/xmodule/xmodule/tests/test_capa_module.py @@ -863,7 +863,7 @@ class ProblemBlockTest(unittest.TestCase): self.assertEqual(xqueue_interface._http_post.call_count, 1) _, kwargs = xqueue_interface._http_post.call_args # pylint: disable=unpacking-non-sequence - self.assertItemsEqual(fpaths, list(kwargs['files'].keys())) + six.assertCountEqual(self, fpaths, list(kwargs['files'].keys())) for fpath, fileobj in six.iteritems(kwargs['files']): self.assertEqual(fpath, fileobj.name) @@ -896,7 +896,7 @@ class ProblemBlockTest(unittest.TestCase): self.assertEqual(xqueue_interface._http_post.call_count, 1) _, kwargs = xqueue_interface._http_post.call_args # pylint: disable=unpacking-non-sequence - self.assertItemsEqual(fnames, list(kwargs['files'].keys())) + six.assertCountEqual(self, fnames, list(kwargs['files'].keys())) for fpath, fileobj in six.iteritems(kwargs['files']): self.assertEqual(fpath, fileobj.name) diff --git a/common/lib/xmodule/xmodule/tests/test_export.py b/common/lib/xmodule/xmodule/tests/test_export.py index f5b774d156..15c9ad4c5a 100644 --- a/common/lib/xmodule/xmodule/tests/test_export.py +++ b/common/lib/xmodule/xmodule/tests/test_export.py @@ -14,6 +14,7 @@ import ddt import lxml.etree import mock import pytz +import six from django.utils.translation import ugettext_lazy from fs.osfs import OSFS from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator @@ -136,7 +137,8 @@ class RoundTripTestCase(unittest.TestCase): course_id = initial_course.id print("Checking key equality") - self.assertItemsEqual( + six.assertCountEqual( + self, list(initial_import.modules[course_id].keys()), list(second_import.modules[course_id].keys()) ) diff --git a/common/test/acceptance/tests/lms/test_lms_courseware.py b/common/test/acceptance/tests/lms/test_lms_courseware.py index e9433db9f7..2b1d648efd 100644 --- a/common/test/acceptance/tests/lms/test_lms_courseware.py +++ b/common/test/acceptance/tests/lms/test_lms_courseware.py @@ -9,6 +9,7 @@ import json from datetime import datetime, timedelta import ddt +import six from six.moves import range from openedx.core.lib.tests import attr @@ -939,4 +940,4 @@ class WordCloudTests(UniqueCourseTest): self.assertTrue(self.courseware_page.is_word_cloud_rendered) self.courseware_page.input_word_cloud('test_wordcloud') self.courseware_page.save_word_cloud() - self.assertItemsEqual(expected_data, self.courseware_page.word_cloud_answer_list) + six.assertCountEqual(self, expected_data, self.courseware_page.word_cloud_answer_list) diff --git a/common/test/acceptance/tests/studio/test_studio_container.py b/common/test/acceptance/tests/studio/test_studio_container.py index c914d786c2..5963475d76 100644 --- a/common/test/acceptance/tests/studio/test_studio_container.py +++ b/common/test/acceptance/tests/studio/test_studio_container.py @@ -8,6 +8,7 @@ from __future__ import absolute_import import datetime import ddt +import six from common.test.acceptance.fixtures.course import XBlockFixtureDesc from common.test.acceptance.pages.lms.courseware import CoursewarePage @@ -297,13 +298,13 @@ class BaseGroupConfigurationsTest(ContainerBase): """ Check that the expected partition scheme is selected. """ - self.assertItemsEqual(expected_scheme, visibility_editor.selected_partition_scheme) + six.assertCountEqual(self, expected_scheme, visibility_editor.selected_partition_scheme) def verify_selected_groups(self, visibility_editor, expected_groups): """ Check the expected partition groups. """ - self.assertItemsEqual(expected_groups, [group.text for group in visibility_editor.selected_groups]) + six.assertCountEqual(self, expected_groups, [group.text for group in visibility_editor.selected_groups]) def select_and_verify_saved(self, component, partition_label, groups=[]): """ diff --git a/common/test/acceptance/tests/studio/test_studio_outline.py b/common/test/acceptance/tests/studio/test_studio_outline.py index 50395828a0..7905d669b5 100644 --- a/common/test/acceptance/tests/studio/test_studio_outline.py +++ b/common/test/acceptance/tests/studio/test_studio_outline.py @@ -10,6 +10,7 @@ from datetime import datetime, timedelta from unittest import skip from pytz import UTC +import six from six.moves import range from common.test.acceptance.fixtures.config import ConfigModelFixture @@ -1713,7 +1714,7 @@ class DeprecationWarningMessageTest(CourseOutlineTest): self.assertEqual(self.course_outline_page.components_visible, components_present) if components_present: self.assertEqual(self.course_outline_page.components_list_heading, self.COMPONENT_LIST_HEADING) - self.assertItemsEqual(self.course_outline_page.components_display_names, components_display_name_list) + six.assertCountEqual(self, self.course_outline_page.components_display_names, components_display_name_list) def test_no_deprecation_warning_message_present(self): """ diff --git a/lms/djangoapps/badges/tests/test_models.py b/lms/djangoapps/badges/tests/test_models.py index 844e28292e..6aaddaeb79 100644 --- a/lms/djangoapps/badges/tests/test_models.py +++ b/lms/djangoapps/badges/tests/test_models.py @@ -248,7 +248,7 @@ class BadgeAssertionTest(ModuleStoreTestCase): Verify that grabbing all assertions for a user behaves as expected. This function uses object IDs because for some reason Jenkins trips up - on its assertItemsEqual check here despite the items being equal. + on its assertCountEqual check here despite the items being equal. """ user = UserFactory() assertions = [BadgeAssertionFactory.create(user=user).id for _i in range(3)] diff --git a/lms/djangoapps/bulk_email/tests/test_email.py b/lms/djangoapps/bulk_email/tests/test_email.py index 7ba38669e5..67d50b398c 100644 --- a/lms/djangoapps/bulk_email/tests/test_email.py +++ b/lms/djangoapps/bulk_email/tests/test_email.py @@ -290,7 +290,8 @@ class TestEmailSendFromDashboardMockedHtmlToText(EmailSendFromDashboardTestCase) # the 1 is for the instructor in this test and others self.assertEquals(len(mail.outbox), 1 + len(self.staff)) - self.assertItemsEqual( + six.assertCountEqual( + self, [e.to[0] for e in mail.outbox], [self.instructor.email] + [s.email for s in self.staff] ) @@ -311,7 +312,8 @@ class TestEmailSendFromDashboardMockedHtmlToText(EmailSendFromDashboardTestCase) response = self.client.post(self.send_mail_url, test_email) self.assertEquals(json.loads(response.content.decode('utf-8')), self.success_content) - self.assertItemsEqual( + six.assertCountEqual( + self, [e.to[0] for e in mail.outbox], [s.email for s in self.students] ) @@ -352,7 +354,8 @@ class TestEmailSendFromDashboardMockedHtmlToText(EmailSendFromDashboardTestCase) response = self.client.post(self.send_mail_url, test_email) self.assertEquals(json.loads(response.content.decode('utf-8')), self.success_content) - self.assertItemsEqual( + six.assertCountEqual( + self, [e.to[0] for e in mail.outbox], [s.email for s in self.students] ) @@ -410,7 +413,8 @@ class TestEmailSendFromDashboardMockedHtmlToText(EmailSendFromDashboardTestCase) # the 1 is for the instructor self.assertEquals(len(mail.outbox), 1 + len(self.staff) + len(self.students)) - self.assertItemsEqual( + six.assertCountEqual( + self, [e.to[0] for e in mail.outbox], [self.instructor.email] + [s.email for s in self.staff] + [s.email for s in self.students] ) @@ -467,7 +471,8 @@ class TestEmailSendFromDashboardMockedHtmlToText(EmailSendFromDashboardTestCase) self.assertEquals(json.loads(response.content.decode('utf-8')), self.success_content) self.assertEquals(len(mail.outbox), 1 + len(self.staff) + len(self.students)) - self.assertItemsEqual( + six.assertCountEqual( + self, [e.to[0] for e in mail.outbox], [self.instructor.email] + [s.email for s in self.staff] + [s.email for s in self.students] ) @@ -494,7 +499,8 @@ class TestEmailSendFromDashboardMockedHtmlToText(EmailSendFromDashboardTestCase) self.assertEquals(len(mail.outbox), 1 + len(self.staff) + len(self.students)) - self.assertItemsEqual( + six.assertCountEqual( + self, [e.to[0] for e in mail.outbox], [self.instructor.email] + [s.email for s in self.staff] + [s.email for s in self.students] ) @@ -595,7 +601,7 @@ class TestEmailSendFromDashboardMockedHtmlToText(EmailSendFromDashboardTestCase) [s.email for s in self.staff] + [s.email for s in self.students] + [s.email for s in added_users if s not in optouts]) - self.assertItemsEqual(outbox_contents, should_send_contents) + six.assertCountEqual(self, outbox_contents, should_send_contents) @skipIf(os.environ.get("TRAVIS") == 'true', "Skip this test in Travis CI.") @@ -623,7 +629,8 @@ class TestEmailSendFromDashboard(EmailSendFromDashboardTestCase): self.assertEquals(json.loads(response.content.decode('utf-8')), self.success_content) self.assertEquals(len(mail.outbox), 1 + len(self.staff) + len(self.students)) - self.assertItemsEqual( + six.assertCountEqual( + self, [e.to[0] for e in mail.outbox], [self.instructor.email] + [s.email for s in self.staff] + [s.email for s in self.students] ) diff --git a/lms/djangoapps/ccx/api/v0/tests/test_views.py b/lms/djangoapps/ccx/api/v0/tests/test_views.py index 1e29fb6e56..9edd80f766 100644 --- a/lms/djangoapps/ccx/api/v0/tests/test_views.py +++ b/lms/djangoapps/ccx/api/v0/tests/test_views.py @@ -1105,7 +1105,7 @@ class CcxDetailTest(CcxRestApiTest): ) self.assertEqual(resp.data.get('coach_email'), self.ccx.coach.email) # pylint: disable=no-member self.assertEqual(resp.data.get('master_course_id'), six.text_type(self.ccx.course_id)) - self.assertItemsEqual(resp.data.get('course_modules'), self.master_course_chapters) + six.assertCountEqual(self, resp.data.get('course_modules'), self.master_course_chapters) @ddt.data(*AUTH_ATTRS) def test_delete_detail(self, auth_attr): @@ -1332,19 +1332,19 @@ class CcxDetailTest(CcxRestApiTest): resp = self.client.patch(self.detail_url, data, format='json', HTTP_AUTHORIZATION=getattr(self, auth_attr)) self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT) ccx_from_db = CustomCourseForEdX.objects.get(id=self.ccx.id) - self.assertItemsEqual(ccx_from_db.structure, data['course_modules']) + six.assertCountEqual(self, ccx_from_db.structure, data['course_modules']) data = {'course_modules': []} resp = self.client.patch(self.detail_url, data, format='json', HTTP_AUTHORIZATION=getattr(self, auth_attr)) self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT) ccx_from_db = CustomCourseForEdX.objects.get(id=self.ccx.id) - self.assertItemsEqual(ccx_from_db.structure, []) + six.assertCountEqual(self, ccx_from_db.structure, []) data = {'course_modules': self.master_course_chapters} resp = self.client.patch(self.detail_url, data, format='json', HTTP_AUTHORIZATION=getattr(self, auth_attr)) self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT) ccx_from_db = CustomCourseForEdX.objects.get(id=self.ccx.id) - self.assertItemsEqual(ccx_from_db.structure, self.master_course_chapters) + six.assertCountEqual(self, ccx_from_db.structure, self.master_course_chapters) data = {'course_modules': None} resp = self.client.patch(self.detail_url, data, format='json', HTTP_AUTHORIZATION=getattr(self, auth_attr)) @@ -1357,7 +1357,7 @@ class CcxDetailTest(CcxRestApiTest): resp = self.client.patch(self.detail_url, data, format='json', HTTP_AUTHORIZATION=getattr(self, auth_attr)) self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT) ccx_from_db = CustomCourseForEdX.objects.get(id=self.ccx.id) - self.assertItemsEqual(ccx_from_db.structure, chapters) + six.assertCountEqual(self, ccx_from_db.structure, chapters) @ddt.data( ('auth', True), @@ -1381,7 +1381,7 @@ class CcxDetailTest(CcxRestApiTest): else: self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT) ccx_from_db = CustomCourseForEdX.objects.get(id=self.ccx.id) - self.assertItemsEqual(ccx_from_db.structure, chapters) + six.assertCountEqual(self, ccx_from_db.structure, chapters) @ddt.data( ('auth', True), diff --git a/lms/djangoapps/certificates/tests/test_api.py b/lms/djangoapps/certificates/tests/test_api.py index 69a6ad9c76..8bcf21287a 100644 --- a/lms/djangoapps/certificates/tests/test_api.py +++ b/lms/djangoapps/certificates/tests/test_api.py @@ -762,7 +762,8 @@ class CertificatesBrandingTest(TestCase): data = certs_api.get_certificate_header_context(is_secure=True) # Make sure there are not unexpected keys in dict returned by 'get_certificate_header_context' - self.assertItemsEqual( + six.assertCountEqual( + self, list(data.keys()), ['logo_src', 'logo_url'] ) @@ -787,7 +788,8 @@ class CertificatesBrandingTest(TestCase): data = certs_api.get_certificate_footer_context() # Make sure there are not unexpected keys in dict returned by 'get_certificate_footer_context' - self.assertItemsEqual( + six.assertCountEqual( + self, list(data.keys()), ['company_about_url', 'company_privacy_url', 'company_tos_url'] ) diff --git a/lms/djangoapps/courseware/management/commands/tests/test_dump_course.py b/lms/djangoapps/courseware/management/commands/tests/test_dump_course.py index a968c300a4..34d50f7021 100644 --- a/lms/djangoapps/courseware/management/commands/tests/test_dump_course.py +++ b/lms/djangoapps/courseware/management/commands/tests/test_dump_course.py @@ -135,7 +135,8 @@ class CommandsTestBase(SharedModuleStoreTestCase): self.assertEqual(dump[video_id]['category'], 'video') video_metadata = dump[video_id]['metadata'] video_metadata.pop('edx_video_id', None) - self.assertItemsEqual( + six.assertCountEqual( + self, list(video_metadata.keys()), ['youtube_id_0_75', 'youtube_id_1_0', 'youtube_id_1_25', 'youtube_id_1_5'] ) diff --git a/lms/djangoapps/courseware/tests/test_submitting_problems.py b/lms/djangoapps/courseware/tests/test_submitting_problems.py index 788d673135..38d502766f 100644 --- a/lms/djangoapps/courseware/tests/test_submitting_problems.py +++ b/lms/djangoapps/courseware/tests/test_submitting_problems.py @@ -803,8 +803,8 @@ class ProblemWithUploadedFilesTest(TestSubmittingProblems): self.assertEqual(name, "post") self.assertEqual(len(args), 1) self.assertTrue(args[0].endswith("/submit/")) - self.assertItemsEqual(list(kwargs.keys()), ["files", "data", "timeout"]) - self.assertItemsEqual(list(kwargs['files'].keys()), filenames.split()) + six.assertCountEqual(self, list(kwargs.keys()), ["files", "data", "timeout"]) + six.assertCountEqual(self, list(kwargs['files'].keys()), filenames.split()) class TestPythonGradedResponse(TestSubmittingProblems): diff --git a/lms/djangoapps/courseware/tests/test_video_handlers.py b/lms/djangoapps/courseware/tests/test_video_handlers.py index a1894ef465..a344b3a438 100644 --- a/lms/djangoapps/courseware/tests/test_video_handlers.py +++ b/lms/djangoapps/courseware/tests/test_video_handlers.py @@ -366,7 +366,7 @@ class TestTranscriptAvailableTranslationsDispatch(TestVideo): # Make request to available translations dispatch. request = Request.blank('/available_translations') response = self.item.transcript(request=request, dispatch='available_translations') - self.assertItemsEqual(json.loads(response.body), result) + six.assertCountEqual(self, json.loads(response.body), result) @patch('xmodule.video_module.transcripts_utils.edxval_api.get_available_transcript_languages') def test_val_available_translations_feature_disabled(self, mock_get_available_transcript_languages): diff --git a/lms/djangoapps/courseware/tests/test_video_mongo.py b/lms/djangoapps/courseware/tests/test_video_mongo.py index 8f23b9c500..fbc83780af 100644 --- a/lms/djangoapps/courseware/tests/test_video_mongo.py +++ b/lms/djangoapps/courseware/tests/test_video_mongo.py @@ -1576,7 +1576,7 @@ class TestVideoBlockStudentViewJson(BaseTestVideoXBlock, CacheIsolationTestCase) self.video.transcripts = transcripts self.video.sub = english_sub student_view_response = self.get_result() - self.assertItemsEqual(list(student_view_response['transcripts'].keys()), expected_transcripts) + six.assertCountEqual(self, list(student_view_response['transcripts'].keys()), expected_transcripts) @ddt.ddt diff --git a/lms/djangoapps/discussion/django_comment_client/tests/test_utils.py b/lms/djangoapps/discussion/django_comment_client/tests/test_utils.py index 22ea5ade1f..989d1a5ecd 100644 --- a/lms/djangoapps/discussion/django_comment_client/tests/test_utils.py +++ b/lms/djangoapps/discussion/django_comment_client/tests/test_utils.py @@ -7,6 +7,7 @@ import json import ddt import mock +import six from django.test import RequestFactory, TestCase from django.urls import reverse from edx_django_utils.cache import RequestCache @@ -1019,7 +1020,8 @@ class CategoryMapTestCase(CategoryMapTestMixin, ModuleStoreTestCase): "Topic B": {"id": "Topic_B"}, "Topic C": {"id": "Topic_C"} } - self.assertItemsEqual( + six.assertCountEqual( + self, utils.get_discussion_categories_ids(self.course, self.user), ["Topic_A", "Topic_B", "Topic_C"] ) @@ -1031,7 +1033,8 @@ class CategoryMapTestCase(CategoryMapTestMixin, ModuleStoreTestCase): self.create_discussion("Chapter 2 / Section 1 / Subsection 1", "Discussion") self.create_discussion("Chapter 2 / Section 1 / Subsection 2", "Discussion") self.create_discussion("Chapter 3 / Section 1", "Discussion") - self.assertItemsEqual( + six.assertCountEqual( + self, utils.get_discussion_categories_ids(self.course, self.user), ["discussion1", "discussion2", "discussion3", "discussion4", "discussion5", "discussion6"] ) @@ -1045,7 +1048,8 @@ class CategoryMapTestCase(CategoryMapTestMixin, ModuleStoreTestCase): self.create_discussion("Chapter 1", "Discussion 1") self.create_discussion("Chapter 2", "Discussion") self.create_discussion("Chapter 2 / Section 1 / Subsection 1", "Discussion") - self.assertItemsEqual( + six.assertCountEqual( + self, utils.get_discussion_categories_ids(self.course, self.user), ["Topic_A", "Topic_B", "Topic_C", "discussion1", "discussion2", "discussion3"] ) diff --git a/lms/djangoapps/edxnotes/tests.py b/lms/djangoapps/edxnotes/tests.py index 5e83d1ef2e..fb7758cd30 100644 --- a/lms/djangoapps/edxnotes/tests.py +++ b/lms/djangoapps/edxnotes/tests.py @@ -10,6 +10,7 @@ from unittest import skipUnless import ddt import jwt +import six from six import text_type from six.moves.urllib.parse import urlparse, parse_qs # pylint: disable=import-error from django.conf import settings @@ -334,7 +335,8 @@ class EdxNotesHelpersTest(ModuleStoreTestCase): } ) - self.assertItemsEqual( + six.assertCountEqual( + self, { "count": 2, "current_page": 1, @@ -440,7 +442,8 @@ class EdxNotesHelpersTest(ModuleStoreTestCase): ] }) - self.assertItemsEqual( + six.assertCountEqual( + self, { "count": 2, "current_page": 1, @@ -524,7 +527,8 @@ class EdxNotesHelpersTest(ModuleStoreTestCase): Tests no results. """ mock_get.return_value.content = json.dumps(NOTES_API_EMPTY_RESPONSE) - self.assertItemsEqual( + six.assertCountEqual( + self, NOTES_VIEW_EMPTY_RESPONSE, helpers.get_notes(self.request, self.course) ) @@ -571,7 +575,8 @@ class EdxNotesHelpersTest(ModuleStoreTestCase): }, ] - self.assertItemsEqual( + six.assertCountEqual( + self, [{ u"quote": u"quote text", u"text": u"text", @@ -617,7 +622,8 @@ class EdxNotesHelpersTest(ModuleStoreTestCase): ] self.html_module_2.visible_to_staff_only = True self.store.update_item(self.html_module_2, self.user.id) - self.assertItemsEqual( + six.assertCountEqual( + self, [{ u"quote": u"quote text", u"text": u"text", @@ -660,8 +666,10 @@ class EdxNotesHelpersTest(ModuleStoreTestCase): u"updated": datetime(2014, 11, 19, 8, 5, 16, 00000).isoformat(), }] - self.assertItemsEqual( - [], helpers.preprocess_collection(self.user, self.course, initial_collection) + six.assertCountEqual( + self, + [], + helpers.preprocess_collection(self.user, self.course, initial_collection) ) @override_settings(NOTES_DISABLED_TABS=['course_structure', 'tags']) @@ -684,7 +692,8 @@ class EdxNotesHelpersTest(ModuleStoreTestCase): }, ] - self.assertItemsEqual( + six.assertCountEqual( + self, [ { diff --git a/lms/djangoapps/instructor_task/tests/test_base.py b/lms/djangoapps/instructor_task/tests/test_base.py index 70a5eb3538..0e8a784f34 100644 --- a/lms/djangoapps/instructor_task/tests/test_base.py +++ b/lms/djangoapps/instructor_task/tests/test_base.py @@ -11,6 +11,7 @@ import shutil from tempfile import mkdtemp from uuid import uuid4 +import six import unicodecsv from celery.states import FAILURE, SUCCESS from django.contrib.auth.models import User @@ -369,8 +370,8 @@ class TestReportMixin(object): self.assertEqual(csv_rows, expected_rows) self.assertEqual(numeric_csv_rows, numeric_expected_rows) else: - self.assertItemsEqual(csv_rows, expected_rows) - self.assertItemsEqual(numeric_csv_rows, numeric_expected_rows) + six.assertCountEqual(self, csv_rows, expected_rows) + six.assertCountEqual(self, numeric_csv_rows, numeric_expected_rows) @staticmethod def _extract_and_round_numeric_items(dictionary): diff --git a/lms/djangoapps/shoppingcart/tests/test_models.py b/lms/djangoapps/shoppingcart/tests/test_models.py index f685861c46..ce58763fdb 100644 --- a/lms/djangoapps/shoppingcart/tests/test_models.py +++ b/lms/djangoapps/shoppingcart/tests/test_models.py @@ -1376,12 +1376,12 @@ class InvoiceHistoryTest(TestCase): def _assert_history_items(self, expected_items): """Check line item info in the latest history record. """ items = self._latest_history()['items'] - self.assertItemsEqual(items, expected_items) + six.assertCountEqual(self, items, expected_items) def _assert_history_transactions(self, expected_transactions): """Check transactions (payments/refunds) in the latest history record. """ transactions = self._latest_history()['transactions'] - self.assertItemsEqual(transactions, expected_transactions) + six.assertCountEqual(self, transactions, expected_transactions) def _latest_history(self): """Retrieve the snapshot from the latest history record. """ diff --git a/openedx/core/djangoapps/catalog/tests/test_utils.py b/openedx/core/djangoapps/catalog/tests/test_utils.py index 49e6e3b1c1..6f6dabad32 100644 --- a/openedx/core/djangoapps/catalog/tests/test_utils.py +++ b/openedx/core/djangoapps/catalog/tests/test_utils.py @@ -842,7 +842,7 @@ class TestGetProgramsByType(CacheIsolationTestCase): def test_get_masters_programs(self): expected_programs = [self.masters_program_1, self.masters_program_2] - self.assertItemsEqual(expected_programs, get_programs_by_type(self.site, 'masters')) + six.assertCountEqual(self, expected_programs, get_programs_by_type(self.site, 'masters')) def test_get_bachelors_programs(self): expected_programs = [self.bachelors_program] diff --git a/openedx/core/djangoapps/coursegraph/management/commands/tests/test_dump_to_neo4j.py b/openedx/core/djangoapps/coursegraph/management/commands/tests/test_dump_to_neo4j.py index 5156428876..40095b17ec 100644 --- a/openedx/core/djangoapps/coursegraph/management/commands/tests/test_dump_to_neo4j.py +++ b/openedx/core/djangoapps/coursegraph/management/commands/tests/test_dump_to_neo4j.py @@ -8,6 +8,7 @@ from datetime import datetime import ddt import mock +import six from django.core.management import call_command from django.utils import six from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase @@ -422,7 +423,7 @@ class TestModuleStoreSerializer(TestDumpToNeo4jCommandBase): # 2 nodes and no relationships from the second self.assertEqual(len(mock_graph.nodes), 11) - self.assertItemsEqual(submitted, self.course_strings) + six.assertCountEqual(self, submitted, self.course_strings) @mock.patch('openedx.core.djangoapps.coursegraph.tasks.NodeSelector') @mock.patch('openedx.core.djangoapps.coursegraph.tasks.authenticate_and_create_graph') @@ -445,7 +446,7 @@ class TestModuleStoreSerializer(TestDumpToNeo4jCommandBase): number_rollbacks=2, ) - self.assertItemsEqual(submitted, self.course_strings) + six.assertCountEqual(self, submitted, self.course_strings) @mock.patch('openedx.core.djangoapps.coursegraph.tasks.NodeSelector') @mock.patch('openedx.core.djangoapps.coursegraph.tasks.authenticate_and_create_graph') diff --git a/openedx/core/djangoapps/enrollments/tests/test_views.py b/openedx/core/djangoapps/enrollments/tests/test_views.py index c7764ea8ac..4a5a4ff502 100644 --- a/openedx/core/djangoapps/enrollments/tests/test_views.py +++ b/openedx/core/djangoapps/enrollments/tests/test_views.py @@ -363,7 +363,8 @@ class EnrollmentTest(EnrollmentTestMixin, ModuleStoreTestCase, APITestCase, Ente response = self.client.get(reverse('courseenrollments'), {'user': self.user.username}, **kwargs) self.assertEqual(response.status_code, status.HTTP_200_OK) data = json.loads(response.content.decode('utf-8')) - self.assertItemsEqual( + six.assertCountEqual( + self, [(datum['course_details']['course_id'], datum['course_details']['course_name']) for datum in data], [(six.text_type(course.id), course.display_name_with_default) for course in courses] ) @@ -1683,4 +1684,4 @@ class CourseEnrollmentsApiListTest(APITestCase, ModuleStoreTestCase): content = self._assert_list_of_enrollments(query_params, status.HTTP_200_OK) results = content['results'] - self.assertItemsEqual(results, expected_results) + six.assertCountEqual(self, results, expected_results) diff --git a/openedx/core/djangoapps/lang_pref/tests/test_middleware.py b/openedx/core/djangoapps/lang_pref/tests/test_middleware.py index 372691e422..e633a07a4d 100644 --- a/openedx/core/djangoapps/lang_pref/tests/test_middleware.py +++ b/openedx/core/djangoapps/lang_pref/tests/test_middleware.py @@ -8,6 +8,7 @@ import itertools import ddt import mock +import six from django.conf import settings from django.contrib.sessions.middleware import SessionMiddleware from django.http import HttpResponse @@ -149,7 +150,7 @@ class TestUserPreferenceMiddleware(CacheIsolationTestCase): accept_lang_out = parse_accept_lang_header(accept_lang_out) if accept_lang_out and accept_lang_result: - self.assertItemsEqual(accept_lang_result, accept_lang_out) + six.assertCountEqual(self, accept_lang_result, accept_lang_out) else: self.assertEqual(accept_lang_result, accept_lang_out) diff --git a/openedx/core/djangoapps/programs/tests/test_utils.py b/openedx/core/djangoapps/programs/tests/test_utils.py index a755ef79ed..f613c87ccb 100644 --- a/openedx/core/djangoapps/programs/tests/test_utils.py +++ b/openedx/core/djangoapps/programs/tests/test_utils.py @@ -674,7 +674,8 @@ class TestProgramProgressMeter(TestCase): self._create_certificates(unknown['key'], status='unknown') meter = ProgramProgressMeter(self.site, self.user) - self.assertItemsEqual( + six.assertCountEqual( + self, meter.completed_course_runs, [ {'course_run_id': downloadable['key'], 'type': CourseMode.VERIFIED}, diff --git a/openedx/core/djangoapps/schedules/management/commands/tests/test_send_upgrade_reminder.py b/openedx/core/djangoapps/schedules/management/commands/tests/test_send_upgrade_reminder.py index 4174f67129..565796fd0e 100644 --- a/openedx/core/djangoapps/schedules/management/commands/tests/test_send_upgrade_reminder.py +++ b/openedx/core/djangoapps/schedules/management/commands/tests/test_send_upgrade_reminder.py @@ -7,6 +7,7 @@ import logging from unittest import skipUnless import ddt +import six from django.conf import settings from edx_ace import Message from edx_ace.utils.date import serialize @@ -86,7 +87,8 @@ class TestUpgradeReminder(ScheduleSendEmailTestMixin, CacheIsolationTestCase): messages = [Message.from_string(m) for m in sent_messages] self.assertEqual(len(messages), 1) message = messages[0] - self.assertItemsEqual( + six.assertCountEqual( + self, message.context['course_ids'], [str(schedules[i].enrollment.course.id) for i in (1, 2, 4)] ) diff --git a/openedx/core/djangoapps/site_configuration/tests/test_helpers.py b/openedx/core/djangoapps/site_configuration/tests/test_helpers.py index beb04a85cf..6c8b8b8d23 100644 --- a/openedx/core/djangoapps/site_configuration/tests/test_helpers.py +++ b/openedx/core/djangoapps/site_configuration/tests/test_helpers.py @@ -3,6 +3,7 @@ Tests for helper function provided by site_configuration app. """ from __future__ import absolute_import +import six from django.test import TestCase from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers @@ -81,7 +82,8 @@ class TestHelpers(TestCase): Test that get_dict returns correct value for any given key. """ # Make sure entry is saved and retrieved correctly - self.assertItemsEqual( + six.assertCountEqual( + self, configuration_helpers.get_dict("REGISTRATION_EXTRA_FIELDS"), test_config['REGISTRATION_EXTRA_FIELDS'], ) @@ -91,7 +93,8 @@ class TestHelpers(TestCase): expected.update(test_config['REGISTRATION_EXTRA_FIELDS']) # Test that the default value is returned if the value for the given key is not found in the configuration - self.assertItemsEqual( + six.assertCountEqual( + self, configuration_helpers.get_dict("REGISTRATION_EXTRA_FIELDS", default), expected, ) @@ -134,7 +137,8 @@ class TestHelpers(TestCase): test_config['css_overrides_file'] ) - self.assertItemsEqual( + six.assertCountEqual( + self, configuration_helpers.get_value_for_org(test_org, "REGISTRATION_EXTRA_FIELDS"), test_config['REGISTRATION_EXTRA_FIELDS'] ) @@ -177,7 +181,8 @@ class TestHelpers(TestCase): """ test_orgs = [test_config['course_org_filter']] with with_site_configuration_context(configuration=test_config): - self.assertItemsEqual( + six.assertCountEqual( + self, list(configuration_helpers.get_all_orgs()), test_orgs, ) @@ -185,7 +190,8 @@ class TestHelpers(TestCase): @with_site_configuration(configuration=test_config_multi_org) def test_get_current_site_orgs(self): test_orgs = test_config_multi_org['course_org_filter'] - self.assertItemsEqual( + six.assertCountEqual( + self, list(configuration_helpers.get_current_site_orgs()), test_orgs ) diff --git a/openedx/core/djangoapps/theming/tests/test_commands.py b/openedx/core/djangoapps/theming/tests/test_commands.py index 7b4563c0bb..d6ec4a7ee9 100644 --- a/openedx/core/djangoapps/theming/tests/test_commands.py +++ b/openedx/core/djangoapps/theming/tests/test_commands.py @@ -3,6 +3,7 @@ Tests for Management commands of comprehensive theming. """ from __future__ import absolute_import +import six from django.core.management import CommandError, call_command from django.test import TestCase @@ -44,12 +45,16 @@ class TestUpdateAssets(TestCase): """ # make sure compile_sass picks all themes when called with 'themes=all' option parsed_args = Command.parse_arguments(themes=["all"]) - self.assertItemsEqual(parsed_args[2], get_themes()) + six.assertCountEqual(self, parsed_args[2], get_themes()) # make sure compile_sass picks no themes when called with 'themes=no' option parsed_args = Command.parse_arguments(themes=["no"]) - self.assertItemsEqual(parsed_args[2], []) + six.assertCountEqual(self, parsed_args[2], []) # make sure compile_sass picks only specified themes parsed_args = Command.parse_arguments(themes=["test-theme"]) - self.assertItemsEqual(parsed_args[2], [theme for theme in get_themes() if theme.theme_dir_name == "test-theme"]) + six.assertCountEqual( + self, + parsed_args[2], + [theme for theme in get_themes() if theme.theme_dir_name == "test-theme"] + ) diff --git a/openedx/core/djangoapps/theming/tests/test_helpers.py b/openedx/core/djangoapps/theming/tests/test_helpers.py index bb920ff1cb..2055d9fb15 100644 --- a/openedx/core/djangoapps/theming/tests/test_helpers.py +++ b/openedx/core/djangoapps/theming/tests/test_helpers.py @@ -3,6 +3,7 @@ Test helpers for Comprehensive Theming. """ from __future__ import absolute_import +import six from django.conf import settings from django.test import TestCase, override_settings from edx_django_utils.cache import RequestCache @@ -38,7 +39,7 @@ class TestHelpers(TestCase): Theme('test-theme', 'test-theme', get_theme_base_dir('test-theme'), settings.PROJECT_ROOT), ] actual_themes = get_themes() - self.assertItemsEqual(expected_themes, actual_themes) + six.assertCountEqual(self, expected_themes, actual_themes) @override_settings(COMPREHENSIVE_THEME_DIRS=[settings.TEST_THEME.dirname()]) def test_get_themes_2(self): @@ -49,7 +50,7 @@ class TestHelpers(TestCase): Theme('test-theme', 'test-theme', get_theme_base_dir('test-theme'), settings.PROJECT_ROOT), ] actual_themes = get_themes() - self.assertItemsEqual(expected_themes, actual_themes) + six.assertCountEqual(self, expected_themes, actual_themes) def test_get_value_returns_override(self): """ diff --git a/openedx/core/djangoapps/user_api/accounts/tests/test_retirement_views.py b/openedx/core/djangoapps/user_api/accounts/tests/test_retirement_views.py index 0d3bfb6075..8e20e9a621 100644 --- a/openedx/core/djangoapps/user_api/accounts/tests/test_retirement_views.py +++ b/openedx/core/djangoapps/user_api/accounts/tests/test_retirement_views.py @@ -11,6 +11,7 @@ import unittest import ddt import mock import pytz +import six from consent.models import DataSharingConsent from django.conf import settings from django.contrib.auth.models import User @@ -661,7 +662,7 @@ class TestAccountRetirementList(RetirementTestCase): del retirement['created'] del retirement['modified'] - self.assertItemsEqual(response_data, expected_data) + six.assertCountEqual(self, response_data, expected_data) def test_empty(self): """ @@ -834,7 +835,7 @@ class TestAccountRetirementsByStatusAndDate(RetirementTestCase): except KeyError: pass - self.assertItemsEqual(response_data, expected_data) + six.assertCountEqual(self, response_data, expected_data) def test_empty(self): """ diff --git a/openedx/core/djangoapps/user_api/accounts/tests/test_views.py b/openedx/core/djangoapps/user_api/accounts/tests/test_views.py index 6b24bd66b8..683651a129 100644 --- a/openedx/core/djangoapps/user_api/accounts/tests/test_views.py +++ b/openedx/core/djangoapps/user_api/accounts/tests/test_views.py @@ -12,6 +12,7 @@ from copy import deepcopy import ddt import mock import pytz +import six from django.conf import settings from django.core.urlresolvers import reverse from django.test.testcases import TransactionTestCase @@ -790,7 +791,7 @@ class TestAccountsAPI(CacheIsolationTestCase, UserAPITestCase): # than django model id. for proficiencies in ([{"code": "en"}, {"code": "fr"}, {"code": "es"}], [{"code": "fr"}], [{"code": "aa"}], []): response = self.send_patch(client, {"language_proficiencies": proficiencies}) - self.assertItemsEqual(response.data["language_proficiencies"], proficiencies) + six.assertCountEqual(self, response.data["language_proficiencies"], proficiencies) @ddt.data( ( diff --git a/openedx/core/djangoapps/user_api/tests/test_views.py b/openedx/core/djangoapps/user_api/tests/test_views.py index 05cc1d7854..b317c4e5e0 100644 --- a/openedx/core/djangoapps/user_api/tests/test_views.py +++ b/openedx/core/djangoapps/user_api/tests/test_views.py @@ -93,8 +93,9 @@ class UserAPITestCase(ApiTestCase): def assertUserIsValid(self, user): """Assert that the given user result is valid""" - self.assertItemsEqual(list(user.keys()), ["email", "id", "name", "username", "preferences", "url"]) - self.assertItemsEqual( + six.assertCountEqual(self, list(user.keys()), ["email", "id", "name", "username", "preferences", "url"]) + six.assertCountEqual( + self, list(user["preferences"].items()), [(pref.key, pref.value) for pref in self.prefs if pref.user.id == user["id"]] ) @@ -104,7 +105,7 @@ class UserAPITestCase(ApiTestCase): """ Assert that the given preference is acknowledged by the system """ - self.assertItemsEqual(list(pref.keys()), ["user", "key", "value", "url"]) + six.assertCountEqual(self, list(pref.keys()), ["user", "key", "value", "url"]) self.assertSelfReferential(pref) self.assertUserIsValid(pref["user"]) diff --git a/openedx/core/lib/api/test_utils.py b/openedx/core/lib/api/test_utils.py index 70e8ebaad4..789a58035f 100644 --- a/openedx/core/lib/api/test_utils.py +++ b/openedx/core/lib/api/test_utils.py @@ -5,6 +5,7 @@ from __future__ import absolute_import import base64 import json import re +import six from django.test import TestCase from django.test.utils import override_settings @@ -49,7 +50,7 @@ class ApiTestCase(TestCase): allow_header = resp.get("Allow") self.assertIsNotNone(allow_header) allowed_methods = re.split('[^A-Z]+', allow_header) - self.assertItemsEqual(allowed_methods, expected_methods) + six.assertCountEqual(self, allowed_methods, expected_methods) def assertSelfReferential(self, obj): """Assert that accessing the "url" entry in the given object returns the same object""" diff --git a/openedx/features/course_duration_limits/tests/test_course_expiration.py b/openedx/features/course_duration_limits/tests/test_course_expiration.py index 07c06c23f7..153e98e389 100644 --- a/openedx/features/course_duration_limits/tests/test_course_expiration.py +++ b/openedx/features/course_duration_limits/tests/test_course_expiration.py @@ -216,7 +216,7 @@ class CourseExpirationTestCase(ModuleStoreTestCase): course_home_url = reverse('openedx.course_experience.course_home', args=[six.text_type(self.course.id)]) response = self.client.get(course_home_url, follow=True) self.assertEqual(response.status_code, 200) - self.assertItemsEqual(response.redirect_chain, []) + six.assertCountEqual(self, response.redirect_chain, []) banner_text = 'You lose all access to this course, including your progress,' if show_expiration_banner: self.assertIn(banner_text, response.content) @@ -281,7 +281,7 @@ class CourseExpirationTestCase(ModuleStoreTestCase): course_home_url = reverse('openedx.course_experience.course_home', args=[six.text_type(self.course.id)]) response = self.client.get(course_home_url, follow=True) self.assertEqual(response.status_code, 200) - self.assertItemsEqual(response.redirect_chain, []) + six.assertCountEqual(self, response.redirect_chain, []) banner_text = 'You lose all access to this course, including your progress,' self.assertNotIn(banner_text, response.content) @@ -317,7 +317,7 @@ class CourseExpirationTestCase(ModuleStoreTestCase): course_home_url = reverse('openedx.course_experience.course_home', args=[six.text_type(self.course.id)]) response = self.client.get(course_home_url, follow=True) self.assertEqual(response.status_code, 200) - self.assertItemsEqual(response.redirect_chain, []) + six.assertCountEqual(self, response.redirect_chain, []) banner_text = 'This learner does not have access to this course. Their access expired on' self.assertIn(banner_text, response.content) @@ -368,7 +368,7 @@ class CourseExpirationTestCase(ModuleStoreTestCase): course_home_url = reverse('openedx.course_experience.course_home', args=[six.text_type(self.course.id)]) response = self.client.get(course_home_url, follow=True) self.assertEqual(response.status_code, 200) - self.assertItemsEqual(response.redirect_chain, []) + six.assertCountEqual(self, response.redirect_chain, []) banner_text = 'This learner does not have access to this course. Their access expired on' self.assertNotIn(banner_text, response.content) @@ -417,6 +417,6 @@ class CourseExpirationTestCase(ModuleStoreTestCase): course_home_url = reverse('openedx.course_experience.course_home', args=[six.text_type(self.course.id)]) response = self.client.get(course_home_url, follow=True) self.assertEqual(response.status_code, 200) - self.assertItemsEqual(response.redirect_chain, []) + six.assertCountEqual(self, response.redirect_chain, []) banner_text = 'This learner does not have access to this course. Their access expired on' self.assertNotIn(banner_text, response.content) diff --git a/pavelib/paver_tests/test_assets.py b/pavelib/paver_tests/test_assets.py index bff9a83969..fc89499a66 100644 --- a/pavelib/paver_tests/test_assets.py +++ b/pavelib/paver_tests/test_assets.py @@ -7,6 +7,7 @@ from unittest import TestCase import ddt import paver.tasks +import six from mock import patch from paver.easy import call_task, path from watchdog.observers import Observer @@ -78,7 +79,7 @@ class TestPaverAssetTasks(PaverTestCase): u'rtlcss cms/static/css/bootstrap/studio-main.css cms/static/css/bootstrap/studio-main-rtl.css' ) - self.assertItemsEqual(self.task_messages, expected_messages) + six.assertCountEqual(self, self.task_messages, expected_messages) @ddt.ddt @@ -195,7 +196,7 @@ class TestPaverThemeAssetTasks(PaverTestCase): u'rtlcss cms/static/css/bootstrap/studio-main.css cms/static/css/bootstrap/studio-main-rtl.css' ) - self.assertItemsEqual(self.task_messages, expected_messages) + six.assertCountEqual(self, self.task_messages, expected_messages) class TestPaverWatchAssetTasks(TestCase): @@ -245,7 +246,7 @@ class TestPaverWatchAssetTasks(TestCase): self.assertIsInstance(sass_watcher_args[0], Observer) self.assertIsInstance(sass_watcher_args[1], list) - self.assertItemsEqual(sass_watcher_args[1], self.expected_sass_directories) + six.assertCountEqual(self, sass_watcher_args[1], self.expected_sass_directories) def test_watch_theme_assets(self): """ @@ -275,7 +276,7 @@ class TestPaverWatchAssetTasks(TestCase): sass_watcher_args = mock_register.call_args_list[0][0] self.assertIsInstance(sass_watcher_args[0], Observer) self.assertIsInstance(sass_watcher_args[1], list) - self.assertItemsEqual(sass_watcher_args[1], self.expected_sass_directories) + six.assertCountEqual(self, sass_watcher_args[1], self.expected_sass_directories) @ddt.ddt