Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #875 from lmorchard/839341-demo-files-removed-on-d…

…elete

bug 839341: Properly delete demo files when submission record deleted
  • Loading branch information...
commit 264bd8de0d904c515539704a0d2d67adfd4a996b 2 parents 37dba23 + 80dd0aa
@groovecoder groovecoder authored
Showing with 36 additions and 1 deletion.
  1. +1 −1  apps/demos/models.py
  2. +35 −0 apps/demos/tests/test_models.py
View
2  apps/demos/models.py
@@ -525,7 +525,7 @@ def save(self, **kwargs):
super(Submission,self).save(**kwargs)
def delete(self,using=None):
- root = '%s/%s' % (settings.MEDIA_ROOT, get_root_for_submission(self))
+ root = '%s/%s' % (DEMO_UPLOADS_ROOT, get_root_for_submission(self))
if isdir(root): rmtree(root)
super(Submission,self).delete(using)
View
35 apps/demos/tests/test_models.py
@@ -332,6 +332,41 @@ def test_demo_unicode_filenames_2(self):
rmtree(path)
+ def test_demo_deletion(self):
+ """Ensure that demo files are deleted along with submission record"""
+
+ fout = StringIO()
+ zf = zipfile.ZipFile(fout, 'w')
+ zf.writestr('demo.html', """<html></html""")
+ zf.writestr('css/main.css', 'h1 { color: red }')
+ zf.writestr('js/main.js', 'alert("HELLO WORLD");')
+ zf.close()
+
+ s = Submission(title='Hello world', slug='hello-world',
+ description='This is a hello world demo',
+ creator=self.user)
+
+ s.demo_package.save('play_demo.zip', ContentFile(fout.getvalue()))
+ s.demo_package.close()
+ s.clean()
+ s.save()
+
+ s.process_demo_package()
+
+ path = s.demo_package.path.replace('.zip', '')
+
+ ok_(isdir(path))
+ ok_(isfile('%s/index.html' % path))
+ ok_(isfile('%s/css/main.css' % path))
+ ok_(isfile('%s/js/main.js' % path))
+
+ s.delete()
+
+ ok_(not isfile('%s/index.html' % path))
+ ok_(not isfile('%s/css/main.css' % path))
+ ok_(not isfile('%s/js/main.js' % path))
+ ok_(not isdir(path))
+
def test_demo_file_size_limit(self):
"""Demo package with any individual file >1MB in size is invalid"""
s = self.submission
Please sign in to comment.
Something went wrong with that request. Please try again.