def test_raw_wrong_cs(self, backend):
        commit_id = u'ERRORcce30c96924232dffcd24178a07ffeb5dfc'
        f_path = 'vcs/nodes.py'

        response = self.app.get(url(controller='files', action='raw',
                                    repo_name=backend.repo_name,
                                    revision=commit_id,
                                    f_path=f_path), status=404)

        msg = """No such commit exists for this repository"""
        response.mustcontain(msg)
Ejemplo n.º 2
0
    def test_repo_refs_data(self, backend):
        response = self.app.get(
            url('repo_refs_data', repo_name=backend.repo_name),
            status=200)

        # Ensure that there is the correct amount of items in the result
        repo = backend.repo.scm_instance()
        data = response.json['results']
        items = sum(len(section['children']) for section in data)
        repo_refs = len(repo.branches) + len(repo.tags) + len(repo.bookmarks)
        assert items == repo_refs
    def test_archival_wrong_ext(self, backend):
        backend.enable_downloads()
        commit = backend.repo.get_commit(commit_idx=173)
        for arch_ext in ['tar', 'rar', 'x', '..ax', '.zipz']:
            fname = commit.raw_id + arch_ext

            response = self.app.get(url(controller='files',
                                        action='archivefile',
                                        repo_name=backend.repo_name,
                                        fname=fname))
            response.mustcontain('Unknown archive type')
    def test_my_account_update(self, name, attrs):
        usr = fixture.create_user(self.test_user_1,
                                  password='******',
                                  email='*****@*****.**',
                                  extern_type='rhodecode',
                                  extern_name=self.test_user_1,
                                  skip_if_exists=True)
        self.destroy_users.add(self.test_user_1)

        params = usr.get_api_data()  # current user data
        user_id = usr.user_id
        self.log_user(username=self.test_user_1, password='******')

        params.update({'password_confirmation': ''})
        params.update({'new_password': ''})
        params.update({'extern_type': 'rhodecode'})
        params.update({'extern_name': self.test_user_1})
        params.update({'csrf_token': self.csrf_token})

        params.update(attrs)
        # my account page cannot set language param yet, only for admins
        del params['language']
        response = self.app.post(url('my_account'), params)

        assert_session_flash(response, 'Your account was updated successfully')

        del params['csrf_token']

        updated_user = User.get_by_username(self.test_user_1)
        updated_params = updated_user.get_api_data()
        updated_params.update({'password_confirmation': ''})
        updated_params.update({'new_password': ''})

        params['last_login'] = updated_params['last_login']
        # my account page cannot set language param yet, only for admins
        # but we get this info from API anyway
        params['language'] = updated_params['language']

        if name == 'email':
            params['emails'] = [attrs['email']]
        if name == 'extern_type':
            # cannot update this via form, expected value is original one
            params['extern_type'] = "rhodecode"
        if name == 'extern_name':
            # cannot update this via form, expected value is original one
            params['extern_name'] = str(user_id)
        if name == 'active':
            # my account cannot deactivate account
            params['active'] = True
        if name == 'admin':
            # my account cannot make you an admin !
            params['admin'] = False

        assert params == updated_params
    def test_archival_wrong_commit_id(self, backend):
        backend.enable_downloads()
        for commit_id in ['00x000000', 'tar', 'wrong', '@##$@$42413232',
                          '232dffcd']:
            fname = '%s.zip' % commit_id

            response = self.app.get(url(controller='files',
                                        action='archivefile',
                                        repo_name=backend.repo_name,
                                        fname=fname))
            response.mustcontain('Unknown revision')
