def _test_not_found(self, filename): """Test that a file could not be found.""" self.assertFalse(self.storage.exists(filename)) with self.assertRaises(Http404): serve_static(self.request, filename) self.assertFalse(self.storage.exists(filename))
def _test_found(self, **kwargs): """Test that a file can be found and contains the correct content.""" response = serve_static(self.request, self.filename, **kwargs) self.assertEqual(response.status_code, 200) self.assertTrue(self.storage.exists(self.filename)) if hasattr(response, 'streaming_content'): content = b''.join(response.streaming_content) else: content = response.content with self.storage.open(self.filename) as f: self.assertEqual(f.read(), content)
def test_debug_false(self): with self.assertRaises(ImproperlyConfigured): serve_static(self.request, self.filename) self.assertFalse(self.storage.exists(self.filename))