def test_file_gets_returned_as_generator_to_wsgi(self): response = Response() with NamedTemporaryFile() as tmpfile: tmpfile.write(b'hello world') tmpfile.seek(0) response.file(tmpfile.name) start_respose = Mock() self.assertIsInstance(response.wsgi(start_respose), GeneratorType)
def test_all_file_contents_are_yielded_by_its_generator(self): response = Response() with NamedTemporaryFile() as tmpfile: tmpfile.write(b'hello world') tmpfile.seek(0) response.file(tmpfile.name) start_respose = Mock() file_generator = response.wsgi(start_respose) contents = b'' for chunk in file_generator: contents += chunk self.assertEqual(contents, b'hello world')