##// END OF EJS Templates
tests update
marcink -
r1047:15b60f83 beta
parent child Browse files
Show More
@@ -1,72 +1,71 b''
1 """Pylons application test package
1 """Pylons application test package
2
2
3 This package assumes the Pylons environment is already loaded, such as
3 This package assumes the Pylons environment is already loaded, such as
4 when this script is imported from the `nosetests --with-pylons=test.ini`
4 when this script is imported from the `nosetests --with-pylons=test.ini`
5 command.
5 command.
6
6
7 This module initializes the application via ``websetup`` (`paster
7 This module initializes the application via ``websetup`` (`paster
8 setup-app`) and provides the base testing objects.
8 setup-app`) and provides the base testing objects.
9 """
9 """
10 from unittest import TestCase
10 from unittest import TestCase
11
11
12 from paste.deploy import loadapp
12 from paste.deploy import loadapp
13 from paste.script.appinstall import SetupCommand
13 from paste.script.appinstall import SetupCommand
14 from pylons import config, url
14 from pylons import config, url
15 from routes.util import URLGenerator
15 from routes.util import URLGenerator
16 from webtest import TestApp
16 from webtest import TestApp
17 import os
17 import os
18 from rhodecode.model import meta
18 from rhodecode.model import meta
19 import logging
19 import logging
20
20
21
21
22 log = logging.getLogger(__name__)
22 log = logging.getLogger(__name__)
23
23
24 import pylons.test
24 import pylons.test
25
25
26 __all__ = ['environ', 'url', 'TestController', 'TESTS_TMP_PATH', 'HG_REPO',
26 __all__ = ['environ', 'url', 'TestController', 'TESTS_TMP_PATH', 'HG_REPO',
27 'GIT_REPO', 'NEW_HG_REPO', 'NEW_GIT_REPO', 'HG_FORK', 'GIT_FORK', ]
27 'GIT_REPO', 'NEW_HG_REPO', 'NEW_GIT_REPO', 'HG_FORK', 'GIT_FORK', ]
28
28
29 # Invoke websetup with the current config file
29 # Invoke websetup with the current config file
30 #SetupCommand('setup-app').run([config_file])
30 #SetupCommand('setup-app').run([config_file])
31
31
32 ##RUNNING DESIRED TESTS
32 ##RUNNING DESIRED TESTS
33 #nosetests -x rhodecode.tests.functional.test_admin_settings:TestSettingsController.test_my_account
33 #nosetests -x rhodecode.tests.functional.test_admin_settings:TestSettingsController.test_my_account
34
34
35 environ = {}
35 environ = {}
36
36
37 #SOME GLOBALS FOR TESTS
37 #SOME GLOBALS FOR TESTS
38 TESTS_TMP_PATH = '/tmp'
38 TESTS_TMP_PATH = '/tmp'
39
39
40 HG_REPO = 'vcs_test_hg'
40 HG_REPO = 'vcs_test_hg'
41 GIT_REPO = 'vcs_test_git'
41 GIT_REPO = 'vcs_test_git'
42
42
43 NEW_HG_REPO = 'vcs_test_hg_new'
43 NEW_HG_REPO = 'vcs_test_hg_new'
44 NEW_GIT_REPO = 'vcs_test_git_new'
44 NEW_GIT_REPO = 'vcs_test_git_new'
45
45
46 HG_FORK = 'vcs_test_hg_fork'
46 HG_FORK = 'vcs_test_hg_fork'
47 GIT_FORK = 'vcs_test_git_fork'
47 GIT_FORK = 'vcs_test_git_fork'
48
48
49 class TestController(TestCase):
49 class TestController(TestCase):
50
50
51 def __init__(self, *args, **kwargs):
51 def __init__(self, *args, **kwargs):
52 wsgiapp = pylons.test.pylonsapp
52 wsgiapp = pylons.test.pylonsapp
53 config = wsgiapp.config
53 config = wsgiapp.config
54
54
55 self.app = TestApp(wsgiapp)
55 self.app = TestApp(wsgiapp)
56 url._push_object(URLGenerator(config['routes.map'], environ))
56 url._push_object(URLGenerator(config['routes.map'], environ))
57 self.sa = meta.Session
57 self.sa = meta.Session
58 self.index_location = config['app_conf']['index_dir']
58 self.index_location = config['app_conf']['index_dir']
59 TestCase.__init__(self, *args, **kwargs)
59 TestCase.__init__(self, *args, **kwargs)
60
60
61 def log_user(self, username='test_admin', password='test12'):
61 def log_user(self, username='test_admin', password='test12'):
62 response = self.app.post(url(controller='login', action='index'),
62 response = self.app.post(url(controller='login', action='index'),
63 {'username':username,
63 {'username':username,
64 'password':password})
64 'password':password})
65 print response
66
65
67 if 'invalid user name' in response.body:
66 if 'invalid user name' in response.body:
68 assert False, 'could not login using %s %s' % (username, password)
67 assert False, 'could not login using %s %s' % (username, password)
69
68
70 assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status
69 assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status
71 assert response.session['rhodecode_user'].username == username, 'wrong logged in user got %s expected %s' % (response.session['rhodecode_user'].username, username)
70 assert response.session['rhodecode_user'].username == username, 'wrong logged in user got %s expected %s' % (response.session['rhodecode_user'].username, username)
72 return response.follow()
71 return response.follow()
@@ -1,241 +1,307 b''
1 from rhodecode.tests import *
1 from rhodecode.tests import *
2
2
3 ARCHIVE_SPECS = {
3 ARCHIVE_SPECS = {
4 '.tar.bz2': ('application/x-bzip2', 'tbz2', ''),
4 '.tar.bz2': ('application/x-bzip2', 'tbz2', ''),
5 '.tar.gz': ('application/x-gzip', 'tgz', ''),
5 '.tar.gz': ('application/x-gzip', 'tgz', ''),
6 '.zip': ('application/zip', 'zip', ''),
6 '.zip': ('application/zip', 'zip', ''),
7 }
7 }
8
8
9 class TestFilesController(TestController):
9 class TestFilesController(TestController):
10
10
11 def test_index(self):
11 def test_index(self):
12 self.log_user()
12 self.log_user()
13 response = self.app.get(url(controller='files', action='index',
13 response = self.app.get(url(controller='files', action='index',
14 repo_name=HG_REPO,
14 repo_name=HG_REPO,
15 revision='tip',
15 revision='tip',
16 f_path='/'))
16 f_path='/'))
17 # Test response...
17 # Test response...
18 assert '<a class="browser-dir" href="/vcs_test_hg/files/27cd5cce30c96924232dffcd24178a07ffeb5dfc/docs">docs</a>' in response.body, 'missing dir'
18 assert '<a class="browser-dir" href="/vcs_test_hg/files/27cd5cce30c96924232dffcd24178a07ffeb5dfc/docs">docs</a>' in response.body, 'missing dir'
19 assert '<a class="browser-dir" href="/vcs_test_hg/files/27cd5cce30c96924232dffcd24178a07ffeb5dfc/tests">tests</a>' in response.body, 'missing dir'
19 assert '<a class="browser-dir" href="/vcs_test_hg/files/27cd5cce30c96924232dffcd24178a07ffeb5dfc/tests">tests</a>' in response.body, 'missing dir'
20 assert '<a class="browser-dir" href="/vcs_test_hg/files/27cd5cce30c96924232dffcd24178a07ffeb5dfc/vcs">vcs</a>' in response.body, 'missing dir'
20 assert '<a class="browser-dir" href="/vcs_test_hg/files/27cd5cce30c96924232dffcd24178a07ffeb5dfc/vcs">vcs</a>' in response.body, 'missing dir'
21 assert '<a class="browser-file" href="/vcs_test_hg/files/27cd5cce30c96924232dffcd24178a07ffeb5dfc/.hgignore">.hgignore</a>' in response.body, 'missing file'
21 assert '<a class="browser-file" href="/vcs_test_hg/files/27cd5cce30c96924232dffcd24178a07ffeb5dfc/.hgignore">.hgignore</a>' in response.body, 'missing file'
22 assert '<a class="browser-file" href="/vcs_test_hg/files/27cd5cce30c96924232dffcd24178a07ffeb5dfc/MANIFEST.in">MANIFEST.in</a>' in response.body, 'missing file'
22 assert '<a class="browser-file" href="/vcs_test_hg/files/27cd5cce30c96924232dffcd24178a07ffeb5dfc/MANIFEST.in">MANIFEST.in</a>' in response.body, 'missing file'
23
23
24
24
25 def test_index_revision(self):
25 def test_index_revision(self):
26 self.log_user()
26 self.log_user()
27
27
28 response = self.app.get(url(controller='files', action='index',
28 response = self.app.get(url(controller='files', action='index',
29 repo_name=HG_REPO,
29 repo_name=HG_REPO,
30 revision='7ba66bec8d6dbba14a2155be32408c435c5f4492',
30 revision='7ba66bec8d6dbba14a2155be32408c435c5f4492',
31 f_path='/'))
31 f_path='/'))
32
32
33
33
34
34
35 #Test response...
35 #Test response...
36
36
37 assert '<a class="browser-dir" href="/vcs_test_hg/files/7ba66bec8d6dbba14a2155be32408c435c5f4492/docs">docs</a>' in response.body, 'missing dir'
37 assert '<a class="browser-dir" href="/vcs_test_hg/files/7ba66bec8d6dbba14a2155be32408c435c5f4492/docs">docs</a>' in response.body, 'missing dir'
38 assert '<a class="browser-dir" href="/vcs_test_hg/files/7ba66bec8d6dbba14a2155be32408c435c5f4492/tests">tests</a>' in response.body, 'missing dir'
38 assert '<a class="browser-dir" href="/vcs_test_hg/files/7ba66bec8d6dbba14a2155be32408c435c5f4492/tests">tests</a>' in response.body, 'missing dir'
39 assert '<a class="browser-file" href="/vcs_test_hg/files/7ba66bec8d6dbba14a2155be32408c435c5f4492/README.rst">README.rst</a>' in response.body, 'missing file'
39 assert '<a class="browser-file" href="/vcs_test_hg/files/7ba66bec8d6dbba14a2155be32408c435c5f4492/README.rst">README.rst</a>' in response.body, 'missing file'
40 assert '1.1 KiB' in response.body, 'missing size of setup.py'
40 assert '1.1 KiB' in response.body, 'missing size of setup.py'
41 assert 'text/x-python' in response.body, 'missing mimetype of setup.py'
41 assert 'text/x-python' in response.body, 'missing mimetype of setup.py'
42
42
43
43
44
44
45 def test_index_different_branch(self):
45 def test_index_different_branch(self):
46 self.log_user()
46 self.log_user()
47
47
48 response = self.app.get(url(controller='files', action='index',
48 response = self.app.get(url(controller='files', action='index',
49 repo_name=HG_REPO,
49 repo_name=HG_REPO,
50 revision='97e8b885c04894463c51898e14387d80c30ed1ee',
50 revision='97e8b885c04894463c51898e14387d80c30ed1ee',
51 f_path='/'))
51 f_path='/'))
52
52
53
53
54
54
55 assert """<span style="text-transform: uppercase;"><a href="#">branch: git</a></span>""" in response.body, 'missing or wrong branch info'
55 assert """<span style="text-transform: uppercase;"><a href="#">branch: git</a></span>""" in response.body, 'missing or wrong branch info'
56
56
57
57
58
58
59 def test_index_paging(self):
59 def test_index_paging(self):
60 self.log_user()
60 self.log_user()
61
61
62 for r in [(73, 'a066b25d5df7016b45a41b7e2a78c33b57adc235'),
62 for r in [(73, 'a066b25d5df7016b45a41b7e2a78c33b57adc235'),
63 (92, 'cc66b61b8455b264a7a8a2d8ddc80fcfc58c221e'),
63 (92, 'cc66b61b8455b264a7a8a2d8ddc80fcfc58c221e'),
64 (109, '75feb4c33e81186c87eac740cee2447330288412'),
64 (109, '75feb4c33e81186c87eac740cee2447330288412'),
65 (1, '3d8f361e72ab303da48d799ff1ac40d5ac37c67e'),
65 (1, '3d8f361e72ab303da48d799ff1ac40d5ac37c67e'),
66 (0, 'b986218ba1c9b0d6a259fac9b050b1724ed8e545')]:
66 (0, 'b986218ba1c9b0d6a259fac9b050b1724ed8e545')]:
67
67
68 response = self.app.get(url(controller='files', action='index',
68 response = self.app.get(url(controller='files', action='index',
69 repo_name=HG_REPO,
69 repo_name=HG_REPO,
70 revision=r[1],
70 revision=r[1],
71 f_path='/'))
71 f_path='/'))
72
72
73 assert """@ r%s:%s""" % (r[0], r[1][:12]) in response.body, 'missing info about current revision'
73 assert """@ r%s:%s""" % (r[0], r[1][:12]) in response.body, 'missing info about current revision'
74
74
75 def test_file_source(self):
75 def test_file_source(self):
76 self.log_user()
76 self.log_user()
77 response = self.app.get(url(controller='files', action='index',
77 response = self.app.get(url(controller='files', action='index',
78 repo_name=HG_REPO,
78 repo_name=HG_REPO,
79 revision='27cd5cce30c96924232dffcd24178a07ffeb5dfc',
79 revision='27cd5cce30c96924232dffcd24178a07ffeb5dfc',
80 f_path='vcs/nodes.py'))
80 f_path='vcs/nodes.py'))
81
81
82 #test or history
82 #test or history
83 assert """<optgroup label="Changesets">
83 assert """<optgroup label="Changesets">
84 <option selected="selected" value="8911406ad776fdd3d0b9932a2e89677e57405a48">r167:8911406ad776</option>
84 <option selected="selected" value="8911406ad776fdd3d0b9932a2e89677e57405a48">r167:8911406ad776</option>
85 <option value="aa957ed78c35a1541f508d2ec90e501b0a9e3167">r165:aa957ed78c35</option>
85 <option value="aa957ed78c35a1541f508d2ec90e501b0a9e3167">r165:aa957ed78c35</option>
86 <option value="48e11b73e94c0db33e736eaeea692f990cb0b5f1">r140:48e11b73e94c</option>
86 <option value="48e11b73e94c0db33e736eaeea692f990cb0b5f1">r140:48e11b73e94c</option>
87 <option value="adf3cbf483298563b968a6c673cd5bde5f7d5eea">r126:adf3cbf48329</option>
87 <option value="adf3cbf483298563b968a6c673cd5bde5f7d5eea">r126:adf3cbf48329</option>
88 <option value="6249fd0fb2cfb1411e764129f598e2cf0de79a6f">r113:6249fd0fb2cf</option>
88 <option value="6249fd0fb2cfb1411e764129f598e2cf0de79a6f">r113:6249fd0fb2cf</option>
89 <option value="75feb4c33e81186c87eac740cee2447330288412">r109:75feb4c33e81</option>
89 <option value="75feb4c33e81186c87eac740cee2447330288412">r109:75feb4c33e81</option>
90 <option value="9a4dc232ecdc763ef2e98ae2238cfcbba4f6ad8d">r108:9a4dc232ecdc</option>
90 <option value="9a4dc232ecdc763ef2e98ae2238cfcbba4f6ad8d">r108:9a4dc232ecdc</option>
91 <option value="595cce4efa21fda2f2e4eeb4fe5f2a6befe6fa2d">r107:595cce4efa21</option>
91 <option value="595cce4efa21fda2f2e4eeb4fe5f2a6befe6fa2d">r107:595cce4efa21</option>
92 <option value="4a8bd421fbc2dfbfb70d85a3fe064075ab2c49da">r104:4a8bd421fbc2</option>
92 <option value="4a8bd421fbc2dfbfb70d85a3fe064075ab2c49da">r104:4a8bd421fbc2</option>
93 <option value="57be63fc8f85e65a0106a53187f7316f8c487ffa">r102:57be63fc8f85</option>
93 <option value="57be63fc8f85e65a0106a53187f7316f8c487ffa">r102:57be63fc8f85</option>
94 <option value="5530bd87f7e2e124a64d07cb2654c997682128be">r101:5530bd87f7e2</option>
94 <option value="5530bd87f7e2e124a64d07cb2654c997682128be">r101:5530bd87f7e2</option>
95 <option value="e516008b1c93f142263dc4b7961787cbad654ce1">r99:e516008b1c93</option>
95 <option value="e516008b1c93f142263dc4b7961787cbad654ce1">r99:e516008b1c93</option>
96 <option value="41f43fc74b8b285984554532eb105ac3be5c434f">r93:41f43fc74b8b</option>
96 <option value="41f43fc74b8b285984554532eb105ac3be5c434f">r93:41f43fc74b8b</option>
97 <option value="cc66b61b8455b264a7a8a2d8ddc80fcfc58c221e">r92:cc66b61b8455</option>
97 <option value="cc66b61b8455b264a7a8a2d8ddc80fcfc58c221e">r92:cc66b61b8455</option>
98 <option value="73ab5b616b3271b0518682fb4988ce421de8099f">r91:73ab5b616b32</option>
98 <option value="73ab5b616b3271b0518682fb4988ce421de8099f">r91:73ab5b616b32</option>
99 <option value="e0da75f308c0f18f98e9ce6257626009fdda2b39">r82:e0da75f308c0</option>
99 <option value="e0da75f308c0f18f98e9ce6257626009fdda2b39">r82:e0da75f308c0</option>
100 <option value="fb2e41e0f0810be4d7103bc2a4c7be16ee3ec611">r81:fb2e41e0f081</option>
100 <option value="fb2e41e0f0810be4d7103bc2a4c7be16ee3ec611">r81:fb2e41e0f081</option>
101 <option value="602ae2f5e7ade70b3b66a58cdd9e3e613dc8a028">r76:602ae2f5e7ad</option>
101 <option value="602ae2f5e7ade70b3b66a58cdd9e3e613dc8a028">r76:602ae2f5e7ad</option>
102 <option value="a066b25d5df7016b45a41b7e2a78c33b57adc235">r73:a066b25d5df7</option>
102 <option value="a066b25d5df7016b45a41b7e2a78c33b57adc235">r73:a066b25d5df7</option>
103 <option value="637a933c905958ce5151f154147c25c1c7b68832">r61:637a933c9059</option>
103 <option value="637a933c905958ce5151f154147c25c1c7b68832">r61:637a933c9059</option>
104 <option value="0c21004effeb8ce2d2d5b4a8baf6afa8394b6fbc">r60:0c21004effeb</option>
104 <option value="0c21004effeb8ce2d2d5b4a8baf6afa8394b6fbc">r60:0c21004effeb</option>
105 <option value="a1f39c56d3f1d52d5fb5920370a2a2716cd9a444">r59:a1f39c56d3f1</option>
105 <option value="a1f39c56d3f1d52d5fb5920370a2a2716cd9a444">r59:a1f39c56d3f1</option>
106 <option value="97d32df05c715a3bbf936bf3cc4e32fb77fe1a7f">r58:97d32df05c71</option>
106 <option value="97d32df05c715a3bbf936bf3cc4e32fb77fe1a7f">r58:97d32df05c71</option>
107 <option value="08eaf14517718dccea4b67755a93368341aca919">r57:08eaf1451771</option>
107 <option value="08eaf14517718dccea4b67755a93368341aca919">r57:08eaf1451771</option>
108 <option value="22f71ad265265a53238359c883aa976e725aa07d">r56:22f71ad26526</option>
108 <option value="22f71ad265265a53238359c883aa976e725aa07d">r56:22f71ad26526</option>
109 <option value="97501f02b7b4330924b647755663a2d90a5e638d">r49:97501f02b7b4</option>
109 <option value="97501f02b7b4330924b647755663a2d90a5e638d">r49:97501f02b7b4</option>
110 <option value="86ede6754f2b27309452bb11f997386ae01d0e5a">r47:86ede6754f2b</option>
110 <option value="86ede6754f2b27309452bb11f997386ae01d0e5a">r47:86ede6754f2b</option>
111 <option value="014c40c0203c423dc19ecf94644f7cac9d4cdce0">r45:014c40c0203c</option>
111 <option value="014c40c0203c423dc19ecf94644f7cac9d4cdce0">r45:014c40c0203c</option>
112 <option value="ee87846a61c12153b51543bf860e1026c6d3dcba">r30:ee87846a61c1</option>
112 <option value="ee87846a61c12153b51543bf860e1026c6d3dcba">r30:ee87846a61c1</option>
113 <option value="9bb326a04ae5d98d437dece54be04f830cf1edd9">r26:9bb326a04ae5</option>
113 <option value="9bb326a04ae5d98d437dece54be04f830cf1edd9">r26:9bb326a04ae5</option>
114 <option value="536c1a19428381cfea92ac44985304f6a8049569">r24:536c1a194283</option>
114 <option value="536c1a19428381cfea92ac44985304f6a8049569">r24:536c1a194283</option>
115 <option value="dc5d2c0661b61928834a785d3e64a3f80d3aad9c">r8:dc5d2c0661b6</option>
115 <option value="dc5d2c0661b61928834a785d3e64a3f80d3aad9c">r8:dc5d2c0661b6</option>
116 <option value="3803844fdbd3b711175fc3da9bdacfcd6d29a6fb">r7:3803844fdbd3</option>
116 <option value="3803844fdbd3b711175fc3da9bdacfcd6d29a6fb">r7:3803844fdbd3</option>
117 </optgroup>
117 </optgroup>
118 <optgroup label="Branches">
118 <optgroup label="Branches">
119 <option value="27cd5cce30c96924232dffcd24178a07ffeb5dfc">default</option>
119 <option value="27cd5cce30c96924232dffcd24178a07ffeb5dfc">default</option>
120 <option value="97e8b885c04894463c51898e14387d80c30ed1ee">git</option>
120 <option value="97e8b885c04894463c51898e14387d80c30ed1ee">git</option>
121 <option value="2e6a2bf9356ca56df08807f4ad86d480da72a8f4">web</option>
121 <option value="2e6a2bf9356ca56df08807f4ad86d480da72a8f4">web</option>
122 </optgroup>
122 </optgroup>
123 <optgroup label="Tags">
123 <optgroup label="Tags">
124 <option value="27cd5cce30c96924232dffcd24178a07ffeb5dfc">tip</option>
124 <option value="27cd5cce30c96924232dffcd24178a07ffeb5dfc">tip</option>
125 <option value="fd4bdb5e9b2a29b4393a4ac6caef48c17ee1a200">0.1.4</option>
125 <option value="fd4bdb5e9b2a29b4393a4ac6caef48c17ee1a200">0.1.4</option>
126 <option value="17544fbfcd33ffb439e2b728b5d526b1ef30bfcf">0.1.3</option>
126 <option value="17544fbfcd33ffb439e2b728b5d526b1ef30bfcf">0.1.3</option>
127 <option value="a7e60bff65d57ac3a1a1ce3b12a70f8a9e8a7720">0.1.2</option>
127 <option value="a7e60bff65d57ac3a1a1ce3b12a70f8a9e8a7720">0.1.2</option>
128 <option value="eb3a60fc964309c1a318b8dfe26aa2d1586c85ae">0.1.1</option>
128 <option value="eb3a60fc964309c1a318b8dfe26aa2d1586c85ae">0.1.1</option>
129 </optgroup>""" in response.body
129 </optgroup>""" in response.body
130
130
131
131
132 assert """<div class="commit">"Partially implemented #16. filecontent/commit message/author/node name are safe_unicode now.
132 assert """<div class="commit">"Partially implemented #16. filecontent/commit message/author/node name are safe_unicode now.
133 In addition some other __str__ are unicode as well
133 In addition some other __str__ are unicode as well
134 Added test for unicode
134 Added test for unicode
135 Improved test to clone into uniq repository.
135 Improved test to clone into uniq repository.
136 removed extra unicode conversion in diff."</div>""" in response.body
136 removed extra unicode conversion in diff."</div>""" in response.body
137
137
138 assert """<span style="text-transform: uppercase;"><a href="#">branch: default</a></span>""" in response.body, 'missing or wrong branch info'
138 assert """<span style="text-transform: uppercase;"><a href="#">branch: default</a></span>""" in response.body, 'missing or wrong branch info'
139
139
140 def test_file_annotation(self):
140 def test_file_annotation(self):
141 self.log_user()
141 self.log_user()
142 response = self.app.get(url(controller='files', action='annotate',
142 response = self.app.get(url(controller='files', action='annotate',
143 repo_name=HG_REPO,
143 repo_name=HG_REPO,
144 revision='27cd5cce30c96924232dffcd24178a07ffeb5dfc',
144 revision='27cd5cce30c96924232dffcd24178a07ffeb5dfc',
145 f_path='vcs/nodes.py'))
145 f_path='vcs/nodes.py'))
146
146
147 print response.body
147 print response.body
148 assert """<optgroup label="Changesets">
148 assert """<optgroup label="Changesets">
149 <option selected="selected" value="8911406ad776fdd3d0b9932a2e89677e57405a48">r167:8911406ad776</option>
149 <option selected="selected" value="8911406ad776fdd3d0b9932a2e89677e57405a48">r167:8911406ad776</option>
150 <option value="aa957ed78c35a1541f508d2ec90e501b0a9e3167">r165:aa957ed78c35</option>
150 <option value="aa957ed78c35a1541f508d2ec90e501b0a9e3167">r165:aa957ed78c35</option>
151 <option value="48e11b73e94c0db33e736eaeea692f990cb0b5f1">r140:48e11b73e94c</option>
151 <option value="48e11b73e94c0db33e736eaeea692f990cb0b5f1">r140:48e11b73e94c</option>
152 <option value="adf3cbf483298563b968a6c673cd5bde5f7d5eea">r126:adf3cbf48329</option>
152 <option value="adf3cbf483298563b968a6c673cd5bde5f7d5eea">r126:adf3cbf48329</option>
153 <option value="6249fd0fb2cfb1411e764129f598e2cf0de79a6f">r113:6249fd0fb2cf</option>
153 <option value="6249fd0fb2cfb1411e764129f598e2cf0de79a6f">r113:6249fd0fb2cf</option>
154 <option value="75feb4c33e81186c87eac740cee2447330288412">r109:75feb4c33e81</option>
154 <option value="75feb4c33e81186c87eac740cee2447330288412">r109:75feb4c33e81</option>
155 <option value="9a4dc232ecdc763ef2e98ae2238cfcbba4f6ad8d">r108:9a4dc232ecdc</option>
155 <option value="9a4dc232ecdc763ef2e98ae2238cfcbba4f6ad8d">r108:9a4dc232ecdc</option>
156 <option value="595cce4efa21fda2f2e4eeb4fe5f2a6befe6fa2d">r107:595cce4efa21</option>
156 <option value="595cce4efa21fda2f2e4eeb4fe5f2a6befe6fa2d">r107:595cce4efa21</option>
157 <option value="4a8bd421fbc2dfbfb70d85a3fe064075ab2c49da">r104:4a8bd421fbc2</option>
157 <option value="4a8bd421fbc2dfbfb70d85a3fe064075ab2c49da">r104:4a8bd421fbc2</option>
158 <option value="57be63fc8f85e65a0106a53187f7316f8c487ffa">r102:57be63fc8f85</option>
158 <option value="57be63fc8f85e65a0106a53187f7316f8c487ffa">r102:57be63fc8f85</option>
159 <option value="5530bd87f7e2e124a64d07cb2654c997682128be">r101:5530bd87f7e2</option>
159 <option value="5530bd87f7e2e124a64d07cb2654c997682128be">r101:5530bd87f7e2</option>
160 <option value="e516008b1c93f142263dc4b7961787cbad654ce1">r99:e516008b1c93</option>
160 <option value="e516008b1c93f142263dc4b7961787cbad654ce1">r99:e516008b1c93</option>
161 <option value="41f43fc74b8b285984554532eb105ac3be5c434f">r93:41f43fc74b8b</option>
161 <option value="41f43fc74b8b285984554532eb105ac3be5c434f">r93:41f43fc74b8b</option>
162 <option value="cc66b61b8455b264a7a8a2d8ddc80fcfc58c221e">r92:cc66b61b8455</option>
162 <option value="cc66b61b8455b264a7a8a2d8ddc80fcfc58c221e">r92:cc66b61b8455</option>
163 <option value="73ab5b616b3271b0518682fb4988ce421de8099f">r91:73ab5b616b32</option>
163 <option value="73ab5b616b3271b0518682fb4988ce421de8099f">r91:73ab5b616b32</option>
164 <option value="e0da75f308c0f18f98e9ce6257626009fdda2b39">r82:e0da75f308c0</option>
164 <option value="e0da75f308c0f18f98e9ce6257626009fdda2b39">r82:e0da75f308c0</option>
165 <option value="fb2e41e0f0810be4d7103bc2a4c7be16ee3ec611">r81:fb2e41e0f081</option>
165 <option value="fb2e41e0f0810be4d7103bc2a4c7be16ee3ec611">r81:fb2e41e0f081</option>
166 <option value="602ae2f5e7ade70b3b66a58cdd9e3e613dc8a028">r76:602ae2f5e7ad</option>
166 <option value="602ae2f5e7ade70b3b66a58cdd9e3e613dc8a028">r76:602ae2f5e7ad</option>
167 <option value="a066b25d5df7016b45a41b7e2a78c33b57adc235">r73:a066b25d5df7</option>
167 <option value="a066b25d5df7016b45a41b7e2a78c33b57adc235">r73:a066b25d5df7</option>
168 <option value="637a933c905958ce5151f154147c25c1c7b68832">r61:637a933c9059</option>
168 <option value="637a933c905958ce5151f154147c25c1c7b68832">r61:637a933c9059</option>
169 <option value="0c21004effeb8ce2d2d5b4a8baf6afa8394b6fbc">r60:0c21004effeb</option>
169 <option value="0c21004effeb8ce2d2d5b4a8baf6afa8394b6fbc">r60:0c21004effeb</option>
170 <option value="a1f39c56d3f1d52d5fb5920370a2a2716cd9a444">r59:a1f39c56d3f1</option>
170 <option value="a1f39c56d3f1d52d5fb5920370a2a2716cd9a444">r59:a1f39c56d3f1</option>
171 <option value="97d32df05c715a3bbf936bf3cc4e32fb77fe1a7f">r58:97d32df05c71</option>
171 <option value="97d32df05c715a3bbf936bf3cc4e32fb77fe1a7f">r58:97d32df05c71</option>
172 <option value="08eaf14517718dccea4b67755a93368341aca919">r57:08eaf1451771</option>
172 <option value="08eaf14517718dccea4b67755a93368341aca919">r57:08eaf1451771</option>
173 <option value="22f71ad265265a53238359c883aa976e725aa07d">r56:22f71ad26526</option>
173 <option value="22f71ad265265a53238359c883aa976e725aa07d">r56:22f71ad26526</option>
174 <option value="97501f02b7b4330924b647755663a2d90a5e638d">r49:97501f02b7b4</option>
174 <option value="97501f02b7b4330924b647755663a2d90a5e638d">r49:97501f02b7b4</option>
175 <option value="86ede6754f2b27309452bb11f997386ae01d0e5a">r47:86ede6754f2b</option>
175 <option value="86ede6754f2b27309452bb11f997386ae01d0e5a">r47:86ede6754f2b</option>
176 <option value="014c40c0203c423dc19ecf94644f7cac9d4cdce0">r45:014c40c0203c</option>
176 <option value="014c40c0203c423dc19ecf94644f7cac9d4cdce0">r45:014c40c0203c</option>
177 <option value="ee87846a61c12153b51543bf860e1026c6d3dcba">r30:ee87846a61c1</option>
177 <option value="ee87846a61c12153b51543bf860e1026c6d3dcba">r30:ee87846a61c1</option>
178 <option value="9bb326a04ae5d98d437dece54be04f830cf1edd9">r26:9bb326a04ae5</option>
178 <option value="9bb326a04ae5d98d437dece54be04f830cf1edd9">r26:9bb326a04ae5</option>
179 <option value="536c1a19428381cfea92ac44985304f6a8049569">r24:536c1a194283</option>
179 <option value="536c1a19428381cfea92ac44985304f6a8049569">r24:536c1a194283</option>
180 <option value="dc5d2c0661b61928834a785d3e64a3f80d3aad9c">r8:dc5d2c0661b6</option>
180 <option value="dc5d2c0661b61928834a785d3e64a3f80d3aad9c">r8:dc5d2c0661b6</option>
181 <option value="3803844fdbd3b711175fc3da9bdacfcd6d29a6fb">r7:3803844fdbd3</option>
181 <option value="3803844fdbd3b711175fc3da9bdacfcd6d29a6fb">r7:3803844fdbd3</option>
182 </optgroup>
182 </optgroup>
183 <optgroup label="Branches">
183 <optgroup label="Branches">
184 <option value="27cd5cce30c96924232dffcd24178a07ffeb5dfc">default</option>
184 <option value="27cd5cce30c96924232dffcd24178a07ffeb5dfc">default</option>
185 <option value="97e8b885c04894463c51898e14387d80c30ed1ee">git</option>
185 <option value="97e8b885c04894463c51898e14387d80c30ed1ee">git</option>
186 <option value="2e6a2bf9356ca56df08807f4ad86d480da72a8f4">web</option>
186 <option value="2e6a2bf9356ca56df08807f4ad86d480da72a8f4">web</option>
187 </optgroup>
187 </optgroup>
188 <optgroup label="Tags">
188 <optgroup label="Tags">
189 <option value="27cd5cce30c96924232dffcd24178a07ffeb5dfc">tip</option>
189 <option value="27cd5cce30c96924232dffcd24178a07ffeb5dfc">tip</option>
190 <option value="fd4bdb5e9b2a29b4393a4ac6caef48c17ee1a200">0.1.4</option>
190 <option value="fd4bdb5e9b2a29b4393a4ac6caef48c17ee1a200">0.1.4</option>
191 <option value="17544fbfcd33ffb439e2b728b5d526b1ef30bfcf">0.1.3</option>
191 <option value="17544fbfcd33ffb439e2b728b5d526b1ef30bfcf">0.1.3</option>
192 <option value="a7e60bff65d57ac3a1a1ce3b12a70f8a9e8a7720">0.1.2</option>
192 <option value="a7e60bff65d57ac3a1a1ce3b12a70f8a9e8a7720">0.1.2</option>
193 <option value="eb3a60fc964309c1a318b8dfe26aa2d1586c85ae">0.1.1</option>
193 <option value="eb3a60fc964309c1a318b8dfe26aa2d1586c85ae">0.1.1</option>
194 </optgroup>""" in response.body, 'missing or wrong history in annotation'
194 </optgroup>""" in response.body, 'missing or wrong history in annotation'
195
195
196 assert """<span style="text-transform: uppercase;"><a href="#">branch: default</a></span>""" in response.body, 'missing or wrong branch info'
196 assert """<span style="text-transform: uppercase;"><a href="#">branch: default</a></span>""" in response.body, 'missing or wrong branch info'
197
197
198
198
199
199
200 def test_archival(self):
200 def test_archival(self):
201 self.log_user()
201 self.log_user()
202
202
203 for arch_ext, info in ARCHIVE_SPECS.items():
203 for arch_ext, info in ARCHIVE_SPECS.items():
204 fname = '27cd5cce30c96924232dffcd24178a07ffeb5dfc%s' % arch_ext
204 fname = '27cd5cce30c96924232dffcd24178a07ffeb5dfc%s' % arch_ext
205 filename = '%s-%s' % (HG_REPO, fname)
205 filename = '%s-%s' % (HG_REPO, fname)
206
206
207 response = self.app.get(url(controller='files', action='archivefile',
207 response = self.app.get(url(controller='files', action='archivefile',
208 repo_name=HG_REPO,
208 repo_name=HG_REPO,
209 fname=fname))
209 fname=fname))
210
210
211 assert response.status == '200 OK', 'wrong response code'
211 assert response.status == '200 OK', 'wrong response code'
212 assert response.response._headers.items() == [('Pragma', 'no-cache'),
212 assert response.response._headers.items() == [('Pragma', 'no-cache'),
213 ('Cache-Control', 'no-cache'),
213 ('Cache-Control', 'no-cache'),
214 ('Content-Type', '%s; charset=utf-8' % info[0]),
214 ('Content-Type', '%s; charset=utf-8' % info[0]),
215 ('Content-Disposition', 'attachment; filename=%s' % filename), ], 'wrong headers'
215 ('Content-Disposition', 'attachment; filename=%s' % filename), ], 'wrong headers'
216
216
217 def test_archival_wrong_ext(self):
217 def test_archival_wrong_ext(self):
218 self.log_user()
218 self.log_user()
219
219
220 for arch_ext in ['tar', 'rar', 'x', '..ax', '.zipz']:
220 for arch_ext in ['tar', 'rar', 'x', '..ax', '.zipz']:
221 fname = '27cd5cce30c96924232dffcd24178a07ffeb5dfc%s' % arch_ext
221 fname = '27cd5cce30c96924232dffcd24178a07ffeb5dfc%s' % arch_ext
222
222
223 response = self.app.get(url(controller='files', action='archivefile',
223 response = self.app.get(url(controller='files', action='archivefile',
224 repo_name=HG_REPO,
224 repo_name=HG_REPO,
225 fname=fname))
225 fname=fname))
226 assert 'Unknown archive type' in response.body
226 assert 'Unknown archive type' in response.body
227
227
228
228
229 def test_archival_wrong_revision(self):
229 def test_archival_wrong_revision(self):
230 self.log_user()
230 self.log_user()
231
231
232 for rev in ['00x000000', 'tar', 'wrong', '@##$@$424213232', '232dffcd']:
232 for rev in ['00x000000', 'tar', 'wrong', '@##$@$424213232', '232dffcd']:
233 fname = '%s.zip' % rev
233 fname = '%s.zip' % rev
234
234
235 response = self.app.get(url(controller='files', action='archivefile',
235 response = self.app.get(url(controller='files', action='archivefile',
236 repo_name=HG_REPO,
236 repo_name=HG_REPO,
237 fname=fname))
237 fname=fname))
238 assert 'Unknown revision' in response.body
238 assert 'Unknown revision' in response.body
239
239
240 #==========================================================================
241 # RAW FILE
242 #==========================================================================
243 def test_raw_file_ok(self):
244 self.log_user()
245 response = self.app.get(url(controller='files', action='rawfile',
246 repo_name=HG_REPO,
247 revision='27cd5cce30c96924232dffcd24178a07ffeb5dfc',
248 f_path='vcs/nodes.py'))
249 assert False
250 #TODO: put in more
251 def test_raw_file_wrong_cs(self):
252 self.log_user()
253 rev = u'ERRORcce30c96924232dffcd24178a07ffeb5dfc'
254 f_path = 'vcs/nodes.py'
255
256 response = self.app.get(url(controller='files', action='rawfile',
257 repo_name=HG_REPO,
258 revision='ERRORce30c96924232dffcd24178a07ffeb5dfc',
259 f_path='vcs/nodes.py'))
260 print response.session['flash']
261 assert """Revision %r does not exist for this repository""" % (rev) in response.session['flash'][0], 'No flash message'
262 assert """%s""" % (HG_REPO) in response.session['flash'][0], 'No flash message'
263
240
264
241
265
266 def test_raw_file_wrong_f_path(self):
267 self.log_user()
268 rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
269 f_path = 'vcs/ERRORnodes.py'
270 response = self.app.get(url(controller='files', action='rawfile',
271 repo_name=HG_REPO,
272 revision=rev,
273 f_path=f_path))
274 assert "There is no file nor directory at the given path %r at revision %r" % (f_path, rev) in response.session['flash'][0], 'No flash message'
275
276 #==========================================================================
277 # RAW
278 #==========================================================================
279 def test_raw_ok(self):
280 self.log_user()
281 response = self.app.get(url(controller='files', action='raw',
282 repo_name=HG_REPO,
283 revision='27cd5cce30c96924232dffcd24178a07ffeb5dfc',
284 f_path='vcs/nodes.py'))
285 assert False
286 #TODO: put in more
287 def test_raw_wrong_cs(self):
288 self.log_user()
289 rev = 'ERRORcce30c96924232dffcd24178a07ffeb5dfc'
290 f_path = 'vcs/nodes.py'
291
292 response = self.app.get(url(controller='files', action='raw',
293 repo_name=HG_REPO,
294 revision='ERRORce30c96924232dffcd24178a07ffeb5dfc',
295 f_path='vcs/nodes.py'))
296 assert "Cannot find revision %s" % rev in response.session['flash'][0], 'No flash message'
297
298 def test_raw_wrong_f_path(self):
299 self.log_user()
300 rev = '27cd5cce30c96924232dffcd24178a07ffeb5dfc'
301 f_path = 'vcs/ERRORnodes.py'
302 response = self.app.get(url(controller='files', action='raw',
303 repo_name=HG_REPO,
304 revision=rev,
305 f_path=f_path))
306 assert "There is no file nor directory at the given path %r at revision %r" % (f_path, rev) in response.session['flash'][0], 'No flash message'
307
@@ -1,303 +1,332 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 rhodecode.tests.test_hg_operations
3 rhodecode.tests.test_hg_operations
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
5
6 Test suite for making push/pull operations
6 Test suite for making push/pull operations
7
7
8 :created_on: Dec 30, 2010
8 :created_on: Dec 30, 2010
9 :copyright: (c) 2010 by marcink.
9 :copyright: (c) 2010 by marcink.
10 :license: LICENSE_NAME, see LICENSE_FILE for more details.
10 :license: LICENSE_NAME, see LICENSE_FILE for more details.
11 """
11 """
12
12
13 import os
13 import os
14 import shutil
14 import shutil
15 import logging
15 import logging
16 from os.path import join as jn
16 from os.path import join as jn
17
17
18 from tempfile import _RandomNameSequence
18 from tempfile import _RandomNameSequence
19 from subprocess import Popen, PIPE
19 from subprocess import Popen, PIPE
20
20
21 from paste.deploy import appconfig
21 from paste.deploy import appconfig
22 from pylons import config
22 from pylons import config
23 from sqlalchemy import engine_from_config
23 from sqlalchemy import engine_from_config
24
24
25 from rhodecode.lib.utils import add_cache
25 from rhodecode.lib.utils import add_cache
26 from rhodecode.model import init_model
26 from rhodecode.model import init_model
27 from rhodecode.model import meta
27 from rhodecode.model import meta
28 from rhodecode.model.db import User, Repository
28 from rhodecode.model.db import User, Repository
29 from rhodecode.lib.auth import get_crypt_password
29 from rhodecode.lib.auth import get_crypt_password
30
30
31 from rhodecode.tests import TESTS_TMP_PATH, NEW_HG_REPO, HG_REPO
31 from rhodecode.tests import TESTS_TMP_PATH, NEW_HG_REPO, HG_REPO
32 from rhodecode.config.environment import load_environment
32 from rhodecode.config.environment import load_environment
33
33
34 conf = appconfig('config:development.ini', relative_to='./../../')
34 conf = appconfig('config:development.ini', relative_to='./../../')
35 load_environment(conf.global_conf, conf.local_conf)
35 load_environment(conf.global_conf, conf.local_conf)
36
36
37 add_cache(conf)
37 add_cache(conf)
38
38
39 USER = 'test_admin'
39 USER = 'test_admin'
40 PASS = 'test12'
40 PASS = 'test12'
41 HOST = '127.0.0.1:5000'
41 HOST = '127.0.0.1:5000'
42 DEBUG = True
42 DEBUG = True
43 log = logging.getLogger(__name__)
43 log = logging.getLogger(__name__)
44
44
45
45
46 class Command(object):
46 class Command(object):
47
47
48 def __init__(self, cwd):
48 def __init__(self, cwd):
49 self.cwd = cwd
49 self.cwd = cwd
50
50
51 def execute(self, cmd, *args):
51 def execute(self, cmd, *args):
52 """Runs command on the system with given ``args``.
52 """Runs command on the system with given ``args``.
53 """
53 """
54
54
55 command = cmd + ' ' + ' '.join(args)
55 command = cmd + ' ' + ' '.join(args)
56 log.debug('Executing %s' % command)
56 log.debug('Executing %s' % command)
57 if DEBUG:
57 if DEBUG:
58 print command
58 print command
59 p = Popen(command, shell=True, stdout=PIPE, stderr=PIPE, cwd=self.cwd)
59 p = Popen(command, shell=True, stdout=PIPE, stderr=PIPE, cwd=self.cwd)
60 stdout, stderr = p.communicate()
60 stdout, stderr = p.communicate()
61 if DEBUG:
61 if DEBUG:
62 print stdout, stderr
62 print stdout, stderr
63 return stdout, stderr
63 return stdout, stderr
64
64
65 def get_session():
65 def get_session():
66 engine = engine_from_config(conf, 'sqlalchemy.db1.')
66 engine = engine_from_config(conf, 'sqlalchemy.db1.')
67 init_model(engine)
67 init_model(engine)
68 sa = meta.Session()
68 sa = meta.Session()
69 return sa
69 return sa
70
70
71
71
72 def create_test_user(force=True):
72 def create_test_user(force=True):
73 print 'creating test user'
73 print 'creating test user'
74 sa = get_session()
74 sa = get_session()
75
75
76 user = sa.query(User).filter(User.username == USER).scalar()
76 user = sa.query(User).filter(User.username == USER).scalar()
77
77
78 if force and user is not None:
78 if force and user is not None:
79 print 'removing current user'
79 print 'removing current user'
80 for repo in sa.query(Repository).filter(Repository.user == user).all():
81 sa.delete(repo)
80 sa.delete(user)
82 sa.delete(user)
81 sa.commit()
83 sa.commit()
82
84
83 if user is None or force:
85 if user is None or force:
84 print 'creating new one'
86 print 'creating new one'
85 new_usr = User()
87 new_usr = User()
86 new_usr.username = USER
88 new_usr.username = USER
87 new_usr.password = get_crypt_password(PASS)
89 new_usr.password = get_crypt_password(PASS)
88 new_usr.email = 'mail@mail.com'
90 new_usr.email = 'mail@mail.com'
89 new_usr.name = 'test'
91 new_usr.name = 'test'
90 new_usr.lastname = 'lasttestname'
92 new_usr.lastname = 'lasttestname'
91 new_usr.active = True
93 new_usr.active = True
92 new_usr.admin = True
94 new_usr.admin = True
93 sa.add(new_usr)
95 sa.add(new_usr)
94 sa.commit()
96 sa.commit()
95
97
96 print 'done'
98 print 'done'
97
99
98
100
99 def create_test_repo(force=True):
101 def create_test_repo(force=True):
100 from rhodecode.model.repo import RepoModel
102 from rhodecode.model.repo import RepoModel
101 sa = get_session()
103 sa = get_session()
102
104
103 user = sa.query(User).filter(User.username == USER).scalar()
105 user = sa.query(User).filter(User.username == USER).scalar()
104 if user is None:
106 if user is None:
105 raise Exception('user not found')
107 raise Exception('user not found')
106
108
107
109
108 repo = sa.query(Repository).filter(Repository.repo_name == HG_REPO).scalar()
110 repo = sa.query(Repository).filter(Repository.repo_name == HG_REPO).scalar()
109
111
110 if repo is None:
112 if repo is None:
111 print 'repo not found creating'
113 print 'repo not found creating'
112
114
113 form_data = {'repo_name':HG_REPO,
115 form_data = {'repo_name':HG_REPO,
114 'repo_type':'hg',
116 'repo_type':'hg',
115 'private':False, }
117 'private':False, }
116 rm = RepoModel(sa)
118 rm = RepoModel(sa)
117 rm.base_path = '/home/hg'
119 rm.base_path = '/home/hg'
118 rm.create(form_data, user)
120 rm.create(form_data, user)
119
121
122
123 def set_anonymous_access(enable=True):
124 sa = get_session()
125 user = sa.query(User).filter(User.username == 'default').one()
126 user.active = enable
127 sa.add(user)
128 sa.commit()
129
130 def get_anonymous_access():
131 sa = get_session()
132 return sa.query(User).filter(User.username == 'default').one().active
133
134
120 #==============================================================================
135 #==============================================================================
121 # TESTS
136 # TESTS
122 #==============================================================================
137 #==============================================================================
123 def test_clone(no_errors=False):
138 def test_clone(no_errors=False):
124 cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
139 cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
125
140
126 try:
141 try:
127 shutil.rmtree(path, ignore_errors=True)
142 shutil.rmtree(path, ignore_errors=True)
128 os.makedirs(path)
143 os.makedirs(path)
129 #print 'made dirs %s' % jn(path)
144 #print 'made dirs %s' % jn(path)
130 except OSError:
145 except OSError:
131 raise
146 raise
132
147
133
148
134 clone_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s %(dest)s' % \
149 clone_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s %(dest)s' % \
135 {'user':USER,
150 {'user':USER,
136 'pass':PASS,
151 'pass':PASS,
137 'host':HOST,
152 'host':HOST,
138 'cloned_repo':HG_REPO,
153 'cloned_repo':HG_REPO,
139 'dest':path}
154 'dest':path}
140
155
141 stdout, stderr = Command(cwd).execute('hg clone', clone_url)
156 stdout, stderr = Command(cwd).execute('hg clone', clone_url)
142
157
143 if no_errors is False:
158 if no_errors is False:
144 assert """adding file changes""" in stdout, 'no messages about cloning'
159 assert """adding file changes""" in stdout, 'no messages about cloning'
145 assert """abort""" not in stderr , 'got error from clone'
160 assert """abort""" not in stderr , 'got error from clone'
146
161
147
162
148
163
149 def test_clone_anonymous_ok():
164 def test_clone_anonymous_ok():
150 cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
165 cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
151
166
152 try:
167 try:
153 shutil.rmtree(path, ignore_errors=True)
168 shutil.rmtree(path, ignore_errors=True)
154 os.makedirs(path)
169 os.makedirs(path)
155 #print 'made dirs %s' % jn(path)
170 #print 'made dirs %s' % jn(path)
156 except OSError:
171 except OSError:
157 raise
172 raise
158
173
159
174
175 print 'checking if anonymous access is enabled'
176 anonymous_access = get_anonymous_access()
177 if not anonymous_access:
178 print 'not enabled, enabling it '
179 set_anonymous_access(enable=True)
180
160 clone_url = 'http://%(host)s/%(cloned_repo)s %(dest)s' % \
181 clone_url = 'http://%(host)s/%(cloned_repo)s %(dest)s' % \
161 {'user':USER,
182 {'user':USER,
162 'pass':PASS,
183 'pass':PASS,
163 'host':HOST,
184 'host':HOST,
164 'cloned_repo':HG_REPO,
185 'cloned_repo':HG_REPO,
165 'dest':path}
186 'dest':path}
166
187
167 stdout, stderr = Command(cwd).execute('hg clone', clone_url)
188 stdout, stderr = Command(cwd).execute('hg clone', clone_url)
168 print stdout, stderr
189 print stdout, stderr
190
191
169 assert """adding file changes""" in stdout, 'no messages about cloning'
192 assert """adding file changes""" in stdout, 'no messages about cloning'
170 assert """abort""" not in stderr , 'got error from clone'
193 assert """abort""" not in stderr , 'got error from clone'
171
194
195 #disable if it was enabled
196 if not anonymous_access:
197 print 'disabling anonymous access'
198 set_anonymous_access(enable=False)
199
200
172 def test_clone_wrong_credentials():
201 def test_clone_wrong_credentials():
173 cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
202 cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
174
203
175 try:
204 try:
176 shutil.rmtree(path, ignore_errors=True)
205 shutil.rmtree(path, ignore_errors=True)
177 os.makedirs(path)
206 os.makedirs(path)
178 #print 'made dirs %s' % jn(path)
207 #print 'made dirs %s' % jn(path)
179 except OSError:
208 except OSError:
180 raise
209 raise
181
210
182
211
183 clone_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s %(dest)s' % \
212 clone_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s %(dest)s' % \
184 {'user':USER + 'error',
213 {'user':USER + 'error',
185 'pass':PASS,
214 'pass':PASS,
186 'host':HOST,
215 'host':HOST,
187 'cloned_repo':HG_REPO,
216 'cloned_repo':HG_REPO,
188 'dest':path}
217 'dest':path}
189
218
190 stdout, stderr = Command(cwd).execute('hg clone', clone_url)
219 stdout, stderr = Command(cwd).execute('hg clone', clone_url)
191
220
192 assert """abort: authorization failed""" in stderr , 'no error from wrong credentials'
221 assert """abort: authorization failed""" in stderr , 'no error from wrong credentials'
193
222
194
223
195 def test_pull():
224 def test_pull():
196 pass
225 pass
197
226
198 def test_push_modify_file(f_name='setup.py'):
227 def test_push_modify_file(f_name='setup.py'):
199 cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
228 cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
200 modified_file = jn(TESTS_TMP_PATH, HG_REPO, f_name)
229 modified_file = jn(TESTS_TMP_PATH, HG_REPO, f_name)
201 for i in xrange(5):
230 for i in xrange(5):
202 cmd = """echo 'added_line%s' >> %s""" % (i, modified_file)
231 cmd = """echo 'added_line%s' >> %s""" % (i, modified_file)
203 Command(cwd).execute(cmd)
232 Command(cwd).execute(cmd)
204
233
205 cmd = """hg ci -m 'changed file %s' %s """ % (i, modified_file)
234 cmd = """hg ci -m 'changed file %s' %s """ % (i, modified_file)
206 Command(cwd).execute(cmd)
235 Command(cwd).execute(cmd)
207
236
208 Command(cwd).execute('hg push %s' % jn(TESTS_TMP_PATH, HG_REPO))
237 Command(cwd).execute('hg push %s' % jn(TESTS_TMP_PATH, HG_REPO))
209
238
210 def test_push_new_file(commits=15):
239 def test_push_new_file(commits=15):
211
240
212 test_clone(no_errors=True)
241 test_clone(no_errors=True)
213
242
214 cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
243 cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
215 added_file = jn(path, '%ssetup.py' % _RandomNameSequence().next())
244 added_file = jn(path, '%ssetup.py' % _RandomNameSequence().next())
216
245
217 Command(cwd).execute('touch %s' % added_file)
246 Command(cwd).execute('touch %s' % added_file)
218
247
219 Command(cwd).execute('hg add %s' % added_file)
248 Command(cwd).execute('hg add %s' % added_file)
220
249
221 for i in xrange(commits):
250 for i in xrange(commits):
222 cmd = """echo 'added_line%s' >> %s""" % (i, added_file)
251 cmd = """echo 'added_line%s' >> %s""" % (i, added_file)
223 Command(cwd).execute(cmd)
252 Command(cwd).execute(cmd)
224
253
225 cmd = """hg ci -m 'commited new %s' %s """ % (i, added_file)
254 cmd = """hg ci -m 'commited new %s' %s """ % (i, added_file)
226 Command(cwd).execute(cmd)
255 Command(cwd).execute(cmd)
227
256
228 push_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s' % \
257 push_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s' % \
229 {'user':USER,
258 {'user':USER,
230 'pass':PASS,
259 'pass':PASS,
231 'host':HOST,
260 'host':HOST,
232 'cloned_repo':HG_REPO,
261 'cloned_repo':HG_REPO,
233 'dest':jn(TESTS_TMP_PATH, HG_REPO)}
262 'dest':jn(TESTS_TMP_PATH, HG_REPO)}
234
263
235 Command(cwd).execute('hg push --verbose --debug %s' % push_url)
264 Command(cwd).execute('hg push --verbose --debug %s' % push_url)
236
265
237 def test_push_wrong_credentials():
266 def test_push_wrong_credentials():
238 cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
267 cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
239 clone_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s' % \
268 clone_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s' % \
240 {'user':USER + 'xxx',
269 {'user':USER + 'xxx',
241 'pass':PASS,
270 'pass':PASS,
242 'host':HOST,
271 'host':HOST,
243 'cloned_repo':HG_REPO,
272 'cloned_repo':HG_REPO,
244 'dest':jn(TESTS_TMP_PATH, HG_REPO)}
273 'dest':jn(TESTS_TMP_PATH, HG_REPO)}
245
274
246 modified_file = jn(TESTS_TMP_PATH, HG_REPO, 'setup.py')
275 modified_file = jn(TESTS_TMP_PATH, HG_REPO, 'setup.py')
247 for i in xrange(5):
276 for i in xrange(5):
248 cmd = """echo 'added_line%s' >> %s""" % (i, modified_file)
277 cmd = """echo 'added_line%s' >> %s""" % (i, modified_file)
249 Command(cwd).execute(cmd)
278 Command(cwd).execute(cmd)
250
279
251 cmd = """hg ci -m 'commited %s' %s """ % (i, modified_file)
280 cmd = """hg ci -m 'commited %s' %s """ % (i, modified_file)
252 Command(cwd).execute(cmd)
281 Command(cwd).execute(cmd)
253
282
254 Command(cwd).execute('hg push %s' % clone_url)
283 Command(cwd).execute('hg push %s' % clone_url)
255
284
256 def test_push_wrong_path():
285 def test_push_wrong_path():
257 cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
286 cwd = path = jn(TESTS_TMP_PATH, HG_REPO)
258 added_file = jn(path, 'somefile.py')
287 added_file = jn(path, 'somefile.py')
259
288
260 try:
289 try:
261 shutil.rmtree(path, ignore_errors=True)
290 shutil.rmtree(path, ignore_errors=True)
262 os.makedirs(path)
291 os.makedirs(path)
263 print 'made dirs %s' % jn(path)
292 print 'made dirs %s' % jn(path)
264 except OSError:
293 except OSError:
265 raise
294 raise
266
295
267 Command(cwd).execute("""echo '' > %s""" % added_file)
296 Command(cwd).execute("""echo '' > %s""" % added_file)
268 Command(cwd).execute("""hg init %s""" % path)
297 Command(cwd).execute("""hg init %s""" % path)
269 Command(cwd).execute("""hg add %s""" % added_file)
298 Command(cwd).execute("""hg add %s""" % added_file)
270
299
271 for i in xrange(2):
300 for i in xrange(2):
272 cmd = """echo 'added_line%s' >> %s""" % (i, added_file)
301 cmd = """echo 'added_line%s' >> %s""" % (i, added_file)
273 Command(cwd).execute(cmd)
302 Command(cwd).execute(cmd)
274
303
275 cmd = """hg ci -m 'commited new %s' %s """ % (i, added_file)
304 cmd = """hg ci -m 'commited new %s' %s """ % (i, added_file)
276 Command(cwd).execute(cmd)
305 Command(cwd).execute(cmd)
277
306
278 clone_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s' % \
307 clone_url = 'http://%(user)s:%(pass)s@%(host)s/%(cloned_repo)s' % \
279 {'user':USER,
308 {'user':USER,
280 'pass':PASS,
309 'pass':PASS,
281 'host':HOST,
310 'host':HOST,
282 'cloned_repo':HG_REPO + '_error',
311 'cloned_repo':HG_REPO + '_error',
283 'dest':jn(TESTS_TMP_PATH, HG_REPO)}
312 'dest':jn(TESTS_TMP_PATH, HG_REPO)}
284
313
285 stdout, stderr = Command(cwd).execute('hg push %s' % clone_url)
314 stdout, stderr = Command(cwd).execute('hg push %s' % clone_url)
286 assert """abort: HTTP Error 403: Forbidden""" in stderr
315 assert """abort: HTTP Error 403: Forbidden""" in stderr
287
316
288
317
289 if __name__ == '__main__':
318 if __name__ == '__main__':
290 create_test_user(force=False)
319 create_test_user(force=False)
291 create_test_repo()
320 create_test_repo()
292 #test_push_modify_file()
321 #test_push_modify_file()
293 #test_clone()
322 #test_clone()
294 #test_clone_anonymous_ok()
323 #test_clone_anonymous_ok()
295
324
296 #test_clone_wrong_credentials()
325 #test_clone_wrong_credentials()
297
326
298 #test_pull()
327 #test_pull()
299 test_push_new_file(commits=3)
328 test_push_new_file(commits=2)
300 #test_push_wrong_path()
329 #test_push_wrong_path()
301 #test_push_wrong_credentials()
330 #test_push_wrong_credentials()
302
331
303
332
General Comments 0
You need to be logged in to leave comments. Login now