From 95e76dcafe945b62dc7bbaebde1a32434002464a Mon Sep 17 00:00:00 2001 From: bmedx Date: Thu, 4 Jan 2018 15:14:57 -0500 Subject: [PATCH] Small fixes to LMS unit 1 failures in Django 1.11 tests --- lms/djangoapps/badges/tests/test_models.py | 8 +++++++- lms/djangoapps/courseware/tests/test_lti_integration.py | 2 +- lms/djangoapps/courseware/tests/test_module_render.py | 1 + openedx/core/djangoapps/bookmarks/models.py | 3 +++ openedx/core/djangoapps/bookmarks/tests/factories.py | 1 - 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lms/djangoapps/badges/tests/test_models.py b/lms/djangoapps/badges/tests/test_models.py index c069ed8022..5065ef9c01 100644 --- a/lms/djangoapps/badges/tests/test_models.py +++ b/lms/djangoapps/badges/tests/test_models.py @@ -2,6 +2,7 @@ Tests for the Badges app models. """ import pytest +from path import Path from django.core.exceptions import ValidationError from django.core.files.images import ImageFile from django.core.files.storage import default_storage @@ -33,10 +34,14 @@ def get_image(name): @attr(shard=1) +@override_settings(MEDIA_ROOT=TEST_DATA_ROOT) class BadgeImageConfigurationTest(TestCase): """ Test the validation features of BadgeImageConfiguration. """ + def tearDown(self): + tmp_path = Path(TEST_DATA_ROOT / 'course_complete_badges') + Path.rmtree_p(tmp_path) @pytest.mark.django111_expected_failure def test_no_double_default(self): @@ -66,6 +71,7 @@ class DummyBackend(object): award = Mock() +@override_settings(MEDIA_ROOT=TEST_DATA_ROOT) class BadgeClassTest(ModuleStoreTestCase): """ Test BadgeClass functionality @@ -157,7 +163,7 @@ class BadgeClassTest(ModuleStoreTestCase): self.assertEqual(badge_class.description, 'This is a test') self.assertEqual(badge_class.criteria, 'https://example.com/test_criteria') self.assertEqual(badge_class.display_name, 'Super Badge') - self.assertEqual(badge_class.image.name.rsplit('/', 1)[-1], 'good.png') + self.assertTrue('good' in badge_class.image.name.rsplit('/', 1)[-1]) def test_get_badge_class_nocreate(self): """ diff --git a/lms/djangoapps/courseware/tests/test_lti_integration.py b/lms/djangoapps/courseware/tests/test_lti_integration.py index fdd941d101..65e9e8ae16 100644 --- a/lms/djangoapps/courseware/tests/test_lti_integration.py +++ b/lms/djangoapps/courseware/tests/test_lti_integration.py @@ -173,7 +173,7 @@ class TestLTIModuleListing(SharedModuleStoreTestCase): def expected_handler_url(self, handler): """convenience method to get the reversed handler urls""" return "https://{}{}".format(settings.SITE_NAME, reverse( - 'courseware.module_render.handle_xblock_callback_noauth', + 'xblock_handler_noauth', args=[ self.course.id.to_deprecated_string(), quote_slashes(unicode(self.lti_published.scope_ids.usage_id.to_deprecated_string()).encode('utf-8')), diff --git a/lms/djangoapps/courseware/tests/test_module_render.py b/lms/djangoapps/courseware/tests/test_module_render.py index ad50a2c3d9..d61240d9fb 100644 --- a/lms/djangoapps/courseware/tests/test_module_render.py +++ b/lms/djangoapps/courseware/tests/test_module_render.py @@ -248,6 +248,7 @@ class ModuleRenderTestCase(SharedModuleStoreTestCase, LoginEnrollmentTestCase): ) # Verify that handle ajax is called with the correct data + request.POST._mutable = True request.POST['queuekey'] = fake_key self.mock_module.handle_ajax.assert_called_once_with(self.dispatch, request.POST) diff --git a/openedx/core/djangoapps/bookmarks/models.py b/openedx/core/djangoapps/bookmarks/models.py index de0dfaae0d..c463f23c21 100644 --- a/openedx/core/djangoapps/bookmarks/models.py +++ b/openedx/core/djangoapps/bookmarks/models.py @@ -89,6 +89,9 @@ class Bookmark(TimeStampedModel): user = data.pop('user') + # Sometimes this ends up in data, but newer versions of Django will fail on having unknown keys in defaults + data.pop('display_name', None) + bookmark, created = cls.objects.get_or_create(usage_key=usage_key, user=user, defaults=data) return bookmark, created diff --git a/openedx/core/djangoapps/bookmarks/tests/factories.py b/openedx/core/djangoapps/bookmarks/tests/factories.py index 682b6fa07d..e5027bc003 100644 --- a/openedx/core/djangoapps/bookmarks/tests/factories.py +++ b/openedx/core/djangoapps/bookmarks/tests/factories.py @@ -23,7 +23,6 @@ class BookmarkFactory(DjangoModelFactory): user = factory.SubFactory(UserFactory) course_key = COURSE_KEY usage_key = LOCATION('usage_id') - path = list() xblock_cache = factory.SubFactory( 'openedx.core.djangoapps.bookmarks.tests.factories.XBlockCacheFactory', course_key=factory.SelfAttribute('..course_key'),