def test_update_fails_when_parent_pointing_to_self(app, csrf_token, user_util,
                                                   autologin_user):
    group = user_util.create_repo_group()
    response = app.post(
        url('update_repo_group', group_name=group.group_name),
        fixture._get_group_create_params(group_parent_id=group.group_id,
                                         csrf_token=csrf_token,
                                         _method='PUT'))
    response.mustcontain('<select class="medium error" id="group_parent_id"'
                         ' name="group_parent_id">')
    response.mustcontain('<span class="error-message">Value must be one of:')
    def test_file_annotation(self, backend):
        response = self.app.get(url(
            controller='files', action='index',
            repo_name=backend.repo_name, revision='tip', f_path='vcs/nodes.py',
            annotate=True))

        expected_revisions = {
            'hg': 'r356:25213a5fbb04',
            'git': 'r345:c994f0de03b2',
            'svn': 'r208:209',
        }
        response.mustcontain(expected_revisions[backend.alias])
    def test_password_is_updated_in_session_on_password_change(
            self, user_util):
        old_password = '******'
        new_password = '******'

        user = user_util.create_user(password=old_password)
        session = self.log_user(user.username, old_password)
        old_password_hash = session['password']

        form_data = {
            'current_password': old_password,
            'new_password': new_password,
            'new_password_confirmation': new_password,
            'csrf_token': self.csrf_token
        }
        self.app.post(url('my_account_password'), form_data)

        response = self.app.get(url('home'))
        new_password_hash = response.session['rhodecode_user']['password']

        assert old_password_hash != new_password_hash
    def test_reviewer_notifications(self, backend, csrf_token):
        # We have to use the app.post for this test so it will create the
        # notifications properly with the new PR
        commits = [
            {'message': 'ancestor',
             'added': [FileNode('file_A', content='content_of_ancestor')]},
            {'message': 'change',
             'added': [FileNode('file_a', content='content_of_change')]},
            {'message': 'change-child'},
            {'message': 'ancestor-child', 'parents': ['ancestor'],
             'added': [
                FileNode('file_B', content='content_of_ancestor_child')]},
            {'message': 'ancestor-child-2'},
        ]
        commit_ids = backend.create_master_repo(commits)
        target = backend.create_repo(heads=['ancestor-child'])
        source = backend.create_repo(heads=['change'])

        response = self.app.post(
            url(
                controller='pullrequests',
                action='create',
                repo_name=source.repo_name),
            params={
                'source_repo': source.repo_name,
                'source_ref': 'branch:default:' + commit_ids['change'],
                'target_repo': target.repo_name,
                'target_ref': 'branch:default:' + commit_ids['ancestor-child'],
                'pullrequest_desc': 'Description',
                'pullrequest_title': 'Title',
                'review_members': '2',
                'revisions': commit_ids['change'],
                'user': '',
                'csrf_token': csrf_token,
            },
            status=302)

        location = response.headers['Location']
        pull_request_id = int(location.rsplit('/', 1)[1])
        pull_request = PullRequest.get(pull_request_id)

        # Check that a notification was made
        notifications = Notification.query()\
            .filter(Notification.created_by == pull_request.author.user_id,
                    Notification.type_ == Notification.TYPE_PULL_REQUEST,
                    Notification.subject.contains("wants you to review "
                                                  "pull request #%d"
                                                  % pull_request_id))
        assert len(notifications.all()) == 1

        # Change reviewers and check that a notification was made
        PullRequestModel().update_reviewers(pull_request.pull_request_id, [1])
        assert len(notifications.all()) == 2
Ejemplo n.º 10
0
    def test_tree_metadata_list_success(self, backend, xhr_header):
        commit = backend.repo.get_commit(commit_idx=173)
        response = self.app.get(
            url('files_metadata_list_home', repo_name=backend.repo_name,
                f_path='/', revision=commit.raw_id),
            extra_environ=xhr_header)

        expected_keys = ['author', 'message', 'modified_at', 'modified_ts',
                         'name', 'revision', 'short_id', 'size']
        for filename in response.json.get('metadata'):
            for key in expected_keys:
                assert key in filename
