示例#1
0
    def test_body(self):
        json_data = {'foo' : 'bar', 'baz' : 42}
        url = 'https://api.dropbox.com/metadata'
        post_params = {'quux' : 'is', 'a' : 'horse'}

        # setup mocks
        response = mock.Mock()
        response.status = 200

        conn = mock.Mock()
        conn.getresponse.return_value = response

        mock_http_connect = mock.Mock()
        mock_http_connect.return_value = conn

        fd, path = tempfile.mkstemp()
        os.unlink(path)
        with os.fdopen(fd, 'wb+') as f:
            f.writelines(itertools.repeat(b("a5"), int(16 * 1024 / 2)))
            f.seek(0)

            # invoke code
            ret = RESTClientObject(http_connect=mock_http_connect).PUT(url, body=f,
                                                                       raw_response=True)

            # check code
            mock_http_connect.assert_called_with('api.dropbox.com', 443)
            conn.request.assert_called_with('PUT', url, "",
                                            {'User-Agent' : 'OfficialDropboxPythonSDK/' + SDK_VERSION,
                                             'Content-Length' : str(16 * 1024)})
            sent = b('').join(a[0][0] for a in conn.send.call_args_list)
            self.assertEqual(sent, b("a5") * int(16 * 1024 / 2))

            conn.getresponse.assert_called_with()
            assert ret is response
示例#2
0
            def simple_app(environ, start_response):
                path = environ['PATH_INFO']

                if path == '/die':
                    time_to_die[0] = True
                    start_response('200 OK', [('Content-type', 'text/plain')])
                    return [b('dead')]

                try:
                    result = routes[path]
                except KeyError:
                    start_response('404 NOT FOUND', [('Content-type', 'text/plain')])
                    return [b('NOT FOUND')]
                else:
                    start_response('200 OK', [('Content-type', 'text/plain')])
                    return [result]
示例#3
0
 def test_basic_unicode(self):
     path = u"/\u4545"
     result = b("sup")
     with self.listen_server({path : result}) as a:
         # URLs can't have unicode in them,
         # they have to be quoted by urllib.quote
         self.assertRaises(Exception, a.request, "GET", path)
    def test_body(self):
        json_data = {'foo': 'bar', 'baz': 42}
        url = 'https://api.dropbox.com/metadata'

        # setup mocks
        response, mock_urlopen = setup_response_mock(json_data)

        fd, path = tempfile.mkstemp()
        os.unlink(path)
        with os.fdopen(fd, 'wb+') as f:
            f.writelines(itertools.repeat(b("a5"), int(16 * 1024 / 2)))
            f.seek(0)

            # invoke code
            ret = RESTClientObject(mock_urlopen=mock_urlopen).PUT(
                url, body=f, raw_response=True)

            # check code
            check_mock(response,
                       mock_urlopen,
                       'PUT',
                       url,
                       body=f,
                       raw_response=True,
                       headers={
                           'User-Agent':
                           'OfficialDropboxPythonSDK/' + SDK_VERSION
                       })

            assert ret.urllib3_response is response
 def test_basic_unicode(self):
     path = u"/\u4545"
     result = b("sup")
     with self.listen_server({path: result}) as a:
         # URLs can't have unicode in them,
         # they have to be quoted by urllib.quote
         self.assertRaises(Exception, a.request, "GET", path)
示例#6
0
 def test_basic(self):
     path = "/"
     result = b("sup")
     with self.listen_server({path: result}) as a:
         a.connect()
         a.request("GET", path)
         response = a.getresponse()
         self.assertEqual(response.read(), result)
示例#7
0
 def test_basic(self):
     path = "/"
     result = b("sup")
     with self.listen_server({path : result}) as a:
         a.connect()
         a.request("GET", path)
         response = a.getresponse()
         self.assertEqual(response.read(), result)
            def simple_app(environ, start_response):
                path = environ['PATH_INFO']

                if path == '/die':
                    time_to_die[0] = True
                    start_response('200 OK', [('Content-type', 'text/plain')])
                    return [b('dead')]

                try:
                    result = routes[path]
                except KeyError:
                    start_response('404 NOT FOUND',
                                   [('Content-type', 'text/plain')])
                    return [b('NOT FOUND')]
                else:
                    start_response('200 OK', [('Content-type', 'text/plain')])
                    return [result]
示例#9
0
    def test_body(self):
        json_data = {'foo': 'bar', 'baz': 42}
        url = 'https://api.dropbox.com/metadata'
        post_params = {'quux': 'is', 'a': 'horse'}

        # setup mocks
        response = mock.Mock()
        response.status = 200

        conn = mock.Mock()
        conn.getresponse.return_value = response

        mock_http_connect = mock.Mock()
        mock_http_connect.return_value = conn

        fd, path = tempfile.mkstemp()
        os.unlink(path)
        with os.fdopen(fd, 'wb+') as f:
            f.writelines(itertools.repeat(b("a5"), int(16 * 1024 / 2)))
            f.seek(0)

            # invoke code
            ret = RESTClientObject(http_connect=mock_http_connect).PUT(
                url, body=f, raw_response=True)

            # check code
            mock_http_connect.assert_called_with('api.dropbox.com', 443)
            conn.request.assert_called_with(
                'PUT', url, "", {
                    'User-Agent': 'OfficialDropboxPythonSDK/' + SDK_VERSION,
                    'Content-Length': str(16 * 1024)
                })
            sent = b('').join(a[0][0] for a in conn.send.call_args_list)
            self.assertEqual(sent, b("a5") * int(16 * 1024 / 2))

            conn.getresponse.assert_called_with()
            assert ret is response
示例#10
0
    def test_body(self):
        json_data = {'foo' : 'bar', 'baz' : 42}
        url = 'https://api.dropbox.com/metadata'

        # setup mocks
        response, mock_urlopen = setup_response_mock(json_data)

        fd, path = tempfile.mkstemp()
        os.unlink(path)
        with os.fdopen(fd, 'wb+') as f:
            f.writelines(itertools.repeat(b("a5"), int(16 * 1024 / 2)))
            f.seek(0)

            # invoke code
            ret = RESTClientObject(mock_urlopen=mock_urlopen).PUT(url, body=f,
                                                                       raw_response=True)

            # check code
            check_mock(
                response, mock_urlopen, 'PUT', url, body=f, raw_response=True,
                headers={'User-Agent' : 'OfficialDropboxPythonSDK/' + SDK_VERSION}
            )

            assert ret.urllib3_response is response
示例#11
0
 def test_basic(self):
     path = "/"
     result = b("sup")
     with self.listen_server({path : result}) as a:
         response = a.request("GET", path)
         self.assertEqual(response.data, result)
 def test_basic(self):
     path = "/"
     result = b("sup")
     with self.listen_server({path: result}) as a:
         response = a.request("GET", path)
         self.assertEqual(response.data, result)