##// END OF EJS Templates
caches: use individual namespaces per user to prevent beaker caching problems....
caches: use individual namespaces per user to prevent beaker caching problems. - especially for mysql in case large number of data in caches there could be critical errors storing cache, and thus preventing users from authentication. This is caused by the fact that we used single namespace for ALL users. It means it grew as number of users grew reaching mysql single column limit. This changes the behaviour and now we use namespace per-user it means that each user-id will have it's own cache namespace fragmenting maximum column data to a single user cache. Which we should never reach.

File last commit:

r2487:fcee5614 default
r2591:36829a17 stable
Show More
test_api.py
131 lines | 5.0 KiB | text/x-python | PythonLexer
project: added all source files and assets
r1 # -*- coding: utf-8 -*-
release: update copyright year to 2018
r2487 # Copyright (C) 2010-2018 RhodeCode GmbH
project: added all source files and assets
r1 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
import pytest
from rhodecode.api.utils import Optional, OAttr
from rhodecode.api.tests.utils import (
build_data, api_call, assert_error, assert_ok)
@pytest.mark.usefixtures("testuser_api", "app")
class TestApi(object):
maxDiff = None
def test_Optional_object(self):
option1 = Optional(None)
assert '<Optional:%s>' % (None,) == repr(option1)
assert option1() is None
assert 1 == Optional.extract(Optional(1))
assert 'example' == Optional.extract('example')
def test_Optional_OAttr(self):
option1 = Optional(OAttr('apiuser'))
assert 'apiuser' == Optional.extract(option1)
def test_OAttr_object(self):
oattr1 = OAttr('apiuser')
assert '<OptionalAttr:apiuser>' == repr(oattr1)
assert oattr1() == oattr1
def test_api_wrong_key(self):
id_, params = build_data('trololo', 'get_user')
response = api_call(self.app, params)
expected = 'Invalid API KEY'
assert_error(id_, expected, given=response.body)
def test_api_missing_non_optional_param(self):
id_, params = build_data(self.apikey, 'get_repo')
response = api_call(self.app, params)
expected = 'Missing non optional `repoid` arg in JSON DATA'
assert_error(id_, expected, given=response.body)
def test_api_missing_non_optional_param_args_null(self):
id_, params = build_data(self.apikey, 'get_repo')
params = params.replace('"args": {}', '"args": null')
response = api_call(self.app, params)
expected = 'Missing non optional `repoid` arg in JSON DATA'
assert_error(id_, expected, given=response.body)
def test_api_missing_non_optional_param_args_bad(self):
id_, params = build_data(self.apikey, 'get_repo')
params = params.replace('"args": {}', '"args": 1')
response = api_call(self.app, params)
expected = 'Missing non optional `repoid` arg in JSON DATA'
assert_error(id_, expected, given=response.body)
def test_api_non_existing_method(self, request):
id_, params = build_data(self.apikey, 'not_existing', args='xx')
response = api_call(self.app, params)
api: add get_method API call....
r1417 expected = 'No such method: not_existing. Similar methods: none'
assert_error(id_, expected, given=response.body)
def test_api_non_existing_method_have_similar(self, request):
id_, params = build_data(self.apikey, 'comment', args='xx')
response = api_call(self.app, params)
api: pull-requests, make the repoid parameter optional. Because pullrequestid is global...
r2395 expected = 'No such method: comment. Similar methods: changeset_comment, comment_pull_request, get_pull_request_comments, comment_commit'
project: added all source files and assets
r1 assert_error(id_, expected, given=response.body)
def test_api_disabled_user(self, request):
def set_active(active):
from rhodecode.model.db import Session, User
user = User.get_by_auth_token(self.apikey)
user.active = active
Session().add(user)
Session().commit()
request.addfinalizer(lambda: set_active(True))
set_active(False)
id_, params = build_data(self.apikey, 'test', args='xx')
response = api_call(self.app, params)
expected = 'Request from this user not allowed'
assert_error(id_, expected, given=response.body)
def test_api_args_is_null(self):
__, params = build_data(self.apikey, 'get_users', )
params = params.replace('"args": {}', '"args": null')
response = api_call(self.app, params)
assert response.status == '200 OK'
def test_api_args_is_bad(self):
__, params = build_data(self.apikey, 'get_users', )
params = params.replace('"args": {}', '"args": 1')
response = api_call(self.app, params)
assert response.status == '200 OK'
def test_api_args_different_args(self):
import string
expected = {
'ascii_letters': string.ascii_letters,
'ws': string.whitespace,
'printables': string.printable
}
id_, params = build_data(self.apikey, 'test', args=expected)
response = api_call(self.app, params)
assert response.status == '200 OK'
assert_ok(id_, expected, response.body)