from rhodecode.tests import * from rhodecode.model.repo import RepoModel from rhodecode.model.meta import Session from rhodecode.model.db import Repository from rhodecode.model.scm import ScmModel from rhodecode.lib.vcs.backends.base import EmptyChangeset class TestCompareController(TestController): def test_index_tag(self): self.log_user() tag1 = '0.1.3' tag2 = '0.1.2' response = self.app.get(url(controller='compare', action='index', repo_name=HG_REPO, org_ref_type="tag", org_ref=tag1, other_ref_type="tag", other_ref=tag2, )) response.mustcontain('%s@%s -> %s@%s' % (HG_REPO, tag1, HG_REPO, tag2)) ## outgoing changesets between tags response.mustcontain('''r120:17544fbfcd33''' % HG_REPO) response.mustcontain('''r119:36e0fc9d2808''' % HG_REPO) response.mustcontain('''r118:bb1a3ab98cc4''' % HG_REPO) response.mustcontain('''r117:41fda979f02f''' % HG_REPO) response.mustcontain('''r116:9749bfbfc0d2''' % HG_REPO) response.mustcontain('''r115:70d4cef8a376''' % HG_REPO) response.mustcontain('''r112:c5ddebc06eaa''' % HG_REPO) ## files diff response.mustcontain('''
docs/api/utils/index.rst
''' % (HG_REPO, tag1, tag2)) response.mustcontain('''
test_and_report.sh
''' % (HG_REPO, tag1, tag2)) response.mustcontain('''
.hgignore
''' % (HG_REPO, tag1, tag2)) response.mustcontain('''
.hgtags
''' % (HG_REPO, tag1, tag2)) response.mustcontain('''
docs/api/index.rst
''' % (HG_REPO, tag1, tag2)) response.mustcontain('''
vcs/__init__.py
''' % (HG_REPO, tag1, tag2)) response.mustcontain('''
vcs/backends/hg.py
''' % (HG_REPO, tag1, tag2)) response.mustcontain('''
vcs/utils/__init__.py
''' % (HG_REPO, tag1, tag2)) response.mustcontain('''
vcs/utils/annotate.py
''' % (HG_REPO, tag1, tag2)) response.mustcontain('''
vcs/utils/diffs.py
''' % (HG_REPO, tag1, tag2)) response.mustcontain('''
vcs/utils/lazy.py
''' % (HG_REPO, tag1, tag2)) def test_index_branch(self): self.log_user() response = self.app.get(url(controller='compare', action='index', repo_name=HG_REPO, org_ref_type="branch", org_ref='default', other_ref_type="branch", other_ref='default', )) response.mustcontain('%s@default -> %s@default' % (HG_REPO, HG_REPO)) # branch are equal response.mustcontain('No changesets') def test_compare_revisions(self): self.log_user() rev1 = '3d8f361e72ab' rev2 = 'b986218ba1c9' response = self.app.get(url(controller='compare', action='index', repo_name=HG_REPO, org_ref_type="rev", org_ref=rev1, other_ref_type="rev", other_ref=rev2, )) response.mustcontain('%s@%s -> %s@%s' % (HG_REPO, rev1, HG_REPO, rev2)) ## outgoing changesets between those revisions response.mustcontain("""r1:%s""" % (HG_REPO, rev1)) ## files response.mustcontain(""".hgignore""" % (HG_REPO, rev1, rev2)) def test_compare_remote_repos(self): self.log_user() form_data = dict( repo_name=HG_FORK, repo_name_full=HG_FORK, repo_group=None, repo_type='hg', description='', private=False, copy_permissions=False, landing_rev='tip', update_after_clone=False, fork_parent_id=Repository.get_by_repo_name(HG_REPO), ) RepoModel().create_fork(form_data, cur_user=TEST_USER_ADMIN_LOGIN) Session().commit() rev1 = '7d4bc8ec6be5' rev2 = '56349e29c2af' response = self.app.get(url(controller='compare', action='index', repo_name=HG_REPO, org_ref_type="rev", org_ref=rev1, other_ref_type="rev", other_ref=rev2, repo=HG_FORK )) try: response.mustcontain('%s@%s -> %s@%s' % (HG_REPO, rev1, HG_FORK, rev2)) ## outgoing changesets between those revisions response.mustcontain("""r6:%s""" % (HG_REPO, rev1)) response.mustcontain("""r5:6fff84722075""" % (HG_REPO)) response.mustcontain("""r4:2dda4e345fac""" % (HG_REPO)) ## files response.mustcontain("""vcs/backends/hg.py""" % (HG_REPO, rev1, rev2)) response.mustcontain("""vcs/backends/__init__.py""" % (HG_REPO, rev1, rev2)) response.mustcontain("""vcs/backends/base.py""" % (HG_REPO, rev1, rev2)) finally: RepoModel().delete(HG_FORK) def test_compare_extra_commits(self): self.log_user() repo1 = RepoModel().create_repo(repo_name='one', repo_type='hg', description='diff-test', owner=TEST_USER_ADMIN_LOGIN) repo2 = RepoModel().create_repo(repo_name='one-fork', repo_type='hg', description='diff-test', owner=TEST_USER_ADMIN_LOGIN) Session().commit() r1_id = repo1.repo_id r1_name = repo1.repo_name r2_id = repo2.repo_id r2_name = repo2.repo_name #commit something ! cs0 = ScmModel().create_node( repo=repo1.scm_instance, repo_name=r1_name, cs=EmptyChangeset(alias='hg'), user=TEST_USER_ADMIN_LOGIN, author=TEST_USER_ADMIN_LOGIN, message='commit1', content='line1', f_path='file1' ) cs0_prim = ScmModel().create_node( repo=repo2.scm_instance, repo_name=r2_name, cs=EmptyChangeset(alias='hg'), user=TEST_USER_ADMIN_LOGIN, author=TEST_USER_ADMIN_LOGIN, message='commit1', content='line1', f_path='file1' ) cs1 = ScmModel().commit_change( repo=repo2.scm_instance, repo_name=r2_name, cs=cs0_prim, user=TEST_USER_ADMIN_LOGIN, author=TEST_USER_ADMIN_LOGIN, message='commit2', content='line1\nline2', f_path='file1' ) rev1 = 'default' rev2 = 'default' response = self.app.get(url(controller='compare', action='index', repo_name=r2_name, org_ref_type="branch", org_ref=rev1, other_ref_type="branch", other_ref=rev2, repo=r1_name )) try: response.mustcontain('%s@%s -> %s@%s' % (r2_name, rev1, r1_name, rev2)) response.mustcontain("""
commit2
""") response.mustcontain("""r1:%s""" % (r2_name, cs1.raw_id, cs1.short_id)) ## files response.mustcontain("""file1""" % (r2_name, rev1, rev2)) finally: RepoModel().delete(r1_id) RepoModel().delete(r2_id) def test_org_repo_new_commits_after_forking(self): self.log_user() repo1 = RepoModel().create_repo(repo_name='one', repo_type='hg', description='diff-test', owner=TEST_USER_ADMIN_LOGIN) Session().commit() r1_id = repo1.repo_id r1_name = repo1.repo_name #commit something initially ! cs0 = ScmModel().create_node( repo=repo1.scm_instance, repo_name=r1_name, cs=EmptyChangeset(alias='hg'), user=TEST_USER_ADMIN_LOGIN, author=TEST_USER_ADMIN_LOGIN, message='commit1', content='line1', f_path='file1' ) Session().commit() self.assertEqual(repo1.scm_instance.revisions, [cs0.raw_id]) #fork the repo1 repo2 = RepoModel().create_repo(repo_name='one-fork', repo_type='hg', description='compare-test', clone_uri=repo1.repo_full_path, owner=TEST_USER_ADMIN_LOGIN, fork_of='one') Session().commit() self.assertEqual(repo2.scm_instance.revisions, [cs0.raw_id]) r2_id = repo2.repo_id r2_name = repo2.repo_name #make 3 new commits in fork cs1 = ScmModel().create_node( repo=repo2.scm_instance, repo_name=r2_name, cs=repo2.scm_instance[-1], user=TEST_USER_ADMIN_LOGIN, author=TEST_USER_ADMIN_LOGIN, message='commit1-fork', content='file1-line1-from-fork', f_path='file1-fork' ) cs2 = ScmModel().create_node( repo=repo2.scm_instance, repo_name=r2_name, cs=cs1, user=TEST_USER_ADMIN_LOGIN, author=TEST_USER_ADMIN_LOGIN, message='commit2-fork', content='file2-line1-from-fork', f_path='file2-fork' ) cs3 = ScmModel().create_node( repo=repo2.scm_instance, repo_name=r2_name, cs=cs2, user=TEST_USER_ADMIN_LOGIN, author=TEST_USER_ADMIN_LOGIN, message='commit3-fork', content='file3-line1-from-fork', f_path='file3-fork' ) #compare ! rev1 = 'default' rev2 = 'default' response = self.app.get(url(controller='compare', action='index', repo_name=r2_name, org_ref_type="branch", org_ref=rev1, other_ref_type="branch", other_ref=rev2, repo=r1_name )) try: response.mustcontain('%s@%s -> %s@%s' % (r2_name, rev1, r1_name, rev2)) response.mustcontain("""file1-line1-from-fork""") response.mustcontain("""file2-line1-from-fork""") response.mustcontain("""file3-line1-from-fork""") #add new commit into parent ! cs0 = ScmModel().create_node( repo=repo1.scm_instance, repo_name=r1_name, cs=EmptyChangeset(alias='hg'), user=TEST_USER_ADMIN_LOGIN, author=TEST_USER_ADMIN_LOGIN, message='commit2', content='line1', f_path='file2' ) #compare ! rev1 = 'default' rev2 = 'default' response = self.app.get(url(controller='compare', action='index', repo_name=r2_name, org_ref_type="branch", org_ref=rev1, other_ref_type="branch", other_ref=rev2, repo=r1_name )) response.mustcontain('%s@%s -> %s@%s' % (r2_name, rev1, r1_name, rev2)) response.mustcontain("""file1-line1-from-fork""") response.mustcontain("""file2-line1-from-fork""") response.mustcontain("""file3-line1-from-fork""") finally: RepoModel().delete(r2_id) RepoModel().delete(r1_id)