From 8c920b469c28c1a8962676038b8a9f755f709ca6 Mon Sep 17 00:00:00 2001 From: Jonathan Piacenti Date: Wed, 11 Mar 2015 15:11:06 +0000 Subject: [PATCH] Replace broken logic in import template with working logic in view. --- .../contentstore/views/import_export.py | 1 + cms/templates/import.html | 4 --- .../acceptance/pages/studio/import_export.py | 21 ++++++++--- .../tests/studio/test_import_export.py | 36 +++++++++++++++++++ 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/cms/djangoapps/contentstore/views/import_export.py b/cms/djangoapps/contentstore/views/import_export.py index 1bb08eb26c..e652dbb82a 100644 --- a/cms/djangoapps/contentstore/views/import_export.py +++ b/cms/djangoapps/contentstore/views/import_export.py @@ -304,6 +304,7 @@ def _import_handler(request, courselike_key, root_name, successful_url, context_ context_name: courselike_module, 'successful_import_redirect_url': successful_url, 'import_status_url': status_url, + 'library': isinstance(courselike_key, LibraryLocator) }) else: return HttpResponseNotFound() diff --git a/cms/templates/import.html b/cms/templates/import.html index d1d7bd310d..4d445948e5 100644 --- a/cms/templates/import.html +++ b/cms/templates/import.html @@ -4,10 +4,6 @@ <%! from django.utils.translation import ugettext as _ import json - try: - library = True - except NameError: - library = False %> <%block name="title"> %if library: diff --git a/common/test/acceptance/pages/studio/import_export.py b/common/test/acceptance/pages/studio/import_export.py index c9a514b481..27bee884ea 100644 --- a/common/test/acceptance/pages/studio/import_export.py +++ b/common/test/acceptance/pages/studio/import_export.py @@ -10,6 +10,19 @@ from .course_page import CoursePage from . import BASE_URL +class TemplateCheckMixin(object): + """ + Mixin for verifying that a template is loading the correct text. + """ + @property + def header_text(self): + """ + Get the header text of the page. + """ + # There are prefixes like 'Tools' and '>', but the text itself is not in a span. + return self.q(css='h1.page-header')[0].text.split('\n')[-1] + + class ExportMixin(object): """ Export page Mixin. @@ -86,13 +99,13 @@ class LibraryLoader(object): return "/".join([BASE_URL, self.url_path, unicode(self.locator)]) -class ExportCoursePage(ExportMixin, CoursePage): +class ExportCoursePage(ExportMixin, TemplateCheckMixin, CoursePage): """ Export page for Courses """ -class ExportLibraryPage(ExportMixin, LibraryLoader, LibraryPage): +class ExportLibraryPage(ExportMixin, TemplateCheckMixin, LibraryLoader, LibraryPage): """ Export page for Libraries """ @@ -226,13 +239,13 @@ class ImportMixin(object): return self.q(css='.action.action-primary')[0].get_attribute('href') -class ImportCoursePage(ImportMixin, CoursePage): +class ImportCoursePage(ImportMixin, TemplateCheckMixin, CoursePage): """ Import page for Courses """ -class ImportLibraryPage(ImportMixin, LibraryLoader, LibraryPage): +class ImportLibraryPage(ImportMixin, TemplateCheckMixin, LibraryLoader, LibraryPage): """ Import page for Libraries """ diff --git a/common/test/acceptance/tests/studio/test_import_export.py b/common/test/acceptance/tests/studio/test_import_export.py index 52412233f3..8e4dadf511 100644 --- a/common/test/acceptance/tests/studio/test_import_export.py +++ b/common/test/acceptance/tests/studio/test_import_export.py @@ -41,6 +41,15 @@ class TestCourseExport(ExportTestMixin, StudioCourseTest): ) self.export_page.visit() + def test_header(self): + """ + Scenario: I should see the correct text when exporting a course. + Given that I have a course to export from + When I visit the export page + The correct header should be shown + """ + self.assertEqual(self.export_page.header_text, 'Course Export') + class TestLibraryExport(ExportTestMixin, StudioLibraryTest): """ @@ -54,6 +63,15 @@ class TestLibraryExport(ExportTestMixin, StudioLibraryTest): self.export_page = ExportLibraryPage(self.browser, self.library_key) self.export_page.visit() + def test_header(self): + """ + Scenario: I should see the correct text when exporting a library. + Given that I have a library to export from + When I visit the export page + The correct header should be shown + """ + self.assertEqual(self.export_page.header_text, 'Library Export') + # pylint: disable=no-member class BadExportMixin(object): @@ -243,6 +261,15 @@ class TestCourseImport(ImportTestMixin, StudioCourseTest): # There's a section named 'Section' in the tarball. self.landing_page.section("Section") + def test_header(self): + """ + Scenario: I should see the correct text when importing a course. + Given that I have a course to import to + When I visit the import page + The correct header should be shown + """ + self.assertEqual(self.import_page.header_text, 'Course Import') + class TestLibraryImport(ImportTestMixin, StudioLibraryTest): """ @@ -276,3 +303,12 @@ class TestLibraryImport(ImportTestMixin, StudioLibraryTest): self.landing_page.wait_until_ready() # There are three blocks in the tarball. self.assertEqual(len(self.landing_page.xblocks), 3) + + def test_header(self): + """ + Scenario: I should see the correct text when importing a library. + Given that I have a library to import to + When I visit the import page + The correct header should be shown + """ + self.assertEqual(self.import_page.header_text, 'Library Import')