Commit aefe41ef by Awais Committed by Awais Qureshi

Adding support for multi orgs courses.

ECOM-7871
parent 86c851a6
...@@ -167,12 +167,6 @@ def organizations_requirements(organizations, meta_data_course): ...@@ -167,12 +167,6 @@ def organizations_requirements(organizations, meta_data_course):
""" Before adding course make sure organization exists and has OrganizationExtension """ Before adding course make sure organization exists and has OrganizationExtension
object also. object also.
""" """
if organizations.count() > 1:
logger.warning(
'Course has more than 1 organization. Course uuid is [%s].', meta_data_course.uuid
)
return None
available_organization = organizations.first() available_organization = organizations.first()
if not available_organization: if not available_organization:
......
...@@ -89,25 +89,6 @@ class ImportCoursesTests(TestCase): ...@@ -89,25 +89,6 @@ class ImportCoursesTests(TestCase):
) )
create_or_update_course.assert_not_called() create_or_update_course.assert_not_called()
@mock.patch('course_discovery.apps.publisher.dataloader.create_courses.create_or_update_course')
def test_course_having_multiple_auth_organizations(self, create_or_update_course):
""" Verify that if the course has multiple organization then that course will not be
imported to publisher.
"""
self.course.authoring_organizations.add(OrganizationFactory())
self.course.authoring_organizations.add(OrganizationFactory())
with LogCapture(dataloader_logger.name) as log_capture:
call_command(self.command_name, *self.command_args)
log_capture.check(
(
dataloader_logger.name,
'WARNING',
'Course has more than 1 organization. Course uuid is [{}].'.format(self.course.uuid)
)
)
create_or_update_course.assert_not_called()
# pylint: disable=no-member # pylint: disable=no-member
@ddt.ddt @ddt.ddt
...@@ -164,6 +145,20 @@ class CreateCoursesTests(TestCase): ...@@ -164,6 +145,20 @@ class CreateCoursesTests(TestCase):
self._assert_course_run(course.course_runs.first(), self.course.canonical_course_run) self._assert_course_run(course.course_runs.first(), self.course.canonical_course_run)
self._assert_seats(course.course_runs.first(), self.course.canonical_course_run) self._assert_seats(course.course_runs.first(), self.course.canonical_course_run)
def test_course_having_multiple_auth_organizations(self):
""" Verify that if the course has multiple organization then that course will be
imported to publisher but with only 1 organization.
"""
# later that record will be updated with dual org manually.
org2 = OrganizationFactory()
self.course.authoring_organizations.add(org2)
call_command(self.command_name, *self.command_args)
course = Publisher_Course.objects.all().first()
self._assert_course(course)
def test_course_does_not_create_twice(self): def test_course_does_not_create_twice(self):
""" Verify that course does not create two course with same title and number. """ Verify that course does not create two course with same title and number.
Just update. Just update.
...@@ -238,6 +233,9 @@ class CreateCoursesTests(TestCase): ...@@ -238,6 +233,9 @@ class CreateCoursesTests(TestCase):
def _assert_course(self, publisher_course): def _assert_course(self, publisher_course):
""" Verify that publisher course and metadata course has correct values.""" """ Verify that publisher course and metadata course has correct values."""
# assert organization
self.assertEqual(publisher_course.organizations.first(), self.organization)
self.assertEqual(publisher_course.title, self.course.title) self.assertEqual(publisher_course.title, self.course.title)
self.assertEqual(publisher_course.number, self.course.number) self.assertEqual(publisher_course.number, self.course.number)
self.assertEqual(publisher_course.short_description, self.course.short_description) self.assertEqual(publisher_course.short_description, self.course.short_description)
......
...@@ -3217,11 +3217,30 @@ class CreateAdminImportCourseTest(TestCase): ...@@ -3217,11 +3217,30 @@ class CreateAdminImportCourseTest(TestCase):
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
def test_page_with_post(self): def test_page_with_post(self):
""" Verify post from page. """ """ Verify page shows message with successful import. """
# organization should be available for import
self.course.authoring_organizations.add(OrganizationFactory())
self._make_users_valid(True) self._make_users_valid(True)
post_data = {'start_id': self.course.pk} post_data = {'start_id': self.course.pk}
response = self.client.post(self.page_url, post_data) response = self.client.post(self.page_url, post_data)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertContains(response, 'Course Imported')
def test_page_with_invalid_course_id(self):
""" Verify page shows error message if import fails. """
self._make_users_valid(True)
post_data = {'start_id': 100}
response = self.client.post(self.page_url, post_data)
self.assertContains(response, 'Invalid Course ID')
def test_import_with_failure(self):
""" Verify page shows error in case of any error. """
self._make_users_valid(True)
post_data = {'start_id': self.course.pk}
response = self.client.post(self.page_url, post_data)
self.assertContains(response, 'Some error occurred')
def _make_users_valid(self, switch): def _make_users_valid(self, switch):
""" make user eligible for the page.""" """ make user eligible for the page."""
......
...@@ -947,10 +947,22 @@ class AdminImportCourse(mixins.LoginRequiredMixin, TemplateView): ...@@ -947,10 +947,22 @@ class AdminImportCourse(mixins.LoginRequiredMixin, TemplateView):
if form.is_valid(): if form.is_valid():
start_id = self.request.POST.get('start_id') start_id = self.request.POST.get('start_id')
for course in CourseMetaData.objects.select_related('canonical_course_run', 'level_type', 'video').filter(
id=start_id
):
try:
course = CourseMetaData.objects.select_related('canonical_course_run', 'level_type', 'video').get(
id=start_id
)
process_course(course) process_course(course)
return super(AdminImportCourse, self).get(request, args, **kwargs,) # check publisher db that course is available now.
publisher_course = Course.objects.filter(course_metadata_pk=start_id)
if publisher_course.exists():
messages.success(request, 'Course Imported')
else:
messages.error(request, 'Some error occurred. Please check authoring organizations of course.')
except CourseMetaData.DoesNotExist:
messages.error(request, 'Invalid Course ID')
return super(AdminImportCourse, self).get(request, args, **kwargs)
...@@ -7,7 +7,7 @@ msgid "" ...@@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-06-09 21:46+0500\n" "POT-Creation-Date: 2017-06-14 14:42+0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
......
...@@ -7,7 +7,7 @@ msgid "" ...@@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-06-09 21:46+0500\n" "POT-Creation-Date: 2017-06-14 14:42+0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
......
...@@ -7,7 +7,7 @@ msgid "" ...@@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-06-09 21:46+0500\n" "POT-Creation-Date: 2017-06-14 14:42+0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
......
...@@ -7,7 +7,7 @@ msgid "" ...@@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-06-09 21:46+0500\n" "POT-Creation-Date: 2017-06-14 14:42+0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
......
...@@ -6,6 +6,17 @@ ...@@ -6,6 +6,17 @@
{% endblock title %} {% endblock title %}
{% block page_content %} {% block page_content %}
<div class="alert-messages">
{% if messages %}
{% for message in messages %}
<div class="alert alert-{{ message.tags }}" role="alert" aria-labelledby="alert-title-{{ message.tags }}"
tabindex="-1">
<div>{{ message }}</div>
</div>
{% endfor %}
{% endif %}
</div>
<form method="post" action="" enctype="multipart/form-data"> <form method="post" action="" enctype="multipart/form-data">
{% csrf_token %} {% csrf_token %}
<div class="col col-6 help-text"> <div class="col col-6 help-text">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment