Commit 253ed3b8 by Don Mitchell

Merge pull request #3820 from edx/dhm/bug_ok_serial_numbers

Dhm/bug ok serial numbers
parents 0631c635 ba59e3b8
...@@ -6,6 +6,7 @@ from django.core.management.base import BaseCommand, CommandError ...@@ -6,6 +6,7 @@ from django.core.management.base import BaseCommand, CommandError
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from licenses.models import CourseSoftware, UserLicense from licenses.models import CourseSoftware, UserLicense
from xmodule.modulestore.locations import SlashSeparatedCourseKey
class Command(BaseCommand): class Command(BaseCommand):
...@@ -36,10 +37,8 @@ class Command(BaseCommand): ...@@ -36,10 +37,8 @@ class Command(BaseCommand):
raise CommandError("Incorrect number of arguments") raise CommandError("Incorrect number of arguments")
course_id = args[0] course_id = args[0]
courses = modulestore().get_courses() course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id)
known_course_ids = set(c.id for c in courses) if not modulestore().has_course(course_key):
if course_id not in known_course_ids:
raise CommandError("Unknown course_id") raise CommandError("Unknown course_id")
software_name = escape(args[1].lower()) software_name = escape(args[1].lower())
...@@ -49,7 +48,7 @@ class Command(BaseCommand): ...@@ -49,7 +48,7 @@ class Command(BaseCommand):
except ValueError: except ValueError:
raise CommandError("Invalid <count> argument.") raise CommandError("Invalid <count> argument.")
return course_id, software_name, count return course_key, software_name, count
def _generate_serials(self, software, count): def _generate_serials(self, software, count):
print "Generating {0} serials".format(count) print "Generating {0} serials".format(count)
......
...@@ -6,6 +6,7 @@ from django.core.management.base import BaseCommand, CommandError ...@@ -6,6 +6,7 @@ from django.core.management.base import BaseCommand, CommandError
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from licenses.models import CourseSoftware, UserLicense from licenses.models import CourseSoftware, UserLicense
from xmodule.modulestore.locations import SlashSeparatedCourseKey
class Command(BaseCommand): class Command(BaseCommand):
...@@ -36,10 +37,8 @@ class Command(BaseCommand): ...@@ -36,10 +37,8 @@ class Command(BaseCommand):
raise CommandError("Incorrect number of arguments") raise CommandError("Incorrect number of arguments")
course_id = args[0] course_id = args[0]
courses = modulestore().get_courses() course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id)
known_course_ids = set(c.id for c in courses) if not modulestore().has_course(course_key):
if course_id not in known_course_ids:
raise CommandError("Unknown course_id") raise CommandError("Unknown course_id")
software_name = escape(args[1].lower()) software_name = escape(args[1].lower())
...@@ -48,7 +47,7 @@ class Command(BaseCommand): ...@@ -48,7 +47,7 @@ class Command(BaseCommand):
if not os.path.exists(filename): if not os.path.exists(filename):
raise CommandError("Cannot find filename {0}".format(filename)) raise CommandError("Cannot find filename {0}".format(filename))
return course_id, software_name, filename return course_key, software_name, filename
def _import_serials(self, software, filename): def _import_serials(self, software, filename):
print "Importing serial numbers for {0}.".format(software) print "Importing serial numbers for {0}.".format(software)
......
...@@ -156,12 +156,12 @@ class CommandTest(ModuleStoreTestCase): ...@@ -156,12 +156,12 @@ class CommandTest(ModuleStoreTestCase):
log.debug('Adding one set of serials for {0}'.format(SOFTWARE_1)) log.debug('Adding one set of serials for {0}'.format(SOFTWARE_1))
with generate_serials_file(size) as temp_file: with generate_serials_file(size) as temp_file:
args = [self.course_id, SOFTWARE_1, temp_file.name] args = [self.course_id.to_deprecated_string(), SOFTWARE_1, temp_file.name]
call_command('import_serial_numbers', *args) call_command('import_serial_numbers', *args)
log.debug('Adding one set of serials for {0}'.format(SOFTWARE_2)) log.debug('Adding one set of serials for {0}'.format(SOFTWARE_2))
with generate_serials_file(size) as temp_file: with generate_serials_file(size) as temp_file:
args = [self.course_id, SOFTWARE_2, temp_file.name] args = [self.course_id.to_deprecated_string(), SOFTWARE_2, temp_file.name]
call_command('import_serial_numbers', *args) call_command('import_serial_numbers', *args)
log.debug('There should be only 2 course-software entries') log.debug('There should be only 2 course-software entries')
...@@ -174,7 +174,7 @@ class CommandTest(ModuleStoreTestCase): ...@@ -174,7 +174,7 @@ class CommandTest(ModuleStoreTestCase):
log.debug('Adding more serial numbers to {0}'.format(SOFTWARE_1)) log.debug('Adding more serial numbers to {0}'.format(SOFTWARE_1))
with generate_serials_file(size) as temp_file: with generate_serials_file(size) as temp_file:
args = [self.course_id, SOFTWARE_1, temp_file.name] args = [self.course_id.to_deprecated_string(), SOFTWARE_1, temp_file.name]
call_command('import_serial_numbers', *args) call_command('import_serial_numbers', *args)
log.debug('There should be still only 2 course-software entries') log.debug('There should be still only 2 course-software entries')
...@@ -197,7 +197,7 @@ class CommandTest(ModuleStoreTestCase): ...@@ -197,7 +197,7 @@ class CommandTest(ModuleStoreTestCase):
with NamedTemporaryFile() as tmpfile: with NamedTemporaryFile() as tmpfile:
tmpfile.write('\n'.join(known_serials)) tmpfile.write('\n'.join(known_serials))
tmpfile.flush() tmpfile.flush()
args = [self.course_id, SOFTWARE_1, tmpfile.name] args = [self.course_id.to_deprecated_string(), SOFTWARE_1, tmpfile.name]
call_command('import_serial_numbers', *args) call_command('import_serial_numbers', *args)
log.debug('Check if we added only the new ones') log.debug('Check if we added only the new ones')
......
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