Exemple #1
0
    def test_serve_content_as_file(self):
        disp_text = self.disposition_string % self.filename

        response = serve_file(filename=self.filename,
                              content=self.content,
                              is_download=True)
        self.assertTrue(response.has_header('Content-Disposition'))
        self.assertEqual(response['Content-Disposition'], disp_text)
Exemple #2
0
    def test_serve_file_contents(self):
        different_content = "different content"

        self.assertRaises(Http404,
                          serve_file,
                          filename='/etc/totally_garbage_fn3434dfd3s13')

        response = serve_file(filename=self.temp.name)
        self.assertEqual(response.content, self.content)
def serve_raw_data(request, file_type=None, pqq_type=None, extension=None):

    # Fine the current ./data directory no matter where this call
    # is executed from (staging, production, or wherever)
    data_root = os.path.abspath("%s/data" % os.path.split(__file__)[0])

    # The URL pattern would not have matched, and thus we would not get
    # to this view if any of the keyword arguments are None
    filename = os.path.join(data_root,
                            "%s_%s.%s" % (file_type, pqq_type, extension))
    #from django.http import HttpResponse
    #r = HttpResponse()
    #r.write(filename)

    return serve_file(filename=filename)

    #serve_file(filename="xx")
    return r
Exemple #4
0
    def test_serve_content_with_custom_filename(self):
        different_content = "different_content"

        response = serve_file(filename=self.temp.name,
                              content=different_content)
        self.assertEqual(response.content, different_content)
Exemple #5
0
 def test_serve_content(self):
     response = serve_file(filename=self.filename, content=self.content)
     self.assertEqual(response.content, self.content)