##// END OF EJS Templates
Update LICENSE.md to include license information about History.js
Update LICENSE.md to include license information about History.js

File last commit:

r4116:ffd45b18 rhodecode-2.2.5-gpl
r4134:0fef0864 rhodecode-2.2.5-gpl
Show More
test_admin_gists.py
172 lines | 7.0 KiB | text/x-python | PythonLexer
added tests for gist expiration
r3844 import datetime
Implemented simple gist functionality ref #530....
r3840 from rhodecode.tests import *
from rhodecode.model.gist import GistModel
from rhodecode.model.meta import Session
from rhodecode.model.db import User, Gist
def _create_gist(f_name, content='some gist', lifetime=-1,
Gist: implemented delete of gists by owner, or super admin
r3843 description='gist-desc', gist_type='public',
owner=TEST_USER_ADMIN_LOGIN):
Implemented simple gist functionality ref #530....
r3840 gist_mapping = {
f_name: {'content': content}
}
Gist: implemented delete of gists by owner, or super admin
r3843 user = User.get_by_username(owner)
Implemented simple gist functionality ref #530....
r3840 gist = GistModel().create(description, owner=user,
gist_mapping=gist_mapping, gist_type=gist_type,
lifetime=lifetime)
Session().commit()
return gist
class TestGistsController(TestController):
def tearDown(self):
for g in Gist.get_all():
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')
small tests improvements
r3849 g1 = _create_gist('gist1').gist_access_id
g2 = _create_gist('gist2', lifetime=1400).gist_access_id
g3 = _create_gist('gist3', description='gist3-desc').gist_access_id
g4 = _create_gist('gist4', gist_type='private').gist_access_id
Implemented simple gist functionality ref #530....
r3840 response = self.app.get(url('gists'))
# Test response...
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 response.mustcontain('gist: %s' % g1)
response.mustcontain('gist: %s' % g2)
Implemented simple gist functionality ref #530....
r3840 response.mustcontain('Expires: in 23 hours') # we don't care about the end
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 response.mustcontain('gist: %s' % g3)
Implemented simple gist functionality ref #530....
r3840 response.mustcontain('gist3-desc')
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 response.mustcontain(no=['gist: %s' % g4])
Implemented simple gist functionality ref #530....
r3840
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
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 response.mustcontain('gist: %s' % gist.gist_access_id)
Implemented simple gist functionality ref #530....
r3840
def test_create_missing_description(self):
self.log_user()
response = self.app.post(url('gists'),
params={'lifetime': -1}, 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'},
status=302)
response = response.follow()
response.mustcontain('added file: foo')
response.mustcontain('gist test')
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 response.mustcontain('<div class="btn btn-mini btn-success disabled">Public Gist</div>')
Implemented simple gist functionality ref #530....
r3840
Gist: don't allow files inside directories when creating gists
r3846 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'},
status=200)
response.mustcontain('Filename cannot be inside a directory')
added tests for gist expiration
r3844 def test_access_expired_gist(self):
self.log_user()
gist = _create_gist('never-see-me')
gist.gist_expires = 0 # 1970
Session().add(gist)
Session().commit()
refactored url.resource to full definition of routes...
r3866 response = self.app.get(url('gist', gist_id=gist.gist_access_id), status=404)
added tests for gist expiration
r3844
Implemented simple gist functionality ref #530....
r3840 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'},
status=302)
response = response.follow()
response.mustcontain('added file: private-foo<')
response.mustcontain('private gist test')
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 response.mustcontain('<div class="btn btn-mini btn-warning disabled">Private Gist</div>')
Implemented simple gist functionality ref #530....
r3840
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'},
status=302)
response = response.follow()
response.mustcontain('added file: foo-desc')
response.mustcontain('gist test')
response.mustcontain('gist-desc')
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 response.mustcontain('<div class="btn btn-mini btn-success disabled">Public Gist</div>')
Implemented simple gist functionality ref #530....
r3840
def test_new(self):
self.log_user()
response = self.app.get(url('new_gist'))
def test_update(self):
self.skipTest('not implemented')
refactored url.resource to full definition of routes...
r3866 response = self.app.put(url('gist', gist_id=1))
Implemented simple gist functionality ref #530....
r3840
def test_delete(self):
Gist: implemented delete of gists by owner, or super admin
r3843 self.log_user()
gist = _create_gist('delete-me')
refactored url.resource to full definition of routes...
r3866 response = self.app.delete(url('gist', gist_id=gist.gist_id))
Gist: implemented delete of gists by owner, or super admin
r3843 self.checkSessionFlash(response, 'Deleted gist %s' % gist.gist_id)
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)
refactored url.resource to full definition of routes...
r3866 response = self.app.delete(url('gist', gist_id=gist.gist_id))
Gist: implemented delete of gists by owner, or super admin
r3843 self.checkSessionFlash(response, 'Deleted gist %s' % gist.gist_id)
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')
refactored url.resource to full definition of routes...
r3866 response = self.app.delete(url('gist', gist_id=gist.gist_id), status=403)
Implemented simple gist functionality ref #530....
r3840
def test_show(self):
gist = _create_gist('gist-show-me')
refactored url.resource to full definition of routes...
r3866 response = self.app.get(url('gist', gist_id=gist.gist_access_id))
Implemented simple gist functionality ref #530....
r3840 response.mustcontain('added file: gist-show-me<')
gists: add some API related code improvements
r3842 response.mustcontain('test_admin (RhodeCode Admin) - created')
Implemented simple gist functionality ref #530....
r3840 response.mustcontain('gist-desc')
Bradley M. Kuhn
Imported some of the GPLv3'd changes from RhodeCode v2.2.5....
r4116 response.mustcontain('<div class="btn btn-mini btn-success disabled">Public Gist</div>')
Implemented simple gist functionality ref #530....
r3840
added tests for raw gists
r3873 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'))
self.assertEqual(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'))
self.assertEqual(response.body, 'GIST BODY')
Implemented simple gist functionality ref #530....
r3840 def test_edit(self):
refactored url.resource to full definition of routes...
r3866 response = self.app.get(url('edit_gist', gist_id=1))