Parent: [3abb2e] (diff)

Child: [c2e3f8] (diff)

Download this file

test_helpers.py    90 lines (75 with data), 2.7 kB

 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
from os import path, environ
from tg import config
from pylons import c, g
from paste.deploy import loadapp
from paste.script.appinstall import SetupCommand
from nose.tools import eq_
from allura import model as M
from allura.lib import helpers as h
from . import helpers
def setUp(self):
"""Method called by nose before running each test"""
helpers.setup_basic_test()
def test_really_unicode():
s = h.really_unicode('\xef\xbb\xbf<?xml version="1.0" encoding="utf-8" ?>')
assert s.startswith(u'\ufeff')
s = h.really_unicode(open('allura/tests/unicode_test.txt').read())
assert isinstance(s, unicode)
def test_render_genshi_plaintext():
here_dir = path.dirname(__file__)
tpl = path.join(here_dir, 'genshi_hello_tmpl')
text = h.render_genshi_plaintext(tpl, object='world')
eq_(u'Hello, world!\n', text)
def test_find_project():
proj, rest = h.find_project('/p/test/foo')
assert proj is not None
proj, rest = h.find_project('/p/testable/foo')
assert proj is None
def test_find_executable():
assert h.find_executable('bash') == '/bin/bash'
def test_make_users():
r = h.make_users([None]).next()
assert r.username == '*anonymous', r
def test_make_roles():
g.set_project('test')
g.set_app('hello')
u = M.User.anonymous()
pr = u.project_role()
assert h.make_roles([pr._id]).next() == pr
def test_context_setters():
h.set_context('test', 'hello')
assert c.project is not None
assert c.app is not None
cfg_id = c.app.config._id
h.set_context('test', app_config_id=cfg_id)
assert c.project is not None
assert c.app is not None
h.set_context('test', app_config_id=str(cfg_id))
assert c.project is not None
assert c.app is not None
c.project = c.app = None
with h.push_context('test', 'hello'):
assert c.project is not None
assert c.app is not None
assert c.project == c.app == None
with h.push_context('test', app_config_id=cfg_id):
assert c.project is not None
assert c.app is not None
assert c.project == c.app == None
with h.push_context('test', app_config_id=str(cfg_id)):
assert c.project is not None
assert c.app is not None
assert c.project == c.app == None
del c.project
del c.app
with h.push_context('test', app_config_id=str(cfg_id)):
assert c.project is not None
assert c.app is not None
assert not hasattr(c, 'project')
assert not hasattr(c, 'app')
def test_encode_keys():
kw = h.encode_keys({u'foo':5})
assert type(kw.keys()[0]) != unicode
def test_ago():
from datetime import datetime, timedelta
assert h.ago(datetime.utcnow() - timedelta(days=2)) == '2 days ago'