Exemple #1
0
    def test_box_import_user_auth_returns_serialized_settings(
            self, mock_get_folder, mock_account_info):
        mock_get_folder.return_value = {
            'name': 'Camera Uploads',
            'path_collection': {
                'entries': [{
                    'name': 'All Files'
                }]
            }
        }
        mock_account_info.return_value = {'display_name': 'Mr. Box'}
        # Node does not have user settings
        self.node_settings.user_settings = None
        self.node_settings.save()
        url = api_url_for('box_import_user_auth',
                          pid=self.project._primary_key)
        res = self.app.put(url, auth=self.user.auth)
        self.project.reload()
        self.node_settings.reload()

        expected_result = serialize_settings(self.node_settings,
                                             self.user,
                                             client=mock_client)
        result = res.json['result']
        assert_equal(result, expected_result)
Exemple #2
0
    def test_serialize_settings_helper_returns_correct_urls(
            self, mock_get_folder):
        mock_get_folder.return_value = {
            'name': 'Camera Uploads',
            'path_collection': {
                'entries': [{
                    'name': 'All Files'
                }]
            }
        }
        result = serialize_settings(self.node_settings,
                                    self.user,
                                    client=mock_client)
        urls = result['urls']

        assert_equal(urls['config'],
                     self.project.api_url_for('box_config_put'))
        assert_equal(urls['deauthorize'],
                     self.project.api_url_for('box_deauthorize'))
        assert_equal(urls['auth'], self.project.api_url_for('box_oauth_start'))
        assert_equal(urls['importAuth'],
                     self.project.api_url_for('box_import_user_auth'))
        assert_equal(urls['files'],
                     self.project.web_url_for('collect_file_trees'))
        # assert_equal(urls['share'], utils.get_share_folder_uri(self.node_settings.folder))
        # Includes endpoint for fetching folders only
        # NOTE: Querystring params are in camelCase
        assert_equal(urls['folders'],
                     self.project.api_url_for('box_list_folders'))
        assert_equal(urls['settings'], web_url_for('user_addons'))
Exemple #3
0
 def test_serialize_settings_valid_credentials(self, mock_get_folder):
     mock_get_folder.return_value = {
         'name': 'Camera Uploads',
         'path_collection': {
             'entries': [
                 {'name': 'All Files'}
             ]
         }
     }
     result = serialize_settings(self.node_settings, self.user, client=mock_client)
     assert_true(result['validCredentials'])
Exemple #4
0
 def test_serialize_settings_invalid_credentials(self, mock_get_folder, mock_account_info):
     mock_get_folder.return_value = {
         'name': 'Camera Uploads',
         'path_collection': {
             'entries': [
                 {'name': 'All Files'}
             ]
         }
     }
     mock_account_info.side_effect = BoxClientException(401, "The given OAuth 2 access token doesn't exist or has expired.")
     result = serialize_settings(self.node_settings, self.user)
     assert_false(result['validCredentials'])
Exemple #5
0
 def test_serialize_settings_valid_credentials(self, mock_get_folder):
     mock_get_folder.return_value = {
         'name': 'Camera Uploads',
         'path_collection': {
             'entries': [{
                 'name': 'All Files'
             }]
         }
     }
     result = serialize_settings(self.node_settings,
                                 self.user,
                                 client=mock_client)
     assert_true(result['validCredentials'])
Exemple #6
0
 def test_serialize_settings_helper_returns_correct_folder_info(self, mock_get_folder):
     mock_get_folder.return_value = {
         'name': 'Camera Uploads',
         'path_collection': {
             'entries': [
                 {'name': 'All Files'}
             ]
         }
     }
     result = serialize_settings(self.node_settings, self.user, client=mock_client)
     folder = result['folder']
     assert_equal(folder['name'], '/' + self.node_settings.folder_name)
     assert_equal(folder['path'], 'All Files/' + self.node_settings.folder_name)
Exemple #7
0
 def test_serialize_settings_for_user_no_auth(self, mock_get_folder):
     mock_get_folder.return_value = {
         'name': 'Camera Uploads',
         'path_collection': {
             'entries': [
                 {'name': 'All Files'}
             ]
         }
     }
     no_addon_user = AuthUserFactory()
     result = serialize_settings(self.node_settings, no_addon_user, client=mock_client)
     assert_false(result['userIsOwner'])
     assert_false(result['userHasAuth'])
