Show More
@@ -28,9 +28,13 b' from rhodecode.lib import helpers as h' | |||
|
28 | 28 | from rhodecode.lib.compat import OrderedDict |
|
29 | 29 | from rhodecode.lib.ext_json import json |
|
30 | 30 | from rhodecode.lib.vcs import nodes |
|
31 | from rhodecode.lib.vcs.backends.base import EmptyCommit | |
|
31 | 32 | from rhodecode.lib.vcs.conf import settings |
|
33 | from rhodecode.lib.vcs.nodes import FileNode | |
|
34 | from rhodecode.model.db import Repository | |
|
35 | from rhodecode.model.scm import ScmModel | |
|
32 | 36 | from rhodecode.tests import ( |
|
33 | url, assert_session_flash, assert_not_in_session_flash) | |
|
37 | url, TEST_USER_ADMIN_LOGIN, assert_session_flash, assert_not_in_session_flash) | |
|
34 | 38 | from rhodecode.tests.fixture import Fixture |
|
35 | 39 | from rhodecode.tests.utils import AssertResponse |
|
36 | 40 | |
@@ -43,6 +47,41 b' NODE_HISTORY = {' | |||
|
43 | 47 | } |
|
44 | 48 | |
|
45 | 49 | |
|
50 | ||
|
51 | def _commit_change( | |
|
52 | repo, filename, content, message, vcs_type, parent=None, | |
|
53 | newfile=False): | |
|
54 | repo = Repository.get_by_repo_name(repo) | |
|
55 | _commit = parent | |
|
56 | if not parent: | |
|
57 | _commit = EmptyCommit(alias=vcs_type) | |
|
58 | ||
|
59 | if newfile: | |
|
60 | nodes = { | |
|
61 | filename: { | |
|
62 | 'content': content | |
|
63 | } | |
|
64 | } | |
|
65 | commit = ScmModel().create_nodes( | |
|
66 | user=TEST_USER_ADMIN_LOGIN, repo=repo, | |
|
67 | message=message, | |
|
68 | nodes=nodes, | |
|
69 | parent_commit=_commit, | |
|
70 | author=TEST_USER_ADMIN_LOGIN, | |
|
71 | ) | |
|
72 | else: | |
|
73 | commit = ScmModel().commit_change( | |
|
74 | repo=repo.scm_instance(), repo_name=repo.repo_name, | |
|
75 | commit=parent, user=TEST_USER_ADMIN_LOGIN, | |
|
76 | author=TEST_USER_ADMIN_LOGIN, | |
|
77 | message=message, | |
|
78 | content=content, | |
|
79 | f_path=filename | |
|
80 | ) | |
|
81 | return commit | |
|
82 | ||
|
83 | ||
|
84 | ||
|
46 | 85 | @pytest.mark.usefixtures("app") |
|
47 | 86 | class TestFilesController: |
|
48 | 87 | |
@@ -940,3 +979,100 b' def _assert_items_in_response(response, ' | |||
|
940 | 979 | def assert_timeago_in_response(response, items, params): |
|
941 | 980 | for item in items: |
|
942 | 981 | response.mustcontain(h.age_component(params['date'])) |
|
982 | ||
|
983 | ||
|
984 | ||
|
985 | @pytest.mark.usefixtures("autologin_user", "app") | |
|
986 | class TestSideBySideDiff: | |
|
987 | ||
|
988 | def test_diff2way(self, app, backend, backend_stub): | |
|
989 | f_path = 'content' | |
|
990 | commit1_content = 'content-25d7e49c18b159446c' | |
|
991 | commit2_content = 'content-603d6c72c46d953420' | |
|
992 | repo = backend.create_repo() | |
|
993 | ||
|
994 | commit1 = _commit_change( | |
|
995 | repo.repo_name, filename=f_path, content=commit1_content, | |
|
996 | message='A', vcs_type=backend.alias, parent=None, newfile=True) | |
|
997 | ||
|
998 | commit2 = _commit_change( | |
|
999 | repo.repo_name, filename=f_path, content=commit2_content, | |
|
1000 | message='B, child of A', vcs_type=backend.alias, parent=commit1) | |
|
1001 | ||
|
1002 | response = self.app.get(url( | |
|
1003 | controller='files', action='diff_2way', | |
|
1004 | repo_name=repo.repo_name, | |
|
1005 | diff1=commit1.raw_id, | |
|
1006 | diff2=commit2.raw_id, | |
|
1007 | f_path=f_path)) | |
|
1008 | ||
|
1009 | assert_response = AssertResponse(response) | |
|
1010 | response.mustcontain( | |
|
1011 | ('Side-by-side Diff r0:%s ... r1:%s') % ( commit1.short_id, commit2.short_id )) | |
|
1012 | response.mustcontain('id="compare"') | |
|
1013 | response.mustcontain(( | |
|
1014 | "var orig1_url = '/%s/raw/%s/%s';\n" | |
|
1015 | "var orig2_url = '/%s/raw/%s/%s';") % | |
|
1016 | ( repo.repo_name, commit1.raw_id, f_path, | |
|
1017 | repo.repo_name, commit2.raw_id, f_path)) | |
|
1018 | ||
|
1019 | ||
|
1020 | def test_diff2way_with_empty_file(self, app, backend, backend_stub): | |
|
1021 | commits = [ | |
|
1022 | {'message': 'First commit'}, | |
|
1023 | {'message': 'Commit with binary', | |
|
1024 | 'added': [nodes.FileNode('file.empty', content='')]}, | |
|
1025 | ] | |
|
1026 | f_path='file.empty' | |
|
1027 | repo = backend.create_repo(commits=commits) | |
|
1028 | commit_id1 = repo.get_commit(commit_idx=0).raw_id | |
|
1029 | commit_id2 = repo.get_commit(commit_idx=1).raw_id | |
|
1030 | ||
|
1031 | response = self.app.get(url( | |
|
1032 | controller='files', action='diff_2way', | |
|
1033 | repo_name=repo.repo_name, | |
|
1034 | diff1=commit_id1, | |
|
1035 | diff2=commit_id2, | |
|
1036 | f_path=f_path)) | |
|
1037 | ||
|
1038 | assert_response = AssertResponse(response) | |
|
1039 | if backend.alias == 'svn': | |
|
1040 | assert_session_flash( response, | |
|
1041 | ('%(file_path)s has not changed') % { 'file_path': 'file.empty' }) | |
|
1042 | else: | |
|
1043 | response.mustcontain( | |
|
1044 | ('Side-by-side Diff r0:%s ... r1:%s') % ( repo.get_commit(commit_idx=0).short_id, repo.get_commit(commit_idx=1).short_id )) | |
|
1045 | response.mustcontain('id="compare"') | |
|
1046 | response.mustcontain(( | |
|
1047 | "var orig1_url = '/%s/raw/%s/%s';\n" | |
|
1048 | "var orig2_url = '/%s/raw/%s/%s';") % | |
|
1049 | ( repo.repo_name, commit_id1, f_path, | |
|
1050 | repo.repo_name, commit_id2, f_path)) | |
|
1051 | ||
|
1052 | ||
|
1053 | def test_empty_diff_2way_redirect_to_summary_with_alert(self, app, backend): | |
|
1054 | commit_id_range = { | |
|
1055 | 'hg': ( | |
|
1056 | '25d7e49c18b159446cadfa506a5cf8ad1cb04067', | |
|
1057 | '603d6c72c46d953420c89d36372f08d9f305f5dd'), | |
|
1058 | 'git': ( | |
|
1059 | '6fc9270775aaf5544c1deb014f4ddd60c952fcbb', | |
|
1060 | '03fa803d7e9fb14daa9a3089e0d1494eda75d986'), | |
|
1061 | 'svn': ( | |
|
1062 | '335', | |
|
1063 | '337'), | |
|
1064 | } | |
|
1065 | f_path = 'setup.py' | |
|
1066 | ||
|
1067 | commit_ids = commit_id_range[backend.alias] | |
|
1068 | ||
|
1069 | response = self.app.get(url( | |
|
1070 | controller='files', action='diff_2way', | |
|
1071 | repo_name=backend.repo_name, | |
|
1072 | diff2=commit_ids[0], | |
|
1073 | diff1=commit_ids[1], | |
|
1074 | f_path=f_path)) | |
|
1075 | ||
|
1076 | assert_response = AssertResponse(response) | |
|
1077 | assert_session_flash( response, | |
|
1078 | ('%(file_path)s has not changed') % { 'file_path': f_path }) |
General Comments 0
You need to be logged in to leave comments.
Login now