コード例 #1
0
 def handle(self, *args, **kwargs):
     # all options are required
     if not kwargs.get('file'):
         raise CommandError("You must provide a path to the csv file")
     # try open the file
     try:
         with open(kwargs.get('file'), "r") as f:
             lines = csv.reader(f)
             i = 0
             for line in lines:
                 try:
                     username = line[0]
                     id_string = line[1]
                     uuid = line[2]
                     update_xform_uuid(username, id_string, uuid)
                 except IndexError:
                     print "line %d is in an invalid format" % (i + 1)
                 except XForm.DoesNotExist:
                     print "XForm with username: %s and id string: %s does"\
                           " not exist" % (username, id_string, uuid)
                 except DuplicateUUIDError:
                     print "An xform with uuid: %s already exists" % uuid
                 else:
                     i += 1
                     print "Updated %d rows" % i
     except IOError:
         raise CommandError(
             "file %s could not be open" % kwargs.get('file'))
コード例 #2
0
 def handle(self, *args, **kwargs):
     # all options are required
     if not kwargs.get('file'):
         raise CommandError("You must provide a path to the csv file")
     # try open the file
     try:
         with open(kwargs.get('file'), "r") as f:
             lines = csv.reader(f)
             i = 0
             for line in lines:
                 try:
                     username = line[0]
                     id_string = line[1]
                     uuid = line[2]
                     update_xform_uuid(username, id_string, uuid)
                 except IndexError:
                     print("line %d is in an invalid format" % (i + 1))
                 except XForm.DoesNotExist:
                     print("XForm with username: %s and id string: %s does"
                           " not exist" % (username, id_string, uuid))
                 except DuplicateUUIDError:
                     print("An xform with uuid: %s already exists" % uuid)
                 else:
                     i += 1
                     print("Updated %d rows" % i)
     except IOError:
         raise CommandError("file %s could not be open" %
                            kwargs.get('file'))
コード例 #3
0
 def test_fail_update_on_duplicate_uuid(self):
     self.xform.uuid = self.new_uuid
     self.xform.save()
     try:
         update_xform_uuid(self.user.username, self.xform.id_string,
                           self.new_uuid)
     except DuplicateUUIDError:
         self.assertTrue(True)
     else:
         self.assertTrue(False)
コード例 #4
0
 def test_fail_update_on_duplicate_uuid(self):
     self.xform.uuid = self.new_uuid
     self.xform.save()
     try:
         update_xform_uuid(self.user.username, self.xform.id_string,
                           self.new_uuid)
     except DuplicateUUIDError:
         self.assertTrue(True)
     else:
         self.assertTrue(False)