Exemple #8
0
 def test_serialize_settings_helper_returns_correct_auth_info(self, mock_get_folder):
     mock_get_folder.return_value = {
         'name': 'Camera Uploads',
         'path_collection': {
             'entries': [
                 {'name': 'All Files'}
             ]
         }
     }
     result = serialize_settings(self.node_settings, self.user, client=mock_client)
     assert_equal(result['nodeHasAuth'], self.node_settings.has_auth)
     assert_true(result['userHasAuth'])
     assert_true(result['userIsOwner'])
Exemple #9
0
 def test_serialize_settings_invalid_credentials(self, mock_get_folder,
                                                 mock_account_info):
     mock_get_folder.return_value = {
         'name': 'Camera Uploads',
         'path_collection': {
             'entries': [{
                 'name': 'All Files'
             }]
         }
     }
     mock_account_info.side_effect = BoxClientException(
         401,
         "The given OAuth 2 access token doesn't exist or has expired.")
     result = serialize_settings(self.node_settings, self.user)
     assert_false(result['validCredentials'])
Exemple #10
0
 def test_serialize_settings_for_user_no_auth(self, mock_get_folder):
     mock_get_folder.return_value = {
         'name': 'Camera Uploads',
         'path_collection': {
             'entries': [{
                 'name': 'All Files'
             }]
         }
     }
     no_addon_user = AuthUserFactory()
     result = serialize_settings(self.node_settings,
                                 no_addon_user,
                                 client=mock_client)
     assert_false(result['userIsOwner'])
     assert_false(result['userHasAuth'])
Exemple #11
0
 def test_serialize_settings_helper_returns_correct_auth_info(
         self, mock_get_folder):
     mock_get_folder.return_value = {
         'name': 'Camera Uploads',
         'path_collection': {
             'entries': [{
                 'name': 'All Files'
             }]
         }
     }
     result = serialize_settings(self.node_settings,
                                 self.user,
                                 client=mock_client)
     assert_equal(result['nodeHasAuth'], self.node_settings.has_auth)
     assert_true(result['userHasAuth'])
     assert_true(result['userIsOwner'])
Exemple #12
0
 def test_serialize_settings_helper_returns_correct_folder_info(
         self, mock_get_folder):
     mock_get_folder.return_value = {
         'name': 'Camera Uploads',
         'path_collection': {
             'entries': [{
                 'name': 'All Files'
             }]
         }
     }
     result = serialize_settings(self.node_settings,
                                 self.user,
                                 client=mock_client)
     folder = result['folder']
     assert_equal(folder['name'], '/' + self.node_settings.folder_name)
     assert_equal(folder['path'],
                  'All Files/' + self.node_settings.folder_name)
Exemple #13
0
    def test_box_import_user_auth_returns_serialized_settings(self, mock_get_folder, mock_account_info):
        mock_get_folder.return_value = {
            'name': 'Camera Uploads',
            'path_collection': {
                'entries': [
                    {'name': 'All Files'}
                ]
            }
        }
        mock_account_info.return_value = {'display_name': 'Mr. Box'}
        # Node does not have user settings
        self.node_settings.user_settings = None
        self.node_settings.save()
        url = api_url_for('box_import_user_auth', pid=self.project._primary_key)
        res = self.app.put(url, auth=self.user.auth)
        self.project.reload()
        self.node_settings.reload()

        expected_result = serialize_settings(self.node_settings, self.user,
                                             client=mock_client)
        result = res.json['result']
        assert_equal(result, expected_result)
Exemple #14
0
    def test_serialize_settings_helper_returns_correct_urls(self, mock_get_folder):
        mock_get_folder.return_value = {
            'name': 'Camera Uploads',
            'path_collection': {
                'entries': [
                    {'name': 'All Files'}
                ]
            }
        }
        result = serialize_settings(self.node_settings, self.user, client=mock_client)
        urls = result['urls']

        assert_equal(urls['config'], self.project.api_url_for('box_config_put'))
        assert_equal(urls['deauthorize'], self.project.api_url_for('box_deauthorize'))
        assert_equal(urls['auth'], self.project.api_url_for('box_oauth_start'))
        assert_equal(urls['importAuth'], self.project.api_url_for('box_import_user_auth'))
        assert_equal(urls['files'], self.project.web_url_for('collect_file_trees'))
        # assert_equal(urls['share'], utils.get_share_folder_uri(self.node_settings.folder))
        # Includes endpoint for fetching folders only
        # NOTE: Querystring params are in camelCase
        assert_equal(urls['folders'], self.project.api_url_for('box_list_folders'))
        assert_equal(urls['settings'], web_url_for('user_addons'))