1. Faheem Mitha
  2. bixfile

Commits

Faheem Mitha  committed fa43103

'name' field of FileUpload is no longer required, but filesystem name is used instead. Add testFileUploadFormBlankName test.

  • Participants
  • Parent commits 6b7b434
  • Branches default

Comments (0)

Files changed (2)

File models.py

View file
  • Ignore whitespace
     #upload = models.FileField(upload_to=settings.BIXFILE_UPLOAD)
     upload = models.FileField(upload_to=file_upload_path, max_length=200)
     #name = models.CharField(core=True, max_length=200)
-    name = models.CharField(max_length=200)
+    name = models.CharField(blank=True, max_length=200)
     description = models.CharField(blank=True, max_length=200)
     md5sum = models.CharField(blank=False, editable=False, max_length=200)
 
             else:
                 self.path = self.folder.path
         self.md5sum = md5_for_django_file_object(self.upload)
+        if self.name == '':
+            self.name = os.path.basename(self.upload.name)
         super(FileUpload, self).save()
         # Need to add some error checking.
 

File tests.py

View file
  • Ignore whitespace
         self.assertEqual(fu_path, os.path.join(pf_path, os.path.split(fu_path)[1]))
         self.assertEqual(clean(walk()), [pf_path, fu_path])
 
+    def testFileUploadFormBlankName(self):
+        name = None
+        description = None
+        filename = "testFileUploadFormBlankName"
+        content = "test file testFileUploadFormBlankName"
+        data = {'name':name, 'description':description}
+        file_data = {'upload': SimpleUploadedFile(filename, content)}
+        ff = FileUploadForm(data, file_data)
+        if ff.is_valid():
+            fu = ff.save()
+        else:
+            raise ValidationError(ff.errors)
+        fu_path = os.path.join(settings.MEDIA_ROOT, fu.upload.name)
+        self.assertTrue(os.path.exists(fu_path))
+        self.assertEqual(clean(walk()), [fu_path])
+        self.assertEqual(fu.name, os.path.basename(fu.upload.name))
+
     def testFileUploadFormValidationError(self):
         """content-length is missing so save should throw value error."""
         data = {'name':'foo', 'description':'test file foo', 'folder':'1'}