auth-tokens: fixed tests

This commit is contained in:
Marcin Kuzminski 2017-02-28 12:49:40 +01:00
parent b1f8bb4212
commit d6dfdba2a8
13 changed files with 85 additions and 58 deletions

View file

@ -22,14 +22,19 @@ import pytest
from rhodecode.model.meta import Session
from rhodecode.model.user import UserModel
from rhodecode.model.auth_token import AuthTokenModel
from rhodecode.tests import TEST_USER_ADMIN_LOGIN
@pytest.fixture(scope="class")
def testuser_api(request, pylonsapp):
cls = request.cls
# ADMIN USER
cls.usr = UserModel().get_by_username(TEST_USER_ADMIN_LOGIN)
cls.apikey = cls.usr.api_key
# REGULAR USER
cls.test_user = UserModel().create_or_update(
username='test-api',
password='test',
@ -37,6 +42,11 @@ def testuser_api(request, pylonsapp):
firstname='first',
lastname='last'
)
# create TOKEN for user, if he doesn't have one
if not cls.test_user.api_key:
AuthTokenModel().create(
user=cls.test_user, description='TEST_USER_TOKEN')
Session().commit()
cls.TEST_USER_LOGIN = cls.test_user.username
cls.apikey_regular = cls.test_user.api_key

View file

@ -29,6 +29,7 @@ from rhodecode.api.tests.utils import (
@pytest.mark.usefixtures("testuser_api", "app")
class TestClosePullRequest(object):
@pytest.mark.backends("git", "hg")
def test_api_close_pull_request(self, pr_util):
pull_request = pr_util.create_pull_request()

View file

@ -53,11 +53,10 @@ class TestApiDeleteRepo(object):
}
assert_ok(id_, expected, given=response.body)
def test_api_delete_repo_by_non_admin_no_permission(
self, backend, user_regular):
def test_api_delete_repo_by_non_admin_no_permission(self, backend):
repo = backend.create_repo()
id_, params = build_data(
user_regular.api_key, 'delete_repo', repoid=repo.repo_name, )
self.apikey_regular, 'delete_repo', repoid=repo.repo_name, )
response = api_call(self.app, params)
expected = 'repository `%s` does not exist' % (repo.repo_name)
assert_error(id_, expected, given=response.body)

View file

@ -62,7 +62,6 @@ def get_user(request, apiuser, userid=Optional(OAttr('apiuser'))):
"result": {
"active": true,
"admin": false,
"api_key": "api-key",
"api_keys": [ list of keys ],
"email": "user@example.com",
"emails": [