def test_response_filename(self):
        response = ZipFileResponse(filename='otherfile')

        for fn, content in self.files.iteritems():
            response.append(fn, content)
            self.zipfile.writestr(fn, content.encode(response._content_encoding))

        response.close()
        self.zipfile.close()

        headers = "Content-Type: application/octet-stream\r\nContent-Disposition: attachment; filename=otherfile\r\n\r\n"
        self.assertEqual('%s' % response, '%s%s' % (headers, self.output.getvalue()))
    def test_response_filename(self):
        response = ZipFileResponse(filename='otherfile')

        for fn, content in self.files.iteritems():
            response.append(fn, content)
            self.zipfile.writestr(fn,
                                  content.encode(response._content_encoding))

        response.close()
        self.zipfile.close()

        headers = "Content-Type: application/octet-stream\r\nContent-Disposition: attachment; filename=otherfile\r\n\r\n"
        self.assertEqual('%s' % response,
                         '%s%s' % (headers, self.output.getvalue()))
    def test_response_no_encoding(self):
        response = ZipFileResponse(content_encoding=None)

        for fn, content in self.files.iteritems():
            # writestr fails for unencoded unicode content
            if fn == 'love.txt':
                with self.assertRaises(UnicodeEncodeError):
                    response.append(fn, content)
            else:
                response.append(fn, content)
                self.zipfile.writestr(fn, content)

        response.close()
        self.zipfile.close()

        headers = "Content-Type: application/octet-stream\r\nContent-Disposition: attachment; filename=file.zip\r\n\r\n"
        self.assertEqual('%s' % response, '%s%s' % (headers, self.output.getvalue()))
    def test_response_no_encoding(self):
        response = ZipFileResponse(content_encoding=None)

        for fn, content in self.files.iteritems():
            # writestr fails for unencoded unicode content
            if fn == 'love.txt':
                with self.assertRaises(UnicodeEncodeError):
                    response.append(fn, content)
            else:
                response.append(fn, content)
                self.zipfile.writestr(fn, content)

        response.close()
        self.zipfile.close()

        headers = "Content-Type: application/octet-stream\r\nContent-Disposition: attachment; filename=file.zip\r\n\r\n"
        self.assertEqual('%s' % response,
                         '%s%s' % (headers, self.output.getvalue()))