fix: replace deprecated assertDictContainsSubset()
This commit is contained in:
@@ -27,6 +27,7 @@ from openedx.core.djangoapps.xblock import api as xblock_api
|
||||
from openedx.core.djangolib.testing.utils import skip_unless_lms, skip_unless_cms
|
||||
from openedx.core.lib.xblock_serializer import api as serializer_api
|
||||
from common.djangoapps.student.tests.factories import UserFactory
|
||||
from common.test.utils import assert_dict_contains_subset
|
||||
|
||||
|
||||
class ContentLibraryContentTestMixin:
|
||||
@@ -205,10 +206,14 @@ class ContentLibraryRuntimeTests(ContentLibraryContentTestMixin, TestCase):
|
||||
assert metadata_view_result.data['display_name'] == 'New Multi Choice Question'
|
||||
assert 'children' not in metadata_view_result.data
|
||||
assert 'editable_children' not in metadata_view_result.data
|
||||
self.assertDictContainsSubset({
|
||||
"content_type": "CAPA",
|
||||
"problem_types": ["multiplechoiceresponse"],
|
||||
}, metadata_view_result.data["index_dictionary"])
|
||||
assert_dict_contains_subset(
|
||||
self,
|
||||
{
|
||||
"content_type": "CAPA",
|
||||
"problem_types": ["multiplechoiceresponse"],
|
||||
},
|
||||
metadata_view_result.data["index_dictionary"],
|
||||
)
|
||||
assert metadata_view_result.data['student_view_data'] is None
|
||||
# Capa doesn't provide student_view_data
|
||||
|
||||
@@ -493,11 +498,15 @@ class ContentLibraryXBlockUserStateTest(ContentLibraryContentTestMixin, TestCase
|
||||
submit_result = client.post(problem_check_url, data={problem_key: "choice_3"})
|
||||
assert submit_result.status_code == 200
|
||||
submit_data = json.loads(submit_result.content.decode('utf-8'))
|
||||
self.assertDictContainsSubset({
|
||||
"current_score": 0,
|
||||
"total_possible": 1,
|
||||
"attempts_used": 1,
|
||||
}, submit_data)
|
||||
assert_dict_contains_subset(
|
||||
self,
|
||||
{
|
||||
"current_score": 0,
|
||||
"total_possible": 1,
|
||||
"attempts_used": 1,
|
||||
},
|
||||
submit_data,
|
||||
)
|
||||
|
||||
# Now test that the score is also persisted in StudentModule:
|
||||
# If we add a REST API to get an individual block's score, that should be checked instead of StudentModule.
|
||||
@@ -509,11 +518,15 @@ class ContentLibraryXBlockUserStateTest(ContentLibraryContentTestMixin, TestCase
|
||||
submit_result = client.post(problem_check_url, data={problem_key: "choice_1"})
|
||||
assert submit_result.status_code == 200
|
||||
submit_data = json.loads(submit_result.content.decode('utf-8'))
|
||||
self.assertDictContainsSubset({
|
||||
"current_score": 1,
|
||||
"total_possible": 1,
|
||||
"attempts_used": 2,
|
||||
}, submit_data)
|
||||
assert_dict_contains_subset(
|
||||
self,
|
||||
{
|
||||
"current_score": 1,
|
||||
"total_possible": 1,
|
||||
"attempts_used": 2,
|
||||
},
|
||||
submit_data,
|
||||
)
|
||||
# Now test that the score is also updated in StudentModule:
|
||||
# If we add a REST API to get an individual block's score, that should be checked instead of StudentModule.
|
||||
sm = get_score(self.student_a, block_id)
|
||||
|
||||
@@ -18,6 +18,7 @@ from openedx.core.djangolib.testing.utils import skip_unless_lms
|
||||
from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory
|
||||
|
||||
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order
|
||||
from common.test.utils import assert_dict_contains_subset
|
||||
|
||||
|
||||
@skip_unless_lms
|
||||
@@ -90,25 +91,26 @@ class CohortEventTest(SharedModuleStoreTestCase, OpenEdxEventsTestMixin):
|
||||
)
|
||||
|
||||
self.assertTrue(self.receiver_called)
|
||||
self.assertDictContainsSubset(
|
||||
assert_dict_contains_subset(
|
||||
self,
|
||||
{
|
||||
"signal": COHORT_MEMBERSHIP_CHANGED,
|
||||
"sender": None,
|
||||
"cohort": CohortData(
|
||||
user=UserData(
|
||||
pii=UserPersonalData(
|
||||
username=cohort_membership.user.username,
|
||||
email=cohort_membership.user.email,
|
||||
name=cohort_membership.user.profile.name,
|
||||
),
|
||||
id=cohort_membership.user.id,
|
||||
is_active=cohort_membership.user.is_active,
|
||||
),
|
||||
course=CourseData(
|
||||
course_key=cohort_membership.course_id,
|
||||
),
|
||||
name=cohort_membership.course_user_group.name,
|
||||
),
|
||||
user=UserData(
|
||||
pii=UserPersonalData(
|
||||
username=cohort_membership.user.username,
|
||||
email=cohort_membership.user.email,
|
||||
name=cohort_membership.user.profile.name,
|
||||
),
|
||||
id=cohort_membership.user.id,
|
||||
is_active=cohort_membership.user.is_active,
|
||||
),
|
||||
course=CourseData(
|
||||
course_key=cohort_membership.course_id,
|
||||
),
|
||||
name=cohort_membership.course_user_group.name,
|
||||
),
|
||||
},
|
||||
event_receiver.call_args.kwargs
|
||||
event_receiver.call_args.kwargs,
|
||||
)
|
||||
|
||||
@@ -11,6 +11,7 @@ from edx_rest_framework_extensions.auth.jwt.decoder import (
|
||||
from jwt.exceptions import ExpiredSignatureError
|
||||
|
||||
from common.djangoapps.student.models import UserProfile, anonymous_id_for_user
|
||||
from common.test.utils import assert_dict_contains_subset
|
||||
|
||||
|
||||
class AccessTokenMixin:
|
||||
@@ -88,7 +89,7 @@ class AccessTokenMixin:
|
||||
|
||||
expected['grant_type'] = grant_type or ''
|
||||
|
||||
self.assertDictContainsSubset(expected, payload)
|
||||
assert_dict_contains_subset(self, expected, payload)
|
||||
|
||||
if expires_in:
|
||||
assert payload['exp'] == payload['iat'] + expires_in
|
||||
|
||||
@@ -9,6 +9,7 @@ from django.test import TestCase
|
||||
from oauth2_provider.models import AccessToken
|
||||
|
||||
from common.djangoapps.student.tests.factories import UserFactory
|
||||
from common.test.utils import assert_dict_contains_subset
|
||||
|
||||
OAUTH_PROVIDER_ENABLED = settings.FEATURES.get('ENABLE_OAUTH2_PROVIDER')
|
||||
if OAUTH_PROVIDER_ENABLED:
|
||||
@@ -43,7 +44,8 @@ class TestOAuthDispatchAPI(TestCase):
|
||||
token = api.create_dot_access_token(HttpRequest(), self.user, self.client)
|
||||
assert token['access_token']
|
||||
assert token['refresh_token']
|
||||
self.assertDictContainsSubset(
|
||||
assert_dict_contains_subset(
|
||||
self,
|
||||
{
|
||||
'token_type': 'Bearer',
|
||||
'expires_in': EXPECTED_DEFAULT_EXPIRES_IN,
|
||||
@@ -63,5 +65,5 @@ class TestOAuthDispatchAPI(TestCase):
|
||||
token = api.create_dot_access_token(
|
||||
HttpRequest(), self.user, self.client, expires_in=expires_in, scopes=['profile'],
|
||||
)
|
||||
self.assertDictContainsSubset({'scope': 'profile'}, token)
|
||||
self.assertDictContainsSubset({'expires_in': expires_in}, token)
|
||||
assert_dict_contains_subset(self, {'scope': 'profile'}, token)
|
||||
assert_dict_contains_subset(self, {'expires_in': expires_in}, token)
|
||||
|
||||
@@ -12,6 +12,7 @@ from openedx.core.djangoapps.oauth_dispatch.adapters import DOTAdapter
|
||||
from openedx.core.djangoapps.oauth_dispatch.models import RestrictedApplication
|
||||
from openedx.core.djangoapps.oauth_dispatch.tests.mixins import AccessTokenMixin
|
||||
from common.djangoapps.student.tests.factories import UserFactory
|
||||
from common.test.utils import assert_dict_contains_subset
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
@@ -171,7 +172,7 @@ class TestCreateJWTs(AccessTokenMixin, TestCase):
|
||||
token_payload = self.assert_valid_jwt_access_token(
|
||||
jwt_token, self.user, self.default_scopes, aud=aud, secret=secret,
|
||||
)
|
||||
self.assertDictContainsSubset(additional_claims, token_payload)
|
||||
assert_dict_contains_subset(self, additional_claims, token_payload)
|
||||
assert user_email_verified == token_payload['email_verified']
|
||||
assert token_payload['roles'] == mock_create_roles.return_value
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ from openedx.core.djangoapps.django_comment_common.models import (
|
||||
)
|
||||
from openedx.core.djangoapps.django_comment_common.utils import seed_permissions_roles
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order
|
||||
from common.test.utils import assert_dict_contains_subset
|
||||
|
||||
|
||||
class AutoAuthTestCase(UrlResetMixin, TestCase):
|
||||
@@ -182,12 +183,13 @@ class AutoAuthEnabledTestCase(AutoAuthTestCase, ModuleStoreTestCase):
|
||||
for key in ['created_status', 'username', 'email', 'password', 'user_id', 'anonymous_id']:
|
||||
assert key in response_data
|
||||
user = User.objects.get(username=response_data['username'])
|
||||
self.assertDictContainsSubset(
|
||||
assert_dict_contains_subset(
|
||||
self,
|
||||
{
|
||||
'created_status': 'Logged in',
|
||||
'anonymous_id': anonymous_id_for_user(user, None),
|
||||
},
|
||||
response_data
|
||||
response_data,
|
||||
)
|
||||
|
||||
@ddt.data(*COURSE_IDS_DDT)
|
||||
|
||||
@@ -18,6 +18,7 @@ from openedx_events.tests.utils import OpenEdxEventsTestMixin
|
||||
from common.djangoapps.student.tests.factories import UserFactory, UserProfileFactory
|
||||
from openedx.core.djangoapps.user_api.tests.test_views import UserAPITestCase
|
||||
from openedx.core.djangolib.testing.utils import skip_unless_lms
|
||||
from common.test.utils import assert_dict_contains_subset
|
||||
|
||||
|
||||
@skip_unless_lms
|
||||
@@ -83,21 +84,22 @@ class RegistrationEventTest(UserAPITestCase, OpenEdxEventsTestMixin):
|
||||
|
||||
user = User.objects.get(username=self.user_info.get("username"))
|
||||
self.assertTrue(self.receiver_called)
|
||||
self.assertDictContainsSubset(
|
||||
assert_dict_contains_subset(
|
||||
self,
|
||||
{
|
||||
"signal": STUDENT_REGISTRATION_COMPLETED,
|
||||
"sender": None,
|
||||
"user": UserData(
|
||||
pii=UserPersonalData(
|
||||
username=user.username,
|
||||
email=user.email,
|
||||
name=user.profile.name,
|
||||
),
|
||||
id=user.id,
|
||||
is_active=user.is_active,
|
||||
),
|
||||
pii=UserPersonalData(
|
||||
username=user.username,
|
||||
email=user.email,
|
||||
name=user.profile.name,
|
||||
),
|
||||
id=user.id,
|
||||
is_active=user.is_active,
|
||||
),
|
||||
},
|
||||
event_receiver.call_args.kwargs
|
||||
event_receiver.call_args.kwargs,
|
||||
)
|
||||
|
||||
|
||||
@@ -165,19 +167,20 @@ class LoginSessionEventTest(UserAPITestCase, OpenEdxEventsTestMixin):
|
||||
|
||||
user = User.objects.get(username=self.user.username)
|
||||
self.assertTrue(self.receiver_called)
|
||||
self.assertDictContainsSubset(
|
||||
assert_dict_contains_subset(
|
||||
self,
|
||||
{
|
||||
"signal": SESSION_LOGIN_COMPLETED,
|
||||
"sender": None,
|
||||
"user": UserData(
|
||||
pii=UserPersonalData(
|
||||
username=user.username,
|
||||
email=user.email,
|
||||
name=user.profile.name,
|
||||
),
|
||||
id=user.id,
|
||||
is_active=user.is_active,
|
||||
),
|
||||
pii=UserPersonalData(
|
||||
username=user.username,
|
||||
email=user.email,
|
||||
name=user.profile.name,
|
||||
),
|
||||
id=user.id,
|
||||
is_active=user.is_active,
|
||||
),
|
||||
},
|
||||
event_receiver.call_args.kwargs
|
||||
event_receiver.call_args.kwargs,
|
||||
)
|
||||
|
||||
@@ -44,6 +44,7 @@ from openedx.core.lib.api.test_utils import ApiTestCase
|
||||
from openedx.features.enterprise_support.tests.factories import EnterpriseCustomerUserFactory
|
||||
from common.djangoapps.student.models import LoginFailures
|
||||
from common.djangoapps.util.password_policy_validators import DEFAULT_MAX_PASSWORD_LENGTH
|
||||
from common.test.utils import assert_dict_contains_subset
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
@@ -544,7 +545,7 @@ class LoginTest(SiteMixin, CacheIsolationTestCase, OpenEdxEventsTestMixin):
|
||||
expected = {
|
||||
'target': '/',
|
||||
}
|
||||
self.assertDictContainsSubset(expected, response.context_data)
|
||||
assert_dict_contains_subset(self, expected, response.context_data)
|
||||
|
||||
@patch.dict("django.conf.settings.FEATURES", {'SQUELCH_PII_IN_LOGS': True})
|
||||
def test_logout_logging_no_pii(self):
|
||||
|
||||
@@ -14,6 +14,7 @@ from django.urls import reverse
|
||||
from openedx.core.djangoapps.oauth_dispatch.tests.factories import ApplicationFactory
|
||||
from openedx.core.djangolib.testing.utils import skip_unless_lms
|
||||
from common.djangoapps.student.tests.factories import UserFactory
|
||||
from common.test.utils import assert_dict_contains_subset
|
||||
|
||||
|
||||
@skip_unless_lms
|
||||
@@ -76,14 +77,14 @@ class LogoutTests(TestCase):
|
||||
expected = {
|
||||
'target': urllib.parse.unquote(redirect_url),
|
||||
}
|
||||
self.assertDictContainsSubset(expected, response.context_data)
|
||||
assert_dict_contains_subset(self, expected, response.context_data)
|
||||
|
||||
def test_no_redirect_supplied(self):
|
||||
response = self.client.get(reverse('logout'), HTTP_HOST='testserver')
|
||||
expected = {
|
||||
'target': '/',
|
||||
}
|
||||
self.assertDictContainsSubset(expected, response.context_data)
|
||||
assert_dict_contains_subset(self, expected, response.context_data)
|
||||
|
||||
@ddt.data(
|
||||
('https://www.amazon.org', 'edx.org'),
|
||||
@@ -100,7 +101,7 @@ class LogoutTests(TestCase):
|
||||
expected = {
|
||||
'target': '/',
|
||||
}
|
||||
self.assertDictContainsSubset(expected, response.context_data)
|
||||
assert_dict_contains_subset(self, expected, response.context_data)
|
||||
|
||||
def test_client_logout(self):
|
||||
""" Verify the context includes a list of the logout URIs of the authenticated OpenID Connect clients.
|
||||
@@ -113,7 +114,7 @@ class LogoutTests(TestCase):
|
||||
'logout_uris': [],
|
||||
'target': '/',
|
||||
}
|
||||
self.assertDictContainsSubset(expected, response.context_data)
|
||||
assert_dict_contains_subset(self, expected, response.context_data)
|
||||
|
||||
@mock.patch(
|
||||
'django.conf.settings.IDA_LOGOUT_URI_LIST',
|
||||
@@ -138,7 +139,7 @@ class LogoutTests(TestCase):
|
||||
'logout_uris': expected_logout_uris,
|
||||
'target': '/',
|
||||
}
|
||||
self.assertDictContainsSubset(expected, response.context_data)
|
||||
assert_dict_contains_subset(self, expected, response.context_data)
|
||||
|
||||
@mock.patch(
|
||||
'django.conf.settings.IDA_LOGOUT_URI_LIST',
|
||||
@@ -161,7 +162,7 @@ class LogoutTests(TestCase):
|
||||
'logout_uris': expected_logout_uris,
|
||||
'target': '/',
|
||||
}
|
||||
self.assertDictContainsSubset(expected, response.context_data)
|
||||
assert_dict_contains_subset(self, expected, response.context_data)
|
||||
|
||||
def test_filter_referring_service(self):
|
||||
""" Verify that, if the user is directed to the logout page from a service, that service's logout URL
|
||||
@@ -174,7 +175,7 @@ class LogoutTests(TestCase):
|
||||
'target': '/',
|
||||
'show_tpa_logout_link': False,
|
||||
}
|
||||
self.assertDictContainsSubset(expected, response.context_data)
|
||||
assert_dict_contains_subset(self, expected, response.context_data)
|
||||
|
||||
def test_learner_portal_logout_having_idp_logout_url(self):
|
||||
"""
|
||||
@@ -194,7 +195,7 @@ class LogoutTests(TestCase):
|
||||
'tpa_logout_url': idp_logout_url,
|
||||
'show_tpa_logout_link': True,
|
||||
}
|
||||
self.assertDictContainsSubset(expected, response.context_data)
|
||||
assert_dict_contains_subset(self, expected, response.context_data)
|
||||
|
||||
@mock.patch('django.conf.settings.TPA_AUTOMATIC_LOGOUT_ENABLED', True)
|
||||
def test_automatic_tpa_logout_url_redirect(self):
|
||||
@@ -214,7 +215,7 @@ class LogoutTests(TestCase):
|
||||
expected = {
|
||||
'target': idp_logout_url,
|
||||
}
|
||||
self.assertDictContainsSubset(expected, response.context_data)
|
||||
assert_dict_contains_subset(self, expected, response.context_data)
|
||||
|
||||
@mock.patch('django.conf.settings.TPA_AUTOMATIC_LOGOUT_ENABLED', True)
|
||||
def test_no_automatic_tpa_logout_without_logout_url(self):
|
||||
@@ -241,4 +242,4 @@ class LogoutTests(TestCase):
|
||||
expected = {
|
||||
'target': nh3.clean(urllib.parse.unquote(redirect_url)),
|
||||
}
|
||||
self.assertDictContainsSubset(expected, response.context_data)
|
||||
assert_dict_contains_subset(self, expected, response.context_data)
|
||||
|
||||
Reference in New Issue
Block a user