Skip to content
This repository
Browse code

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
luke crouch groovecoder authored

Showing 2 changed files with 36 additions and 1 deletion. Show diff stats Hide diff stats

  1. +1 1  apps/demos/models.py
  2. +35 0 apps/demos/tests/test_models.py
2  apps/demos/models.py
@@ -525,7 +525,7 @@ def save(self, **kwargs):
525 525 super(Submission,self).save(**kwargs)
526 526
527 527 def delete(self,using=None):
528   - root = '%s/%s' % (settings.MEDIA_ROOT, get_root_for_submission(self))
  528 + root = '%s/%s' % (DEMO_UPLOADS_ROOT, get_root_for_submission(self))
529 529 if isdir(root): rmtree(root)
530 530 super(Submission,self).delete(using)
531 531
35 apps/demos/tests/test_models.py
@@ -332,6 +332,41 @@ def test_demo_unicode_filenames_2(self):
332 332
333 333 rmtree(path)
334 334
  335 + def test_demo_deletion(self):
  336 + """Ensure that demo files are deleted along with submission record"""
  337 +
  338 + fout = StringIO()
  339 + zf = zipfile.ZipFile(fout, 'w')
  340 + zf.writestr('demo.html', """<html></html""")
  341 + zf.writestr('css/main.css', 'h1 { color: red }')
  342 + zf.writestr('js/main.js', 'alert("HELLO WORLD");')
  343 + zf.close()
  344 +
  345 + s = Submission(title='Hello world', slug='hello-world',
  346 + description='This is a hello world demo',
  347 + creator=self.user)
  348 +
  349 + s.demo_package.save('play_demo.zip', ContentFile(fout.getvalue()))
  350 + s.demo_package.close()
  351 + s.clean()
  352 + s.save()
  353 +
  354 + s.process_demo_package()
  355 +
  356 + path = s.demo_package.path.replace('.zip', '')
  357 +
  358 + ok_(isdir(path))
  359 + ok_(isfile('%s/index.html' % path))
  360 + ok_(isfile('%s/css/main.css' % path))
  361 + ok_(isfile('%s/js/main.js' % path))
  362 +
  363 + s.delete()
  364 +
  365 + ok_(not isfile('%s/index.html' % path))
  366 + ok_(not isfile('%s/css/main.css' % path))
  367 + ok_(not isfile('%s/js/main.js' % path))
  368 + ok_(not isdir(path))
  369 +
335 370 def test_demo_file_size_limit(self):
336 371 """Demo package with any individual file >1MB in size is invalid"""
337 372 s = self.submission

0 comments on commit 264bd8d

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