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