assertItemsEqual with six.assertCountEqual
This commit is contained in:
Ayub khan
2019-08-21 16:26:12 +05:00
parent acf3cb684d
commit 8a95a8e520
43 changed files with 167 additions and 103 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(self, expected_programs, get_programs_by_type(self.site, 'masters'))
def test_get_bachelors_programs(self):
expected_programs = [self.bachelors_program]

View File

@@ -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')

View File

@@ -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)

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

View File

@@ -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},

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,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)]
)

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,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
)

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,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"]
)

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(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):
"""

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
@@ -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):
"""

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

View File

@@ -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"])