##// END OF EJS Templates
admin: fixed problems with generating last change in admin panels....
admin: fixed problems with generating last change in admin panels. - from now on also updated_on will refer as last commit change instead of last update of DB. Reason for that is since we have audit logs the last db update should be taken from there along the change info. Storing last commit date in the dedicated field makes it searchable, sortable and faster to read.

File last commit:

r3363:f08e98b1 default
r4000:52837660 default
Show More
test_update_repo.py
203 lines | 7.3 KiB | text/x-python | PythonLexer
/ rhodecode / api / tests / test_update_repo.py
project: added all source files and assets
r1 # -*- coding: utf-8 -*-
docs: updated copyrights to 2019
r3363 # Copyright (C) 2010-2019 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 mock
import pytest
from rhodecode.model.repo import RepoModel
from rhodecode.tests import TEST_USER_ADMIN_LOGIN, TEST_USER_REGULAR_LOGIN
from rhodecode.api.tests.utils import (
dan
bugfix: fixed #3965 and updated a bunch of api tests which...
r68 build_data, api_call, assert_error, assert_ok, crash, jsonify)
project: added all source files and assets
r1 from rhodecode.tests.fixture import Fixture
dan
tests: fixed some pytest deprecated calls, and warnings.
r3098 from rhodecode.tests.plugin import plain_http_host_only_stub
project: added all source files and assets
r1
fixture = Fixture()
dan
bugfix: fixed #3965 and updated a bunch of api tests which...
r68 UPDATE_REPO_NAME = 'api_update_me'
repo-schemas: refactor repository schemas and use it in API update/create functions....
r1153
class SAME_AS_UPDATES(object):
""" Constant used for tests below """
project: added all source files and assets
r1
@pytest.mark.usefixtures("testuser_api", "app")
class TestApiUpdateRepo(object):
dan
bugfix: fixed #3965 and updated a bunch of api tests which...
r68
dan
tests: refactor test_update_repo for clarity
r70 @pytest.mark.parametrize("updates, expected", [
repo-schemas: refactor repository schemas and use it in API update/create functions....
r1153 ({'owner': TEST_USER_REGULAR_LOGIN},
SAME_AS_UPDATES),
({'description': 'new description'},
SAME_AS_UPDATES),
({'clone_uri': 'http://foo.com/repo'},
SAME_AS_UPDATES),
({'clone_uri': None},
{'clone_uri': ''}),
({'clone_uri': ''},
{'clone_uri': ''}),
validators: fix url_validator tests and make it flag controllable.
r3072 ({'clone_uri': 'http://example.com/repo_pull'},
{'clone_uri': 'http://example.com/repo_pull'}),
api: update pull method with possible specification of the url
r2563 ({'push_uri': ''},
{'push_uri': ''}),
validators: fix url_validator tests and make it flag controllable.
r3072 ({'push_uri': 'http://example.com/repo_push'},
{'push_uri': 'http://example.com/repo_push'}),
repo-schemas: refactor repository schemas and use it in API update/create functions....
r1153 ({'landing_rev': 'rev:tip'},
{'landing_rev': ['rev', 'tip']}),
({'enable_statistics': True},
SAME_AS_UPDATES),
({'enable_locking': True},
SAME_AS_UPDATES),
({'enable_downloads': True},
SAME_AS_UPDATES),
({'repo_name': 'new_repo_name'},
{
dan
events: add serialization .to_dict() to events based on marshmallow
r379 'repo_name': 'new_repo_name',
dan
tests: fixed some pytest deprecated calls, and warnings.
r3098 'url': 'http://{}/new_repo_name'.format(plain_http_host_only_stub())
repo-schemas: refactor repository schemas and use it in API update/create functions....
r1153 }),
({'repo_name': 'test_group_for_update/{}'.format(UPDATE_REPO_NAME),
'_group': 'test_group_for_update'},
{
'repo_name': 'test_group_for_update/{}'.format(UPDATE_REPO_NAME),
home: moved home and repo group views into pyramid....
r1774 'url': 'http://{}/test_group_for_update/{}'.format(
dan
tests: fixed some pytest deprecated calls, and warnings.
r3098 plain_http_host_only_stub(), UPDATE_REPO_NAME)
repo-schemas: refactor repository schemas and use it in API update/create functions....
r1153 }),
project: added all source files and assets
r1 ])
dan
tests: refactor test_update_repo for clarity
r70 def test_api_update_repo(self, updates, expected, backend):
dan
bugfix: fixed #3965 and updated a bunch of api tests which...
r68 repo_name = UPDATE_REPO_NAME
project: added all source files and assets
r1 repo = fixture.create_repo(repo_name, repo_type=backend.alias)
repo-schemas: refactor repository schemas and use it in API update/create functions....
r1153 if updates.get('_group'):
fixture.create_repo_group(updates['_group'])
project: added all source files and assets
r1
dan
bugfix: fixed #3965 and updated a bunch of api tests which...
r68 expected_api_data = repo.get_api_data(include_secrets=True)
if expected is SAME_AS_UPDATES:
expected_api_data.update(updates)
else:
expected_api_data.update(expected)
project: added all source files and assets
r1 id_, params = build_data(
self.apikey, 'update_repo', repoid=repo_name, **updates)
api: security, fix problem when absolute paths are specified with API call, that would allow...
r2664
with mock.patch('rhodecode.model.validation_schema.validators.url_validator'):
response = api_call(self.app, params)
dan
bugfix: fixed #3965 and updated a bunch of api tests which...
r68
repo-schemas: refactor repository schemas and use it in API update/create functions....
r1153 if updates.get('repo_name'):
repo_name = updates['repo_name']
dan
bugfix: fixed #3965 and updated a bunch of api tests which...
r68
project: added all source files and assets
r1 try:
expected = {
'msg': 'updated repo ID:%s %s' % (repo.repo_id, repo_name),
dan
bugfix: fixed #3965 and updated a bunch of api tests which...
r68 'repository': jsonify(expected_api_data)
project: added all source files and assets
r1 }
assert_ok(id_, expected, given=response.body)
finally:
fixture.destroy_repo(repo_name)
repo-schemas: refactor repository schemas and use it in API update/create functions....
r1153 if updates.get('_group'):
fixture.destroy_repo_group(updates['_group'])
project: added all source files and assets
r1
def test_api_update_repo_fork_of_field(self, backend):
master_repo = backend.create_repo()
repo = backend.create_repo()
updates = {
audit-logs: moved async tasks from old deprecated action_logger.
r1803 'fork_of': master_repo.repo_name,
'fork_of_id': master_repo.repo_id
project: added all source files and assets
r1 }
dan
bugfix: fixed #3965 and updated a bunch of api tests which...
r68 expected_api_data = repo.get_api_data(include_secrets=True)
expected_api_data.update(updates)
project: added all source files and assets
r1 id_, params = build_data(
self.apikey, 'update_repo', repoid=repo.repo_name, **updates)
response = api_call(self.app, params)
expected = {
'msg': 'updated repo ID:%s %s' % (repo.repo_id, repo.repo_name),
dan
bugfix: fixed #3965 and updated a bunch of api tests which...
r68 'repository': jsonify(expected_api_data)
project: added all source files and assets
r1 }
assert_ok(id_, expected, given=response.body)
result = response.json['result']['repository']
assert result['fork_of'] == master_repo.repo_name
audit-logs: moved async tasks from old deprecated action_logger.
r1803 assert result['fork_of_id'] == master_repo.repo_id
project: added all source files and assets
r1
def test_api_update_repo_fork_of_not_found(self, backend):
master_repo_name = 'fake-parent-repo'
repo = backend.create_repo()
updates = {
'fork_of': master_repo_name
}
id_, params = build_data(
self.apikey, 'update_repo', repoid=repo.repo_name, **updates)
response = api_call(self.app, params)
repo-schemas: refactor repository schemas and use it in API update/create functions....
r1153 expected = {
'repo_fork_of': 'Fork with id `{}` does not exists'.format(
master_repo_name)}
project: added all source files and assets
r1 assert_error(id_, expected, given=response.body)
def test_api_update_repo_with_repo_group_not_existing(self):
repo_name = 'admin_owned'
repo-schemas: refactor repository schemas and use it in API update/create functions....
r1153 fake_repo_group = 'test_group_for_update'
project: added all source files and assets
r1 fixture.create_repo(repo_name)
repo-schemas: refactor repository schemas and use it in API update/create functions....
r1153 updates = {'repo_name': '{}/{}'.format(fake_repo_group, repo_name)}
project: added all source files and assets
r1 id_, params = build_data(
self.apikey, 'update_repo', repoid=repo_name, **updates)
response = api_call(self.app, params)
try:
repo-schemas: refactor repository schemas and use it in API update/create functions....
r1153 expected = {
'repo_group': 'Repository group `{}` does not exist'.format(fake_repo_group)
}
project: added all source files and assets
r1 assert_error(id_, expected, given=response.body)
finally:
fixture.destroy_repo(repo_name)
def test_api_update_repo_regular_user_not_allowed(self):
repo_name = 'admin_owned'
fixture.create_repo(repo_name)
updates = {'active': False}
id_, params = build_data(
self.apikey_regular, 'update_repo', repoid=repo_name, **updates)
response = api_call(self.app, params)
try:
expected = 'repository `%s` does not exist' % (repo_name,)
assert_error(id_, expected, given=response.body)
finally:
fixture.destroy_repo(repo_name)
@mock.patch.object(RepoModel, 'update', crash)
def test_api_update_repo_exception_occurred(self, backend):
dan
bugfix: fixed #3965 and updated a bunch of api tests which...
r68 repo_name = UPDATE_REPO_NAME
project: added all source files and assets
r1 fixture.create_repo(repo_name, repo_type=backend.alias)
id_, params = build_data(
self.apikey, 'update_repo', repoid=repo_name,
owner=TEST_USER_ADMIN_LOGIN,)
response = api_call(self.app, params)
try:
expected = 'failed to update repo `%s`' % (repo_name,)
assert_error(id_, expected, given=response.body)
finally:
fixture.destroy_repo(repo_name)