Parent: [51277b] (diff)

Child: [c0629b] (diff)

Download this file

test_root.py    149 lines (125 with data), 7.2 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
 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
# -*- coding: utf-8 -*-
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""
Functional test suite for the root controller.
This is an example of how functional tests can be written for controllers.
As opposed to a unit-test, which test a small unit of functionality,
functional tests exercise the whole application and its WSGI stack.
Please read http://pythonpaste.org/webtest/ for more information.
"""
from tg import config
from nose.tools import assert_equal
from ming.orm.ormsession import ThreadLocalORMSession
from allura.tests import decorators as td
from allura.tests import TestController
from allura import model as M
from allura.lib.helpers import push_config
class TestRootController(TestController):
def setUp(self):
super(TestRootController, self).setUp()
n_adobe = M.Neighborhood.query.get(name='Adobe')
assert n_adobe
u_admin = M.User.query.get(username='test-admin')
assert u_admin
p_adobe2 = n_adobe.register_project('adobe-2', u_admin)
def test_index(self):
response = self.app.get('/')
assert_equal(response.html.find('h2',{'class':'dark title'}).contents[0].strip(), 'All Neighborhoods')
nbhds = response.html.findAll('td',{'class':'nbhd'})
assert nbhds[0].find('a').get('href') == '/adobe/'
cat_links = response.html.find('div',{'id':'sidebar'}).findAll('li')
assert len(cat_links) == 4
assert cat_links[0].find('a').get('href') == '/browse/clustering'
assert cat_links[0].find('a').find('span').string == 'Clustering'
def test_sidebar_escaping(self):
# use this as a convenient way to get something in the sidebar
M.ProjectCategory(name='test-xss', label='<script>alert(1)</script>')
ThreadLocalORMSession.flush_all()
response = self.app.get('/')
# inject it into the sidebar data
content = str(response.html.find('div',{'id':'content_base'}))
assert '<script>' not in content
assert '&lt;script&gt;' in content
def test_strange_accept_headers(self):
hdrs = [
'text/plain;text/html;text/*',
'text/html,application/xhtml+xml,application/xml;q=0.9;text/plain;q=0.8,image/png,*/*;q=0.5' ]
for hdr in hdrs:
# malformed headers used to return 500, just make sure they don't now
self.app.get('/', headers=dict(Accept=hdr), validate_skip=True)
def test_project_browse(self):
com_cat = M.ProjectCategory.query.find(dict(label='Communications')).first()
fax_cat = M.ProjectCategory.query.find(dict(label='Fax')).first()
M.Project.query.find(dict(name='adobe-1')).first().category_id = com_cat._id
response = self.app.get('/browse')
assert len(response.html.findAll('a',{'href':'/adobe/adobe-1/'})) == 1
assert len(response.html.findAll('a',{'href':'/adobe/adobe-2/'})) == 1
response = self.app.get('/browse/communications')
assert len(response.html.findAll('a',{'href':'/adobe/adobe-1/'})) == 1
assert len(response.html.findAll('a',{'href':'/adobe/adobe-2/'})) == 0
response = self.app.get('/browse/communications/fax')
assert len(response.html.findAll('a',{'href':'/adobe/adobe-1/'})) == 0
assert len(response.html.findAll('a',{'href':'/adobe/adobe-2/'})) == 0
def test_project_redirect(self):
with push_config(config, **{'activitystream.enabled': 'false'}):
resp = self.app.get('/p/test2/')
assert_equal(resp.status_int, 302)
assert_equal(resp.location, 'http://localhost/p/test2/admin/')
with push_config(config, **{'activitystream.enabled': 'true'}):
resp = self.app.get('/p/test2/')
assert_equal(resp.status_int, 302)
assert_equal(resp.location, 'http://localhost/p/test2/activity/')
with push_config(config, **{'activitystream.enabled': 'false'}):
self.app.cookies['activitystream.enabled'] = 'true'
resp = self.app.get('/p/test2/')
assert_equal(resp.status_int, 302)
assert_equal(resp.location, 'http://localhost/p/test2/activity/')
def test_neighborhood_home(self):
# Install home app
nb = M.Neighborhood.query.get(name='Adobe')
p = nb.neighborhood_project
p.install_app('home', 'home', 'Home', ordinal=0)
response = self.app.get('/adobe/')
projects = response.html.findAll('div',{'class':'border card'})
assert len(projects) == 2
cat_links = response.html.find('div',{'id':'sidebar'}).findAll('ul')[1].findAll('li')
assert len(cat_links) == 3, cat_links
assert cat_links[0].find('a').get('href') == '/adobe/browse/clustering'
assert cat_links[0].find('a').find('span').string == 'Clustering'
def test_neighborhood_project_browse(self):
com_cat = M.ProjectCategory.query.find(dict(label='Communications')).first()
fax_cat = M.ProjectCategory.query.find(dict(label='Fax')).first()
M.Project.query.find(dict(name='adobe-1')).first().category_id = com_cat._id
M.Project.query.find(dict(name='adobe-2')).first().category_id = fax_cat._id
response = self.app.get('/adobe/browse')
assert len(response.html.findAll('a',{'href':'/adobe/adobe-1/'})) == 1
assert len(response.html.findAll('a',{'href':'/adobe/adobe-2/'})) == 1
response = self.app.get('/adobe/browse/communications')
assert len(response.html.findAll('a',{'href':'/adobe/adobe-1/'})) == 1
assert len(response.html.findAll('a',{'href':'/adobe/adobe-2/'})) == 1
response = self.app.get('/adobe/browse/communications/fax')
assert len(response.html.findAll('a',{'href':'/adobe/adobe-1/'})) == 0
assert len(response.html.findAll('a',{'href':'/adobe/adobe-2/'})) == 1
@td.with_wiki
def test_markdown_to_html(self):
n = M.Neighborhood.query.get(name='Projects')
r = self.app.get('/nf/markdown_to_html?markdown=*aaa*bb[wiki:Home]&project=test&app=bugs&neighborhood=%s' % n._id, validate_chunk=True)
assert '<p><em>aaa</em>bb<a class="alink" href="/p/test/wiki/Home/">[wiki:Home]</a></p>' in r, r
def test_slash_redirect(self):
r = self.app.get('/p',status=301)
r = self.app.get('/p/',status=302)