Skip to content
Browse files

bug 839341: Properly delete demo files when submission record deleted

  • Loading branch information...
1 parent 0a808ee commit 80dd0aa0843f2afeccece551683111539c83ea26 @lmorchard lmorchard committed Feb 19, 2013
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

0 comments on commit 80dd0aa

Please sign in to comment.
Something went wrong with that request. Please try again.