Пример #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['config'], self.project.api_url_for('menbib_config_put'))
        assert_equal(urls['deauthorize'], self.project.api_url_for('menbib_deauthorize'))
        assert_equal(urls['auth'], self.project.api_url_for('menbib_oauth_start'))
        assert_equal(urls['importAuth'], self.project.api_url_for('menbib_import_user_auth'))
        assert_equal(urls['folders'],
            self.project.api_url_for('menbib_hgrid_data_contents'))
Пример #2
0
 def test_menbib_import_user_auth_returns_serialized_settings(self):
     # Node does not have user settings
     self.node_settings.user_settings = None
     self.node_settings.save()
     url = api_url_for('menbib_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)
Пример #3
0
def menbib_import_user_auth(auth, node_addon, **kwargs):
    """Import menbib credentials from the currently logged-in user to a node.
    """
    user = auth.user
    user_addon = user.get_addon('menbib')
    if user_addon is None or node_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.',
    }, http.OK
Пример #4
0
def menbib_config_get(node_addon, **kwargs):
    """API that returns the serialized node settings."""
    user = get_current_user()
    return {
        'result': serialize_settings(node_addon, user),
    }, http.OK
Пример #5
0
 def test_serialize_settings_helper_returns_correct_folder_info(self):
     result = serialize_settings(self.node_settings, self.user)
     folder = result['folder']
     assert_equal(folder['name'], 'Menbib' + self.node_settings.folder)
     assert_equal(folder['path'], self.node_settings.folder)
Пример #6
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'])
Пример #7
0
 def test_serialize_settings_helper_returns_correct_auth_info(self):
     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'])