def test_branch_is_a_link(self, pr_util): pull_request = pr_util.create_pull_request() pull_request.source_ref = 'branch:origin:1234567890abcdef' pull_request.target_ref = 'branch:target:abcdef1234567890' Session().add(pull_request) Session().commit() response = self.app.get(url( controller='pullrequests', action='show', repo_name=pull_request.target_repo.scm_instance().name, pull_request_id=str(pull_request.pull_request_id))) assert response.status_int == 200 assert_response = AssertResponse(response) origin = assert_response.get_element('.pr-origininfo .tag') origin_children = origin.getchildren() assert len(origin_children) == 1 target = assert_response.get_element('.pr-targetinfo .tag') target_children = target.getchildren() assert len(target_children) == 1 expected_origin_link = url( 'changelog_home', repo_name=pull_request.source_repo.scm_instance().name, branch='origin') expected_target_link = url( 'changelog_home', repo_name=pull_request.target_repo.scm_instance().name, branch='target') assert origin_children[0].attrib['href'] == expected_origin_link assert origin_children[0].text == 'branch: origin' assert target_children[0].attrib['href'] == expected_target_link assert target_children[0].text == 'branch: target'
def test_sessions_are_ok_when_password_is_not_changed( self, app, autologin_user): response = app.get(url('home')) assert_response = AssertResponse(response) assert_response.element_contains('#quick_login_link .menu_link_user', TEST_USER_ADMIN_LOGIN) assert 'rhodecode_user' in response.session assert response.session.was_invalidated is False
def test_index_links_submodules_with_absolute_url(self, backend_hg): repo = backend_hg['subrepos'] response = self.app.get(url( controller='files', action='index', repo_name=repo.repo_name, revision='tip', f_path='/')) assert_response = AssertResponse(response) assert_response.contains_one_link( 'absolute-path @ 000000000000', 'http://example.com/absolute-path')
def test_sessions_invalidated_when_password_is_changed( self, app, autologin_user): self.password_changed_mock.return_value = True response = app.get(url('home')) assert_response = AssertResponse(response) assert_response.element_contains('#quick_login_link .user', 'Sign in') assert 'rhodecode_user' not in response.session assert response.session.was_invalidated is True
def test_show(self, create_gist): gist = create_gist('gist-show-me') response = self.app.get(url('gist', gist_id=gist.gist_access_id)) response.mustcontain('added file: gist-show-me<') assert_response = AssertResponse(response) assert_response.element_equals_to( 'div.rc-user span.user', '<span class="user"> %s</span>' % h.link_to_user('test_admin')) response.mustcontain('gist-desc')
def test_register_err_same_email_case_sensitive(self): response = self.app.post( register_url, { 'username': '******', 'password': '******', 'password_confirmation': 'test12', 'email': '*****@*****.**', 'firstname': 'test', 'lastname': 'test' }) assertr = AssertResponse(response) msg = validators.UniqSystemEmail()()._messages['email_taken'] assertr.element_contains('#email+.error-message', msg)
def test_index_different_branch(self, backend): # TODO: Git test repository does not contain branches # TODO: Branch support in Subversion commit = backend.repo.get_commit(commit_idx=150) response = self.app.get(url( controller='files', action='index', repo_name=backend.repo_name, revision=commit.raw_id, f_path='/')) assert_response = AssertResponse(response) assert_response.element_contains( '.tags .branchtag', 'git')
def test_ldap_error_form_wrong_port_number(self, csrf_token): params = self._enable_plugins( 'egg:rhodecode-enterprise-ce#rhodecode,' 'egg:rhodecode-enterprise-ce#ldap', csrf_token) invalid_port_value = 'invalid-port-number' response = self._post_ldap_settings(params, override={ 'port': invalid_port_value, }) assertr = AssertResponse(response) assertr.element_contains( '.form .field #port ~ .error-message', invalid_port_value)
def test_strip_commits_from_pull_request( self, backend, pr_util, csrf_token): commits = [ {'message': 'initial-commit'}, {'message': 'old-feature'}, {'message': 'new-feature', 'parents': ['initial-commit']}, ] pull_request = pr_util.create_pull_request( commits, target_head='initial-commit', source_head='new-feature', revisions=['new-feature']) vcs = pr_util.source_repository.scm_instance() if backend.alias == 'git': vcs.strip(pr_util.commit_ids['new-feature'], branch_name='master') else: vcs.strip(pr_util.commit_ids['new-feature']) response = self.app.get(url( controller='pullrequests', action='show', repo_name=pr_util.target_repository.repo_name, pull_request_id=str(pull_request.pull_request_id))) assert response.status_int == 200 assert_response = AssertResponse(response) assert_response.element_contains( '#changeset_compare_view_content .alert strong', 'Missing commits') assert_response.element_contains( '#changeset_compare_view_content .alert', 'This pull request cannot be displayed, because one or more' ' commits no longer exist in the source repository.') assert_response.element_contains( '#update_commits', 'Update commits')
def test_show_acl_private(self, create_gist): gist = create_gist('gist-show-me-only-when-im-logged-in', acl_level=Gist.ACL_LEVEL_PRIVATE) self.app.get(url('gist', gist_id=gist.gist_access_id), status=404) # now we log-in we should see thi gist self.log_user() response = self.app.get(url('gist', gist_id=gist.gist_access_id)) response.mustcontain('added file: gist-show-me-only-when-im-logged-in') assert_response = AssertResponse(response) assert_response.element_equals_to( 'div.rc-user span.user', '<span class="user"> %s</span>' % h.link_to_user('test_admin')) response.mustcontain('gist-desc')
def test_register_err_same_username(self): uname = 'test_admin' response = self.app.post( register_url, { 'username': uname, 'password': '******', 'password_confirmation': 'test12', 'email': '*****@*****.**', 'firstname': 'test', 'lastname': 'test' }) assertr = AssertResponse(response) msg = validators.ValidUsername()._messages['username_exists'] msg = msg % {'username': uname} assertr.element_contains('#username+.error-message', msg)
def test_register_err_case_sensitive(self): usr = '******' response = self.app.post( register_url, { 'username': usr, 'password': '******', 'password_confirmation': 'test12', 'email': 'goodmailm', 'firstname': 'test', 'lastname': 'test' }) assertr = AssertResponse(response) msg = validators.ValidUsername()._messages['username_exists'] msg = msg % {'username': usr} assertr.element_contains('#username+.error-message', msg)
def test_index_filtered_by_wrong_branch(self, backend): self.log_user() branch = 'wrong-branch-name' response = self.app.get( url( controller='changelog', action='index', repo_name=backend.repo_name, branch=branch), status=302) expected_url = '/{repo}/changelog/{branch}'.format( repo=backend.repo_name, branch=branch) assert expected_url in response.location response = response.follow() expected_warning = 'Branch {} is not found.'.format(branch) assert_response = AssertResponse(response) assert_response.element_contains('.alert-warning', expected_warning)
def test_tag_is_not_a_link(self, pr_util): pull_request = pr_util.create_pull_request() pull_request.source_ref = 'tag:origin:1234567890abcdef' pull_request.target_ref = 'tag:target:abcdef1234567890' Session().add(pull_request) Session().commit() response = self.app.get(url( controller='pullrequests', action='show', repo_name=pull_request.target_repo.scm_instance().name, pull_request_id=str(pull_request.pull_request_id))) assert response.status_int == 200 assert_response = AssertResponse(response) origin = assert_response.get_element('.pr-origininfo .tag') assert origin.text.strip() == 'tag: origin' assert origin.getchildren() == [] target = assert_response.get_element('.pr-targetinfo .tag') assert target.text.strip() == 'tag: target' assert target.getchildren() == []
def test_strip_commits_and_update( self, backend, pr_util, csrf_token): commits = [ {'message': 'initial-commit'}, {'message': 'old-feature'}, {'message': 'new-feature', 'parents': ['old-feature']}, ] pull_request = pr_util.create_pull_request( commits, target_head='old-feature', source_head='new-feature', revisions=['new-feature'], mergeable=True) vcs = pr_util.source_repository.scm_instance() if backend.alias == 'git': vcs.strip(pr_util.commit_ids['new-feature'], branch_name='master') else: vcs.strip(pr_util.commit_ids['new-feature']) response = self.app.post( url(controller='pullrequests', action='update', repo_name=pull_request.target_repo.repo_name, pull_request_id=str(pull_request.pull_request_id)), params={'update_commits': 'true', '_method': 'put', 'csrf_token': csrf_token}) assert response.status_int == 200 assert response.body == 'true' # Make sure that after update, it won't raise 500 errors response = self.app.get(url( controller='pullrequests', action='show', repo_name=pr_util.target_repository.repo_name, pull_request_id=str(pull_request.pull_request_id))) assert response.status_int == 200 assert_response = AssertResponse(response) assert_response.element_contains( '#changeset_compare_view_content .alert strong', 'Missing commits')
def test_user_profile(self): edit_link_css = '.user-profile .panel-edit' self.log_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS) user = fixture.create_user(self.test_user_1, password='******', email='*****@*****.**') Session().commit() self.destroy_users.add(self.test_user_1) response = self.app.get(url('user_profile', username=user.username)) response.mustcontain('testme') response.mustcontain('*****@*****.**') assert_response = AssertResponse(response) assert_response.no_element_exists(edit_link_css) # edit should be available to superadmin users self.logout_user() self.log_user(TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS) response = self.app.get(url('user_profile', username=user.username)) assert_response = AssertResponse(response) assert_response.element_contains(edit_link_css, 'Edit')
def test_index_shows_missing_requirements_message( self, backend, autologin_user): repo_name = backend.repo_name scm_patcher = mock.patch.object( Repository, 'scm_instance', side_effect=RepositoryRequirementError) with scm_patcher: response = self.app.get(url('summary_home', repo_name=repo_name)) assert_response = AssertResponse(response) assert_response.element_contains( '.main .alert-warning strong', 'Missing requirements') assert_response.element_contains( '.main .alert-warning', 'These commits cannot be displayed, because this repository' ' uses the Mercurial largefiles extension, which was not enabled.')
def test_file_source(self, backend): commit = backend.repo.get_commit(commit_idx=167) response = self.app.get(url( controller='files', action='index', repo_name=backend.repo_name, revision=commit.raw_id, f_path='vcs/nodes.py')) msgbox = """<div class="commit right-content">%s</div>""" response.mustcontain(msgbox % (commit.message, )) assert_response = AssertResponse(response) if commit.branch: assert_response.element_contains('.tags.tags-main .branchtag', commit.branch) if commit.tags: for tag in commit.tags: assert_response.element_contains('.tags.tags-main .tagtag', tag)
def test_remove_pull_request_branch(self, backend_git, csrf_token): branch_name = 'development' commits = [ {'message': 'initial-commit'}, {'message': 'old-feature'}, {'message': 'new-feature', 'branch': branch_name}, ] repo = backend_git.create_repo(commits) commit_ids = backend_git.commit_ids pull_request = PullRequest() pull_request.source_repo = repo pull_request.target_repo = repo pull_request.source_ref = 'branch:{branch}:{commit_id}'.format( branch=branch_name, commit_id=commit_ids['new-feature']) pull_request.target_ref = 'branch:{branch}:{commit_id}'.format( branch=backend_git.default_branch_name, commit_id=commit_ids['old-feature']) pull_request.revisions = [commit_ids['new-feature']] pull_request.title = u"Test" pull_request.description = u"Description" pull_request.author = UserModel().get_by_username( TEST_USER_ADMIN_LOGIN) Session().add(pull_request) Session().commit() vcs = repo.scm_instance() vcs.remove_ref('refs/heads/{}'.format(branch_name)) response = self.app.get(url( controller='pullrequests', action='show', repo_name=repo.repo_name, pull_request_id=str(pull_request.pull_request_id))) assert response.status_int == 200 assert_response = AssertResponse(response) assert_response.element_contains( '#changeset_compare_view_content .alert strong', 'Missing commits') assert_response.element_contains( '#changeset_compare_view_content .alert', 'This pull request cannot be displayed, because one or more' ' commits no longer exist in the source repository.')
def test_records_are_displayed(self, autologin_user): sample_licenses = { "python2.7-pytest-2.7.1": { "UNKNOWN": None }, "python2.7-Markdown-2.6.2": { "BSD-3-Clause": "http://spdx.org/licenses/BSD-3-Clause" } } read_licenses_patch = mock.patch( 'rhodecode.admin.views.read_opensource_licenses', return_value=sample_licenses) with read_licenses_patch: response = self.app.get(self._get_url(), status=200) assert_response = AssertResponse(response) assert_response.element_contains( '.panel-heading', 'Licenses of Third Party Packages') for name in sample_licenses: response.mustcontain(name) for license in sample_licenses[name]: assert_response.element_contains('.panel-body', license)
def test_records_can_be_read(self, autologin_user): response = self.app.get(self._get_url(), status=200) assert_response = AssertResponse(response) assert_response.element_contains( '.panel-heading', 'Licenses of Third Party Packages')
def test_has_an_input_for_invalidation_of_inline_comments( self, app): response = app.get(url('admin_settings_vcs')) assert_response = AssertResponse(response) assert_response.one_element_exists( '[name=rhodecode_use_outdated_comments]')
def test_index(self): self.log_user() response = self.app.get(url(controller='search', action='index')) assert_response = AssertResponse(response) assert_response.one_element_exists('input#q')
def test_logout_form_contains_csrf(self, autologin_user, csrf_token): response = self.app.get(url('my_account')) assert_response = AssertResponse(response) element = assert_response.get_element('.logout #csrf_token') assert element.value == csrf_token