Example #1
0
    def test_serialize_settings_helper_returns_correct_urls(self):
        result = serialize_settings(self.node_settings, self.user)
        urls = result['urls']

        assert_equal(urls['files'], self.project.web_url_for('collect_file_trees'))
        assert_equal(urls['config'], self.project.api_url_for('googledrive_config_put'))
        assert_equal(urls['deauthorize'], self.project.api_url_for('googledrive_deauthorize'))
        assert_equal(urls['importAuth'], self.project.api_url_for('googledrive_import_user_auth'))
        # Includes endpoint for fetching folders only
        # NOTE: Querystring params are in camelCase
        assert_equal(urls['get_folders'], self.project.api_url_for('googledrive_folders'))
Example #2
0
    def test_googledrive_import_user_auth_returns_serialized_settings(self):
        self.node_settings.user_settings = None
        self.node_settings.save()
        url = api_url_for('googledrive_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)
        result = res.json['result']
        assert_equal(result, expected_result)
Example #3
0
    def test_serialize_settings_helper_returns_correct_urls(self):
        result = serialize_settings(self.node_settings, self.user)
        urls = result["urls"]

        assert_equal(urls["files"], self.project.web_url_for("collect_file_trees"))
        assert_equal(urls["config"], self.project.api_url_for("googledrive_config_put"))
        assert_equal(urls["deauthorize"], self.project.api_url_for("googledrive_deauthorize"))
        assert_equal(urls["importAuth"], self.project.api_url_for("googledrive_import_user_auth"))
        # Includes endpoint for fetching folders only
        # NOTE: Querystring params are in camelCase
        assert_equal(urls["folders"], self.project.api_url_for("googledrive_folders"))
Example #4
0
    def test_googledrive_import_user_auth_returns_serialized_settings(self):
        self.node_settings.user_settings = None
        self.node_settings.save()
        url = api_url_for('googledrive_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)
        result = res.json['result']
        assert_equal(result, expected_result)
Example #5
0
    def test_serialize_settings_helper_returns_correct_urls(self):
        result = serialize_settings(self.node_settings, self.user)
        urls = result['urls']

        assert_equal(urls['files'], self.project.web_url_for('collect_file_trees'))
        assert_equal(urls['config'], self.project.api_url_for('googledrive_config_put'))
        assert_equal(urls['deauthorize'], self.project.api_url_for('googledrive_deauthorize'))
        assert_equal(urls['importAuth'], self.project.api_url_for('googledrive_import_user_auth'))
        # Includes endpoint for fetching folders only
        # NOTE: Querystring params are in camelCase
        assert_equal(urls['get_folders'], self.project.api_url_for('googledrive_folders'))
Example #6
0
def googledrive_import_user_auth(auth, node_addon, **kwargs):
    """Import googledrive credentials from the currently logged-in user to a node.
    """
    user = auth.user
    user_addon = user.get_addon('googledrive')

    if user_addon is None:
        raise HTTPError(http.BAD_REQUEST)

    node_addon.set_user_auth(user_addon)
    node_addon.save()
    return {
        'result': serialize_settings(node_addon, user),
        'message': 'Successfully imported access token from profile.',
    }
Example #7
0
def googledrive_import_user_auth(auth, node_addon, **kwargs):
    """Import googledrive credentials from the currently logged-in user to a node.
    """
    user = auth.user
    user_addon = user.get_addon('googledrive')

    if user_addon is None:
        raise HTTPError(http.BAD_REQUEST)

    node_addon.set_user_auth(user_addon)
    node_addon.save()
    return {
        'result': serialize_settings(node_addon, user),
        'message': 'Successfully imported access token from profile.',
    }
Example #8
0
 def test_serialize_settings_for_user_no_auth(self):
     no_addon_user = AuthUserFactory()
     result = serialize_settings(self.node_settings, no_addon_user)
     assert_false(result['userIsOwner'])
     assert_false(result['userHasAuth'])
Example #9
0
 def test_serialize_settings_helper_returns_correct_auth_info(self):
     self.user_settings.access_token = 'abc123'
     result = serialize_settings(self.node_settings, self.user)
     assert_equal(result['nodeHasAuth'], self.node_settings.has_auth)
     assert_true(result['userHasAuth'])
     assert_true(result['userIsOwner'])
Example #10
0
def googledrive_config_get(node_addon, auth, **kwargs):
    """API that returns the serialized node settings."""
    return {
        'result': serialize_settings(node_addon, auth.user),
    }
Example #11
0
 def test_serialize_settings_for_user_no_auth(self):
     no_addon_user = AuthUserFactory()
     result = serialize_settings(self.node_settings, no_addon_user)
     assert_false(result['userIsOwner'])
     assert_false(result['userHasAuth'])
Example #12
0
 def test_serialize_settings_helper_returns_correct_auth_info(self):
     self.user_settings.access_token = 'abc123'
     result = serialize_settings(self.node_settings, self.user)
     assert_equal(result['nodeHasAuth'], self.node_settings.has_auth)
     assert_true(result['userHasAuth'])
     assert_true(result['userIsOwner'])