Commit 0359b5d3 by Michael Terry Committed by Michael Terry

Allow UUID to be optional for seats

If the Publisher endpoint is only making seats, don't require a UUID for
the course.

ENT-890
parent 57432017
......@@ -339,6 +339,9 @@ class EntitlementProductHelper(object):
def save(partner, course, uuid, product):
attrs = _flatten(product['attribute_values'])
if not uuid:
raise Exception(_(u"You need to provide a course UUID to create Course Entitlements."))
# Extract arguments required for Seat creation, deserializing as necessary.
certificate_type = attrs.get('certificate_type')
price = Decimal(product['price'])
......@@ -398,7 +401,7 @@ class AtomicPublicationSerializer(serializers.Serializer): # pylint: disable=ab
The automatically applied validation logic rejects course IDs which already exist in the database.
"""
id = serializers.RegexField(COURSE_ID_REGEX, max_length=255)
uuid = serializers.UUIDField()
uuid = serializers.UUIDField(required=False)
name = serializers.CharField(max_length=255)
# Verification deadline should only be required if the course actually requires verification.
verification_deadline = serializers.DateTimeField(required=False, allow_null=True)
......@@ -441,7 +444,7 @@ class AtomicPublicationSerializer(serializers.Serializer): # pylint: disable=ab
if one was raised (else None), and a message for the user, if necessary (else None).
"""
course_id = self.validated_data['id']
course_uuid = self.validated_data['uuid']
course_uuid = self.validated_data.get('uuid')
course_name = self.validated_data['name']
course_verification_deadline = self.validated_data.get('verification_deadline')
create_or_activate_enrollment_code = self.validated_data.get('create_or_activate_enrollment_code')
......
......@@ -351,15 +351,29 @@ class AtomicPublicationTests(DiscoveryTestMixin, TestCase):
self.data.pop('uuid')
response = self.client.post(self.create_path, json.dumps(self.data), JSON_CONTENT_TYPE)
self.assertEqual(response.status_code, 400)
self.assertEqual(response.status_code, 500)
self.assertEqual(
response.data.get('error'),
u'You need to provide a course UUID to create Course Entitlements.'
)
self.assert_course_does_not_exist(self.course_id)
def test_missing_course_uuid_without_entitlements(self):
"""Verify that attempting to save a course without a UUID but no entitlements is fine."""
self.data.pop('uuid')
self.data['products'] = [x for x in self.data['products'] if x['product_class'] == SEAT_PRODUCT_CLASS_NAME]
self._post_create_request()
def test_invalid_course_uuid(self):
"""Verify that attempting to save a course with a bad UUID yields a 400."""
self.data['uuid'] = 'foo-bar'
response = self.client.post(self.create_path, json.dumps(self.data), JSON_CONTENT_TYPE)
self.assertEqual(response.status_code, 400)
self.assertEqual(
response.data.get('uuid')[0],
u'"foo-bar" is not a valid UUID.'
)
self.assert_course_does_not_exist(self.course_id)
def test_invalid_product_class(self):
......
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