Ejemplo n.º 11
0
 def test_index_svn_without_proxy(self, backend_svn):
     self.log_user()
     repo_id = backend_svn.repo.repo_id
     repo_name = backend_svn.repo_name
     response = self.app.get(url('summary_home', repo_name=repo_name))
     # clone url...
     response.mustcontain(
         'id="clone_url" disabled'
         ' value="http://[email protected]:80/%s"' % (repo_name, ))
     response.mustcontain(
         'id="clone_url_id" disabled'
         ' value="http://[email protected]:80/_%s"' % (repo_id, ))
    def test_create_custom_hook_delete(self, csrf_token):
        response = self.app.post(
            url('admin_settings_hooks'),
            params={
                'new_hook_ui_key': 'test_hooks_2',
                'new_hook_ui_value': 'cd /tmp2',
                'csrf_token': csrf_token})

        response = response.follow()
        response.mustcontain('test_hooks_2')
        response.mustcontain('cd /tmp2')

        hook_id = SettingsModel().get_ui_by_key('test_hooks_2').ui_id

        # delete
        self.app.post(
            url('admin_settings_hooks'),
            params={'hook_id': hook_id, 'csrf_token': csrf_token})
        response = self.app.get(url('admin_settings_hooks'))
        response.mustcontain(no=['test_hooks_2'])
        response.mustcontain(no=['cd /tmp2'])
    def test_index_pagination(self, backend):
        self.log_user()
        # pagination, walk up to page 6
        changelog_url = url(
            controller='changelog', action='index',
            repo_name=backend.repo_name)
        for page in range(1, 7):
            response = self.app.get(changelog_url, {'page': page})

        first_idx = -DEFAULT_CHANGELOG_SIZE * (page - 1) - 1
        last_idx = -DEFAULT_CHANGELOG_SIZE * page
        self.assert_commit_range_on_page(response, first_idx, last_idx, backend)
    def test_index_filtered_by_branch_svn(self, autologin_user, backend):
        repo = backend['svn-simple-layout']
        response = self.app.get(
            url(
                controller='changelog',
                action='index',
                repo_name=repo.repo_name,
                branch='trunk'),
            status=200)

        self.assert_commits_on_page(
            response, indexes=[15, 12, 7, 3, 2, 1])
    def test_search_commit_messages(
            self, query, expected_hits, expected_commits, enabled_backends):
        self.log_user()
        response = self.app.get(
            url(controller='search', action='index'), {'q': query,
                                                       'type': 'commit',
                                                       'page_limit': 500})

        response.mustcontain('%s results' % expected_hits)
        for backend, commit_id in expected_commits:
            if backend in enabled_backends:
                response.mustcontain(commit_id)
    def test_index_closed_branches(self, autologin_user, backend):
        repo = backend['closed_branch']
        response = self.app.get(
            url(
                controller='changelog',
                action='index',
                repo_name=repo.repo_name,
                branch='experimental'),
            status=200)

        self.assert_commits_on_page(
            response, indexes=[3, 1])
    def test_delete_svn_patterns(
            self, section, app, csrf_token, settings_util):
        setting = settings_util.create_rhodecode_ui(
            section, '/test_delete', cleanup=False)

        app.post(
            url('admin_settings_vcs'),
            params={
                '_method': 'delete',
                'delete_svn_pattern': setting.ui_id,
                'csrf_token': csrf_token},
            headers={'X-REQUESTED-WITH': 'XMLHttpRequest'})
    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')
Ejemplo n.º 19
0
    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')
