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