Exemplo n.º 1
0
 def __parse_metadata_as_dict(dropbox_raw_response):
     """Parses file metadata from a raw dropbox HTTP response, raising a
     dropbox.rest.ErrorResponse if parsing fails.
     """
     metadata = None
     for header, header_val in dropbox_raw_response.getheaders():
         if header.lower() == 'x-dropbox-metadata':
             try:
                 metadata = json.loads(header_val)
             except ValueError:
                 raise ErrorResponse(dropbox_raw_response)
     if not metadata: raise ErrorResponse(dropbox_raw_response)
     return metadata
Exemplo n.º 2
0
 def test_dropbox_hgrid_data_contents_returns_error_if_invalid_path(
         self, mock_metadata):
     mock_response = mock.Mock()
     mock_metadata.side_effect = ErrorResponse(mock_response,
                                               body='File not found')
     url = self.project.api_url_for('dropbox_hgrid_data_contents')
     res = self.app.get(url, auth=self.user.auth, expect_errors=True)
     assert_equal(res.status_code, httplib.NOT_FOUND)
Exemplo n.º 3
0
 def test_serialize_settings_invalid_credentials(self, mock_account_info):
     mock_response = mock.Mock()
     mock_response.status = 401
     mock_account_info.side_effect = ErrorResponse(
         mock_response,
         "The given OAuth 2 access token doesn't exist or has expired.")
     result = serialize_settings(self.node_settings, self.user)
     assert_false(result['validCredentials'])
Exemplo n.º 4
0
 def test_dropbox_folder_list_returns_error_if_invalid_path(
         self, mock_metadata):
     mock_response = mock.Mock()
     mock_metadata.side_effect = ErrorResponse(mock_response,
                                               body='File not found')
     url = self.project.api_url_for('dropbox_folder_list',
                                    folder_id='/fake_path')
     with mock.patch.object(type(self.node_settings), 'has_auth', True):
         res = self.app.get(url, auth=self.user.auth, expect_errors=True)
     assert_equal(res.status_code, http.NOT_FOUND)
Exemplo n.º 5
0
 def test_upload_file_non_401_errors_thrown_as_400(self, mock_put_file):
     mock_response = mock.Mock()
     mock_response.status = 404
     mock_put_file.side_effect = ErrorResponse(mock_response, "Bad Request.")
     payload = {'file': Upload('fizzbuzz.rst', b'baz', 'text/x-rst')}
     url = api_url_for('dropbox_upload',
             pid=self.project._primary_key,
             path='')
     res = self.app.post(url, payload, auth=self.user.auth, expect_errors=True)
     assert_equal(res.status_code, httplib.BAD_REQUEST)
Exemplo n.º 6
0
 def test_dropbox_user_config_get_has_invalid_credentials(self, mock_account_info):
     mock_response = mock.Mock()
     mock_response.status = 401
     mock_account_info.side_effect = ErrorResponse(mock_response, "The given OAuth 2 access token doesn't exist or has expired.")
     url = api_url_for('dropbox_user_config_get')
     res = self.app.get(url, auth=self.user.auth)
     assert_equal(res.status_code, 200)
     # The JSON result
     result = res.json['result']
     assert_false(result['validCredentials'])
Exemplo n.º 7
0
    def test_upload_file_with_invalid_credentials_throws_error(self, mock_put_file):
        mock_response = mock.Mock()
        mock_response.status = 401
        mock_put_file.side_effect = ErrorResponse(mock_response, "The given OAuth 2 access token doesn't exist or has expired.")

        payload = {'file': Upload('foobar.rst', b'baz', 'text/x-rst')}
        url = api_url_for('dropbox_upload',
                pid=self.project._primary_key,
                path='')
        res = self.app.post(url, payload, auth=self.user.auth, expect_errors=True)
        assert_equal(res.status_code, httplib.UNAUTHORIZED)
Exemplo n.º 8
0
    def test_dropbox_oauth_delete_user_with_invalid_credentials(self, mock_disable_access_token):
        self.user.add_addon('dropbox')
        settings = self.user.get_addon('dropbox')
        settings.access_token = '12345abc'
        settings.save()
        assert_true(settings.has_auth)

        mock_response = mock.Mock()
        mock_response.status = 401
        mock_disable_access_token.side_effect = ErrorResponse(mock_response, "The given OAuth 2 access token doesn't exist or has expired.")

        self.user.save()
        url = api_url_for('dropbox_oauth_delete_user')
        self.app.delete(url)
        settings.reload()
        assert_false(settings.has_auth)