Show More
@@ -1,160 +1,173 b'' | |||||
1 | import datetime |
|
1 | import datetime | |
2 |
|
2 | |||
3 | from rhodecode.tests import * |
|
3 | from rhodecode.tests import * | |
4 | from rhodecode.model.gist import GistModel |
|
4 | from rhodecode.model.gist import GistModel | |
5 | from rhodecode.model.meta import Session |
|
5 | from rhodecode.model.meta import Session | |
6 | from rhodecode.model.db import User, Gist |
|
6 | from rhodecode.model.db import User, Gist | |
7 |
|
7 | |||
8 |
|
8 | |||
9 | def _create_gist(f_name, content='some gist', lifetime=-1, |
|
9 | def _create_gist(f_name, content='some gist', lifetime=-1, | |
10 | description='gist-desc', gist_type='public', |
|
10 | description='gist-desc', gist_type='public', | |
11 | owner=TEST_USER_ADMIN_LOGIN): |
|
11 | owner=TEST_USER_ADMIN_LOGIN): | |
12 | gist_mapping = { |
|
12 | gist_mapping = { | |
13 | f_name: {'content': content} |
|
13 | f_name: {'content': content} | |
14 | } |
|
14 | } | |
15 | user = User.get_by_username(owner) |
|
15 | user = User.get_by_username(owner) | |
16 | gist = GistModel().create(description, owner=user, |
|
16 | gist = GistModel().create(description, owner=user, | |
17 | gist_mapping=gist_mapping, gist_type=gist_type, |
|
17 | gist_mapping=gist_mapping, gist_type=gist_type, | |
18 | lifetime=lifetime) |
|
18 | lifetime=lifetime) | |
19 | Session().commit() |
|
19 | Session().commit() | |
20 | return gist |
|
20 | return gist | |
21 |
|
21 | |||
22 |
|
22 | |||
23 | class TestGistsController(TestController): |
|
23 | class TestGistsController(TestController): | |
24 |
|
24 | |||
25 | def tearDown(self): |
|
25 | def tearDown(self): | |
26 | for g in Gist.get_all(): |
|
26 | for g in Gist.get_all(): | |
27 | GistModel().delete(g) |
|
27 | GistModel().delete(g) | |
28 | Session().commit() |
|
28 | Session().commit() | |
29 |
|
29 | |||
30 | def test_index(self): |
|
30 | def test_index(self): | |
31 | self.log_user() |
|
31 | self.log_user() | |
32 | response = self.app.get(url('gists')) |
|
32 | response = self.app.get(url('gists')) | |
33 | # Test response... |
|
33 | # Test response... | |
34 | response.mustcontain('There are no gists yet') |
|
34 | response.mustcontain('There are no gists yet') | |
35 |
|
35 | |||
36 | g1 = _create_gist('gist1').gist_access_id |
|
36 | g1 = _create_gist('gist1').gist_access_id | |
37 | g2 = _create_gist('gist2', lifetime=1400).gist_access_id |
|
37 | g2 = _create_gist('gist2', lifetime=1400).gist_access_id | |
38 | g3 = _create_gist('gist3', description='gist3-desc').gist_access_id |
|
38 | g3 = _create_gist('gist3', description='gist3-desc').gist_access_id | |
39 | g4 = _create_gist('gist4', gist_type='private').gist_access_id |
|
39 | g4 = _create_gist('gist4', gist_type='private').gist_access_id | |
40 | response = self.app.get(url('gists')) |
|
40 | response = self.app.get(url('gists')) | |
41 | # Test response... |
|
41 | # Test response... | |
42 | response.mustcontain('gist:%s' % g1) |
|
42 | response.mustcontain('gist:%s' % g1) | |
43 | response.mustcontain('gist:%s' % g2) |
|
43 | response.mustcontain('gist:%s' % g2) | |
44 | response.mustcontain('Expires: in 23 hours') # we don't care about the end |
|
44 | response.mustcontain('Expires: in 23 hours') # we don't care about the end | |
45 | response.mustcontain('gist:%s' % g3) |
|
45 | response.mustcontain('gist:%s' % g3) | |
46 | response.mustcontain('gist3-desc') |
|
46 | response.mustcontain('gist3-desc') | |
47 | response.mustcontain(no=['gist:%s' % g4]) |
|
47 | response.mustcontain(no=['gist:%s' % g4]) | |
48 |
|
48 | |||
49 | def test_index_private_gists(self): |
|
49 | def test_index_private_gists(self): | |
50 | self.log_user() |
|
50 | self.log_user() | |
51 | gist = _create_gist('gist5', gist_type='private') |
|
51 | gist = _create_gist('gist5', gist_type='private') | |
52 | response = self.app.get(url('gists', private=1)) |
|
52 | response = self.app.get(url('gists', private=1)) | |
53 | # Test response... |
|
53 | # Test response... | |
54 |
|
54 | |||
55 | #and privates |
|
55 | #and privates | |
56 | response.mustcontain('gist:%s' % gist.gist_access_id) |
|
56 | response.mustcontain('gist:%s' % gist.gist_access_id) | |
57 |
|
57 | |||
58 | def test_create_missing_description(self): |
|
58 | def test_create_missing_description(self): | |
59 | self.log_user() |
|
59 | self.log_user() | |
60 | response = self.app.post(url('gists'), |
|
60 | response = self.app.post(url('gists'), | |
61 | params={'lifetime': -1}, status=200) |
|
61 | params={'lifetime': -1}, status=200) | |
62 |
|
62 | |||
63 | response.mustcontain('Missing value') |
|
63 | response.mustcontain('Missing value') | |
64 |
|
64 | |||
65 | def test_create(self): |
|
65 | def test_create(self): | |
66 | self.log_user() |
|
66 | self.log_user() | |
67 | response = self.app.post(url('gists'), |
|
67 | response = self.app.post(url('gists'), | |
68 | params={'lifetime': -1, |
|
68 | params={'lifetime': -1, | |
69 | 'content': 'gist test', |
|
69 | 'content': 'gist test', | |
70 | 'filename': 'foo', |
|
70 | 'filename': 'foo', | |
71 | 'public': 'public'}, |
|
71 | 'public': 'public'}, | |
72 | status=302) |
|
72 | status=302) | |
73 | response = response.follow() |
|
73 | response = response.follow() | |
74 | response.mustcontain('added file: foo') |
|
74 | response.mustcontain('added file: foo') | |
75 | response.mustcontain('gist test') |
|
75 | response.mustcontain('gist test') | |
76 | response.mustcontain('<div class="ui-btn green badge">Public gist</div>') |
|
76 | response.mustcontain('<div class="ui-btn green badge">Public gist</div>') | |
77 |
|
77 | |||
78 | def test_create_with_path_with_dirs(self): |
|
78 | def test_create_with_path_with_dirs(self): | |
79 | self.log_user() |
|
79 | self.log_user() | |
80 | response = self.app.post(url('gists'), |
|
80 | response = self.app.post(url('gists'), | |
81 | params={'lifetime': -1, |
|
81 | params={'lifetime': -1, | |
82 | 'content': 'gist test', |
|
82 | 'content': 'gist test', | |
83 | 'filename': '/home/foo', |
|
83 | 'filename': '/home/foo', | |
84 | 'public': 'public'}, |
|
84 | 'public': 'public'}, | |
85 | status=200) |
|
85 | status=200) | |
86 | response.mustcontain('Filename cannot be inside a directory') |
|
86 | response.mustcontain('Filename cannot be inside a directory') | |
87 |
|
87 | |||
88 | def test_access_expired_gist(self): |
|
88 | def test_access_expired_gist(self): | |
89 | self.log_user() |
|
89 | self.log_user() | |
90 | gist = _create_gist('never-see-me') |
|
90 | gist = _create_gist('never-see-me') | |
91 | gist.gist_expires = 0 # 1970 |
|
91 | gist.gist_expires = 0 # 1970 | |
92 | Session().add(gist) |
|
92 | Session().add(gist) | |
93 | Session().commit() |
|
93 | Session().commit() | |
94 |
|
94 | |||
95 | response = self.app.get(url('gist', gist_id=gist.gist_access_id), status=404) |
|
95 | response = self.app.get(url('gist', gist_id=gist.gist_access_id), status=404) | |
96 |
|
96 | |||
97 | def test_create_private(self): |
|
97 | def test_create_private(self): | |
98 | self.log_user() |
|
98 | self.log_user() | |
99 | response = self.app.post(url('gists'), |
|
99 | response = self.app.post(url('gists'), | |
100 | params={'lifetime': -1, |
|
100 | params={'lifetime': -1, | |
101 | 'content': 'private gist test', |
|
101 | 'content': 'private gist test', | |
102 | 'filename': 'private-foo', |
|
102 | 'filename': 'private-foo', | |
103 | 'private': 'private'}, |
|
103 | 'private': 'private'}, | |
104 | status=302) |
|
104 | status=302) | |
105 | response = response.follow() |
|
105 | response = response.follow() | |
106 | response.mustcontain('added file: private-foo<') |
|
106 | response.mustcontain('added file: private-foo<') | |
107 | response.mustcontain('private gist test') |
|
107 | response.mustcontain('private gist test') | |
108 | response.mustcontain('<div class="ui-btn yellow badge">Private gist</div>') |
|
108 | response.mustcontain('<div class="ui-btn yellow badge">Private gist</div>') | |
109 |
|
109 | |||
110 | def test_create_with_description(self): |
|
110 | def test_create_with_description(self): | |
111 | self.log_user() |
|
111 | self.log_user() | |
112 | response = self.app.post(url('gists'), |
|
112 | response = self.app.post(url('gists'), | |
113 | params={'lifetime': -1, |
|
113 | params={'lifetime': -1, | |
114 | 'content': 'gist test', |
|
114 | 'content': 'gist test', | |
115 | 'filename': 'foo-desc', |
|
115 | 'filename': 'foo-desc', | |
116 | 'description': 'gist-desc', |
|
116 | 'description': 'gist-desc', | |
117 | 'public': 'public'}, |
|
117 | 'public': 'public'}, | |
118 | status=302) |
|
118 | status=302) | |
119 | response = response.follow() |
|
119 | response = response.follow() | |
120 | response.mustcontain('added file: foo-desc') |
|
120 | response.mustcontain('added file: foo-desc') | |
121 | response.mustcontain('gist test') |
|
121 | response.mustcontain('gist test') | |
122 | response.mustcontain('gist-desc') |
|
122 | response.mustcontain('gist-desc') | |
123 | response.mustcontain('<div class="ui-btn green badge">Public gist</div>') |
|
123 | response.mustcontain('<div class="ui-btn green badge">Public gist</div>') | |
124 |
|
124 | |||
125 | def test_new(self): |
|
125 | def test_new(self): | |
126 | self.log_user() |
|
126 | self.log_user() | |
127 | response = self.app.get(url('new_gist')) |
|
127 | response = self.app.get(url('new_gist')) | |
128 |
|
128 | |||
129 | def test_update(self): |
|
129 | def test_update(self): | |
130 | self.skipTest('not implemented') |
|
130 | self.skipTest('not implemented') | |
131 | response = self.app.put(url('gist', gist_id=1)) |
|
131 | response = self.app.put(url('gist', gist_id=1)) | |
132 |
|
132 | |||
133 | def test_delete(self): |
|
133 | def test_delete(self): | |
134 | self.log_user() |
|
134 | self.log_user() | |
135 | gist = _create_gist('delete-me') |
|
135 | gist = _create_gist('delete-me') | |
136 | response = self.app.delete(url('gist', gist_id=gist.gist_id)) |
|
136 | response = self.app.delete(url('gist', gist_id=gist.gist_id)) | |
137 | self.checkSessionFlash(response, 'Deleted gist %s' % gist.gist_id) |
|
137 | self.checkSessionFlash(response, 'Deleted gist %s' % gist.gist_id) | |
138 |
|
138 | |||
139 | def test_delete_normal_user_his_gist(self): |
|
139 | def test_delete_normal_user_his_gist(self): | |
140 | self.log_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS) |
|
140 | self.log_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS) | |
141 | gist = _create_gist('delete-me', owner=TEST_USER_REGULAR_LOGIN) |
|
141 | gist = _create_gist('delete-me', owner=TEST_USER_REGULAR_LOGIN) | |
142 | response = self.app.delete(url('gist', gist_id=gist.gist_id)) |
|
142 | response = self.app.delete(url('gist', gist_id=gist.gist_id)) | |
143 | self.checkSessionFlash(response, 'Deleted gist %s' % gist.gist_id) |
|
143 | self.checkSessionFlash(response, 'Deleted gist %s' % gist.gist_id) | |
144 |
|
144 | |||
145 | def test_delete_normal_user_not_his_own_gist(self): |
|
145 | def test_delete_normal_user_not_his_own_gist(self): | |
146 | self.log_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS) |
|
146 | self.log_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS) | |
147 | gist = _create_gist('delete-me') |
|
147 | gist = _create_gist('delete-me') | |
148 | response = self.app.delete(url('gist', gist_id=gist.gist_id), status=403) |
|
148 | response = self.app.delete(url('gist', gist_id=gist.gist_id), status=403) | |
149 |
|
149 | |||
150 | def test_show(self): |
|
150 | def test_show(self): | |
151 | gist = _create_gist('gist-show-me') |
|
151 | gist = _create_gist('gist-show-me') | |
152 | response = self.app.get(url('gist', gist_id=gist.gist_access_id)) |
|
152 | response = self.app.get(url('gist', gist_id=gist.gist_access_id)) | |
153 | response.mustcontain('added file: gist-show-me<') |
|
153 | response.mustcontain('added file: gist-show-me<') | |
154 | response.mustcontain('test_admin (RhodeCode Admin) - created') |
|
154 | response.mustcontain('test_admin (RhodeCode Admin) - created') | |
155 | response.mustcontain('gist-desc') |
|
155 | response.mustcontain('gist-desc') | |
156 | response.mustcontain('<div class="ui-btn green badge">Public gist</div>') |
|
156 | response.mustcontain('<div class="ui-btn green badge">Public gist</div>') | |
157 |
|
157 | |||
|
158 | def test_show_as_raw(self): | |||
|
159 | gist = _create_gist('gist-show-me', content='GIST CONTENT') | |||
|
160 | response = self.app.get(url('formatted_gist', | |||
|
161 | gist_id=gist.gist_access_id, format='raw')) | |||
|
162 | self.assertEqual(response.body, 'GIST CONTENT') | |||
|
163 | ||||
|
164 | def test_show_as_raw_individual_file(self): | |||
|
165 | gist = _create_gist('gist-show-me-raw', content='GIST BODY') | |||
|
166 | response = self.app.get(url('formatted_gist_file', | |||
|
167 | gist_id=gist.gist_access_id, format='raw', | |||
|
168 | revision='tip', f_path='gist-show-me-raw')) | |||
|
169 | self.assertEqual(response.body, 'GIST BODY') | |||
|
170 | ||||
158 | def test_edit(self): |
|
171 | def test_edit(self): | |
159 | self.skipTest('not implemented') |
|
172 | self.skipTest('not implemented') | |
160 | response = self.app.get(url('edit_gist', gist_id=1)) |
|
173 | response = self.app.get(url('edit_gist', gist_id=1)) |
General Comments 0
You need to be logged in to leave comments.
Login now