예제 #1
0
    def test_upload_proxy_optional_multiple(self):
        "Upload test case with proxied file."
        foo = make_tempfile('foo')
        bar = make_tempfile('bar')
        data = {
            'file[filename]': ['foo.png', 'bar.png'],
            'file[path]': [foo, bar],
            'file[content_type]': ['image/png'] * 2,
            'file[size]': [os.path.getsize(foo),
                           os.path.getsize(bar)],
        }
        with Settings(settings,
                      DEBUG=False,
                      TRANSFER_SERVER=self.transfer_server):
            r = self.getClient().post('/upload/', data)
        r = json.loads(r.content.decode())

        self.assertDictEqual(
            {
                'path': 'foo.png',
                'size': 3,
                'content-type': 'image/png',
                'data': 'foo'
            }, r['files']['file'][0])
        self.assertDictEqual(
            {
                'path': 'bar.png',
                'size': 3,
                'content-type': 'image/png',
                'data': 'bar'
            }, r['files']['file'][1])
예제 #2
0
    def test_upload_proxy_optional_multiple(self):
        "Upload test case with proxied file."
        foo = make_tempfile('foo')
        bar = make_tempfile('bar')
        data = {
            'file[filename]': ['foo.png', 'bar.png'],
            'file[path]': [foo, bar],
            'file[content_type]': ['image/png'] * 2,
            'file[size]': [os.path.getsize(foo), os.path.getsize(bar)],
        }
        with Settings(settings, DEBUG=False,
                      TRANSFER_SERVER=self.transfer_server):
            r = self.getClient().post('/upload/', data)
        r = json.loads(r.content.decode())

        self.assertDictEqual({
            'path': 'foo.png',
            'size': 3,
            'content-type': 'image/png',
            'data': 'foo'
        }, r['files']['file'][0])
        self.assertDictEqual({
            'path': 'bar.png',
            'size': 3,
            'content-type': 'image/png',
            'data': 'bar'
        }, r['files']['file'][1])
예제 #3
0
 def test_upload_proxy_multiple(self):
     "Upload test case with proxied file."
     foo = make_tempfile("foo")
     bar = make_tempfile("bar")
     data = {"file[filename]": ["foo.png", "bar.png"], "file[path]": [foo, bar]}
     with Settings(settings, DEBUG=False, TRANSFER_SERVER=self.transfer_server):
         r = self.getClient().post("/upload/", data)
     r = json.loads(r.content.decode())
     self.assertDictEqual(
         {"path": "foo.png", "size": 3, "content-type": "image/png", "data": "foo"}, r["files"]["file"][0]
     )
     self.assertDictEqual(
         {"path": "bar.png", "size": 3, "content-type": "image/png", "data": "bar"}, r["files"]["file"][1]
     )
예제 #4
0
 def test_upload_proxy(self):
     "Upload test case with proxied file."
     t = make_tempfile()
     data = {"file[filename]": "foobar.png", "file[path]": t}
     with Settings(settings, DEBUG=False, TRANSFER_SERVER=self.transfer_server):
         r = self.getClient().post("/upload/", data)
     r = json.loads(r.content.decode())
     self.assertEqual(os.getpid(), int(r["files"]["file"]["data"]))
예제 #5
0
 def test_upload_file(self):
     "Upload test case with real file."
     t = make_tempfile()
     with open(t, "rb") as file_obj:
         data = {"file": file_obj}
         with Settings(settings, DEBUG=False, TRANSFER_SERVER=self.transfer_server):
             r = self.getClient().post("/upload/", data)
     r = json.loads(r.content.decode())
     self.assertEqual(os.getpid(), int(r["files"]["file"]["data"]))
예제 #6
0
 def test_upload_file(self):
     "Upload test case with real file."
     t = make_tempfile()
     data = {
         'file': open(t, 'r'),
     }
     with Settings(settings, DEBUG=False,
                   TRANSFER_SERVER=self.transfer_server):
         r = self.getClient().post('/upload/', data)
     r = json.loads(r.content)
     self.assertEqual(os.getpid(), int(r['files']['file']['data']))
예제 #7
0
 def test_upload_proxy(self):
     "Upload test case with proxied file."
     t = make_tempfile()
     data = {
         'file[filename]': 'foobar.png',
         'file[path]': t,
     }
     with Settings(settings, DEBUG=False,
                   TRANSFER_SERVER=self.transfer_server):
         r = self.getClient().post('/upload/', data)
     r = json.loads(r.content)
     self.assertEqual(os.getpid(), int(r['files']['file']['data']))
예제 #8
0
 def test_upload_proxy(self):
     "Upload test case with proxied file."
     t = make_tempfile()
     data = {
         'file[filename]': 'foobar.png',
         'file[path]': t,
     }
     with Settings(settings, DEBUG=False,
                   TRANSFER_SERVER=self.transfer_server):
         r = self.getClient().post('/upload/', data)
     r = json.loads(r.content.decode())
     self.assertEqual(os.getpid(), int(r['files']['file']['data']))
예제 #9
0
 def test_upload_file(self):
     "Upload test case with real file."
     t = make_tempfile()
     with open(t, 'rb') as file_obj:
         data = {
             'file': file_obj,
         }
         with Settings(settings, DEBUG=False,
                       TRANSFER_SERVER=self.transfer_server):
             r = self.getClient().post('/upload/', data)
     r = json.loads(r.content.decode())
     self.assertEqual(os.getpid(), int(r['files']['file']['data']))
예제 #10
0
 def test_upload_proxy_patch(self):
     "Upload test case with proxied file."
     t = make_tempfile()
     data = {
         'file[filename]': 'foobar.png',
         'file[path]': t,
     }
     with Settings(settings,
                   DEBUG=False,
                   TRANSFER_SERVER=self.transfer_server):
         # Patch method does not encode or decode form data. We encode
         # manually.
         r = self.getClient().patch('/upload/',
                                    encode_multipart('--foo-', data),
                                    content_type='multipart/form-data; '
                                    'boundary=--foo-')
     r = json.loads(r.content.decode())
     self.assertEqual(os.getpid(), int(r['files']['file']['data']))