Commit beb3e2e2 by Renzo Lucioni

Allow course name to be updated by CAT

Facilitates the modification of course names in the CAT edit view. XCOM-533.
parent 67d7d888
...@@ -189,7 +189,9 @@ class AtomicPublicationSerializer(serializers.Serializer): # pylint: disable=ab ...@@ -189,7 +189,9 @@ class AtomicPublicationSerializer(serializers.Serializer): # pylint: disable=ab
try: try:
# Explicitly delimit operations which will be rolled back if an exception is raised. # Explicitly delimit operations which will be rolled back if an exception is raised.
with transaction.atomic(): with transaction.atomic():
course, created = Course.objects.get_or_create(id=course_id, defaults={'name': course_name}) course, created = Course.objects.get_or_create(id=course_id)
course.name = course_name
course.save()
for product in products: for product in products:
attrs = self._flatten(product['attribute_values']) attrs = self._flatten(product['attribute_values'])
......
...@@ -84,9 +84,8 @@ class AtomicPublicationTests(CourseCatalogTestMixin, UserMixin, TestCase): ...@@ -84,9 +84,8 @@ class AtomicPublicationTests(CourseCatalogTestMixin, UserMixin, TestCase):
# Create a Course. # Create a Course.
course = Course.objects.create(id=self.course_id, name=self.course_name) course = Course.objects.create(id=self.course_id, name=self.course_name)
updated_data = deepcopy(self.data)
# Create associated products. # Create associated products.
for product in updated_data['products']: for product in self.data['products']:
attrs = {attr['name']: attr['value'] for attr in product['attribute_values']} attrs = {attr['name']: attr['value'] for attr in product['attribute_values']}
attrs['expires'] = EXPIRES if product['expires'] else None attrs['expires'] = EXPIRES if product['expires'] else None
...@@ -95,14 +94,21 @@ class AtomicPublicationTests(CourseCatalogTestMixin, UserMixin, TestCase): ...@@ -95,14 +94,21 @@ class AtomicPublicationTests(CourseCatalogTestMixin, UserMixin, TestCase):
course.create_or_update_seat(**attrs) course.create_or_update_seat(**attrs)
# Update the price of the verified seat. def _update_data(self):
if attrs['certificate_type'] == 'verified': updated_data = deepcopy(self.data)
product['price'] = 20.00 for product in updated_data['products']:
attrs = {attr['name']: attr['value'] for attr in product['attribute_values']}
# Strip course_id, which should be absent from PUT requests. # Update the price of the verified seat.
updated_data.pop('id') if attrs['certificate_type'] == 'verified':
product['price'] = 20.00
return updated_data updated_data['name'] = 'A New Name'
# Strip course_id, which should be absent from PUT requests.
updated_data.pop('id')
return updated_data
def _assert_course_saved(self, course_id, expected=None): def _assert_course_saved(self, course_id, expected=None):
"""Verify that the expected Course and associated products have been saved.""" """Verify that the expected Course and associated products have been saved."""
...@@ -172,14 +178,16 @@ class AtomicPublicationTests(CourseCatalogTestMixin, UserMixin, TestCase): ...@@ -172,14 +178,16 @@ class AtomicPublicationTests(CourseCatalogTestMixin, UserMixin, TestCase):
def test_update(self): def test_update(self):
"""Verify that a Course and associated products can be updated and published.""" """Verify that a Course and associated products can be updated and published."""
updated_data = self._purge_courses(recreate=True) self._purge_courses(recreate=True)
updated_data = self._update_data()
# If LMS publication is disabled, the view should return a 200 and data should be saved. # If LMS publication is disabled, the view should return a 200 and data should be saved.
response = self.client.put(self.update_path, json.dumps(updated_data), JSON_CONTENT_TYPE) response = self.client.put(self.update_path, json.dumps(updated_data), JSON_CONTENT_TYPE)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self._assert_course_saved(self.course_id, expected=updated_data) self._assert_course_saved(self.course_id, expected=updated_data)
updated_data = self._purge_courses(recreate=True) self._purge_courses(recreate=True)
updated_data = self._update_data()
self._toggle_publication(True) self._toggle_publication(True)
with mock.patch.object(LMSPublisher, 'publish') as mock_publish: with mock.patch.object(LMSPublisher, 'publish') as mock_publish:
......
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