assertItemsEqual() moved to assertCountEqual()

This commit is contained in:
Dave St.Germain
2019-08-19 17:00:17 -04:00
parent 3bb7d0f61a
commit 3d2617983b
44 changed files with 132 additions and 111 deletions

View File

@@ -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(expected_programs, get_programs_by_type(self.site, 'masters'))
def test_get_bachelors_programs(self):
expected_programs = [self.bachelors_program]

View File

@@ -422,7 +422,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(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 +445,7 @@ class TestModuleStoreSerializer(TestDumpToNeo4jCommandBase):
number_rollbacks=2,
)
self.assertItemsEqual(submitted, self.course_strings)
six.assertCountEqual(submitted, self.course_strings)
@mock.patch('openedx.core.djangoapps.coursegraph.tasks.NodeSelector')
@mock.patch('openedx.core.djangoapps.coursegraph.tasks.authenticate_and_create_graph')

View File

@@ -363,7 +363,7 @@ 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(
[(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]
)
@@ -1680,4 +1680,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(results, expected_results)

View File

@@ -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(accept_lang_result, accept_lang_out)
else:
self.assertEqual(accept_lang_result, accept_lang_out)

View File

@@ -674,7 +674,7 @@ class TestProgramProgressMeter(TestCase):
self._create_certificates(unknown['key'], status='unknown')
meter = ProgramProgressMeter(self.site, self.user)
self.assertItemsEqual(
six.assertCountEqual(
meter.completed_course_runs,
[
{'course_run_id': downloadable['key'], 'type': CourseMode.VERIFIED},

View File

@@ -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,7 @@ 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(
message.context['course_ids'],
[str(schedules[i].enrollment.course.id) for i in (1, 2, 4)]
)

View File

@@ -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,7 @@ 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(
configuration_helpers.get_dict("REGISTRATION_EXTRA_FIELDS"),
test_config['REGISTRATION_EXTRA_FIELDS'],
)
@@ -91,7 +92,7 @@ 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(
configuration_helpers.get_dict("REGISTRATION_EXTRA_FIELDS", default),
expected,
)
@@ -134,7 +135,7 @@ class TestHelpers(TestCase):
test_config['css_overrides_file']
)
self.assertItemsEqual(
six.assertCountEqual(
configuration_helpers.get_value_for_org(test_org, "REGISTRATION_EXTRA_FIELDS"),
test_config['REGISTRATION_EXTRA_FIELDS']
)
@@ -177,7 +178,7 @@ class TestHelpers(TestCase):
"""
test_orgs = [test_config['course_org_filter']]
with with_site_configuration_context(configuration=test_config):
self.assertItemsEqual(
six.assertCountEqual(
list(configuration_helpers.get_all_orgs()),
test_orgs,
)
@@ -185,7 +186,7 @@ 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(
list(configuration_helpers.get_current_site_orgs()),
test_orgs
)

View File

@@ -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,12 @@ 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(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(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(parsed_args[2], [theme for theme in get_themes() if theme.theme_dir_name == "test-theme"])

View File

@@ -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(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(expected_themes, actual_themes)
def test_get_value_returns_override(self):
"""

View File

@@ -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
@@ -565,7 +566,7 @@ class TestPartnerReportingList(ModuleStoreTestCase):
for returned_user in returned_users:
returned_user['orgs'].sort()
self.assertCountEqual(returned_users, expected_users)
six.assertCountEqual(returned_users, expected_users)
def test_success(self):
"""
@@ -661,7 +662,7 @@ class TestAccountRetirementList(RetirementTestCase):
del retirement['created']
del retirement['modified']
self.assertItemsEqual(response_data, expected_data)
six.assertCountEqual(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(response_data, expected_data)
def test_empty(self):
"""

View File

@@ -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(response.data["language_proficiencies"], proficiencies)
@ddt.data(
(

View File

@@ -19,7 +19,7 @@ from django.test.utils import override_settings
from django.urls import reverse
from opaque_keys.edx.keys import CourseKey
from pytz import UTC, common_timezones_set
from six import text_type
from six import text_type, assertCountEqual
from six.moves import range
from social_django.models import Partial, UserSocialAuth
@@ -93,8 +93,8 @@ 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(
assertCountEqual(list(user.keys()), ["email", "id", "name", "username", "preferences", "url"])
assertCountEqual(
list(user["preferences"].items()),
[(pref.key, pref.value) for pref in self.prefs if pref.user.id == user["id"]]
)
@@ -104,7 +104,7 @@ class UserAPITestCase(ApiTestCase):
"""
Assert that the given preference is acknowledged by the system
"""
self.assertItemsEqual(list(pref.keys()), ["user", "key", "value", "url"])
assertCountEqual(list(pref.keys()), ["user", "key", "value", "url"])
self.assertSelfReferential(pref)
self.assertUserIsValid(pref["user"])

View File

@@ -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(allowed_methods, expected_methods)
def assertSelfReferential(self, obj):
"""Assert that accessing the "url" entry in the given object returns the same object"""

View File

@@ -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(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, [])
self.six.assertCountEqual(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, [])
self.six.assertCountEqual(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, [])
self.six.assertCountEqual(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, [])
self.six.assertCountEqual(response.redirect_chain, [])
banner_text = 'This learner does not have access to this course. Their access expired on'
self.assertNotIn(banner_text, response.content)