Ejemplo n.º 20
0
    def test_raw_file_wrong_f_path(self, backend):
        commit = backend.repo.get_commit(commit_idx=173)
        f_path = 'vcs/ERRORnodes.py'
        response = self.app.get(url(controller='files', action='rawfile',
                                    repo_name=backend.repo_name,
                                    revision=commit.raw_id,
                                    f_path=f_path), status=404)

        msg = (
            "There is no file nor directory at the given path: "
            "&#39;%s&#39; at commit %s" % (f_path, commit.short_id))
        response.mustcontain(msg)
 def test_system_update_nothing_new(self):
     update_data = {
         'versions': [
             {
                 'version': '0.0.0',
                 'general': 'The first version we ever shipped'
             }
         ]
     }
     with mock.patch(UPDATE_DATA_QUALNAME, return_value=update_data):
         response = self.app.get(url('admin_settings_system_update'))
         response.mustcontain(
             'You already have the <b>latest</b> stable version.')
 def test_create_with_path_with_dirs(self):
     self.log_user()
     response = self.app.post(url('gists'),
                              params={
                                  'lifetime': -1,
                                  'content': 'gist test',
                                  'filename': '/home/foo',
                                  'public': 'public',
                                  'acl_level': Gist.ACL_LEVEL_PUBLIC,
                                  'csrf_token': self.csrf_token
                              },
                              status=200)
     response.mustcontain('Filename cannot be inside a directory')
    def test_index_show_all_hidden_from_regular(self, create_gist):
        self.log_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS)
        create_gist('gist2', gist_type='private')
        create_gist('gist3', gist_type='private')
        create_gist('gist4', gist_type='private')

        response = self.app.get(url('gists', all=1))

        assert len(GistModel.get_all()) == 3
        # since we don't have access to private in this view, we
        # should see nothing
        for gist in GistModel.get_all():
            response.mustcontain(no=['gist: %s' % gist.gist_access_id])
    def test_index_show_all(self, create_gist):
        self.log_user()
        create_gist('gist1')
        create_gist('gist2', lifetime=1400)
        create_gist('gist3', description='gist3-desc')
        create_gist('gist4', gist_type='private')

        response = self.app.get(url('gists', all=1))

        assert len(GistModel.get_all()) == 4
        # and privates
        for gist in GistModel.get_all():
            response.mustcontain('gist: %s' % gist.gist_access_id)
Ejemplo n.º 25
0
    def test_delete_file_view_not_on_branch(self, backend):
        repo = backend.create_repo()
        backend.ensure_file('vcs/nodes.py')

        response = self.app.get(
            url(
                'files_delete_home',
                repo_name=repo.repo_name,
                revision='tip', f_path='vcs/nodes.py'),
            status=302)
        assert_session_flash(
            response,
            'You can only delete files with revision being a valid branch')
def test_update(app, csrf_token, autologin_user, user_util):
    repo_group = user_util.create_repo_group()
    description = 'description for newly created repo group'
    Session().commit()
    response = app.post(
        url('update_repo_group', group_name=repo_group.group_name),
        fixture._get_group_create_params(group_name=repo_group.group_name,
                                         group_description=description,
                                         csrf_token=csrf_token,
                                         _method='PUT'))
    # TODO: anderson: johbo: we believe that this update should return
    # a redirect instead of rendering the template.
    assert response.status_code == 200
Ejemplo n.º 27
0
    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')
Ejemplo n.º 28
0
    def test_file_source_history_svn(self, backend_svn):
        simple_repo = backend_svn['svn-simple-layout']
        response = self.app.get(
            url(
                controller='files', action='history',
                repo_name=simple_repo.repo_name,
                revision='tip',
                f_path='trunk/example.py'),
            extra_environ={'HTTP_X_PARTIAL_XHR': '1'})

        expected_data = json.loads(
            fixture.load_resource('svn_node_history_branches.json'))
        assert expected_data == response.json
Ejemplo n.º 29
0
    def test_add_file_into_repo_missing_filename(self, backend, csrf_token):
        response = self.app.post(
            url(
                'files_add',
                repo_name=backend.repo_name,
                revision='tip', f_path='/'),
            params={
                'content': "foo",
                'csrf_token': csrf_token,
            },
            status=302)

        assert_session_flash(response, 'No filename')
    def test_user_with_creation_permissions_cannot_create_subgroups(
            self, user_util):

        user_util.grant_user_permission(TEST_USER_REGULAR_LOGIN,
                                        'hg.repogroup.create.true')
        parent_group = user_util.create_repo_group()
        parent_group_id = parent_group.group_id
        self.log_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS)
        self.app.get(url(
            'new_repo_group',
            parent_group=parent_group_id,
        ),
                     status=403)