def test_project_search_controller(self): self.app.get('/p/test2/search/') # add a comment with h.push_context('test2', 'wiki', neighborhood='Projects'): page = Page.find_page('Home') page.discussion_thread.add_post(text='Sample wiki comment') M.MonQTask.run_ready() resp = self.app.get('/p/test2/search/', params=dict(q='wiki')) resp.mustcontain('Welcome to your wiki! This is the default page') # only from this one project: resp.mustcontain('/test2/') resp.mustcontain(no='/test/') # nice links to comments: resp.mustcontain('Sample wiki comment') resp.mustcontain('/Home/?limit=25#') resp.mustcontain(no='discuss/_thread') # make wiki private with h.push_context('test2', 'wiki', neighborhood='Projects'): anon_role = M.ProjectRole.by_name('*anonymous') anon_read_perm = M.ACE.allow(anon_role._id, 'read') acl = c.app.config.acl acl.remove(anon_read_perm) resp = self.app.get('/p/test2/search/', params=dict(q='wiki')) resp.mustcontain('Welcome to your wiki! This is the default page') resp.mustcontain('Sample wiki comment') resp = self.app.get('/p/test2/search/', params=dict(q='wiki'), extra_environ=dict(username=str('*anonymous'))) resp.mustcontain(no='Welcome to your wiki! This is the default page') resp.mustcontain(no='Sample wiki comment')
def test_version_race(self): # threads must not throw DuplicateKeyError # details https://sourceforge.net/p/allura/tickets/7647/ import time import random from threading import Thread, Lock page = Page.upsert('test-page') page.commit() lock = Lock() def run(n): setup_global_objects() for i in range(10): page = Page.query.get(title='test-page') page.text = 'Test Page %s.%s' % (n, i) time.sleep(random.random()) # tests use mim (mongo-in-memory), which isn't thread-safe lock.acquire() try: page.commit() finally: lock.release() t1 = Thread(target=lambda: run(1)) t2 = Thread(target=lambda: run(2)) t1.start() t2.start() t1.join() t2.join() page = Page.query.get(title='test-page') # 10 changes by each thread + initial upsert assert page.history().count() == 21, page.history().count()
def test_post_url_paginated_with_artifact(): """Post.url_paginated should return link to attached artifact, if any""" from forgewiki.model import Page page = Page.upsert(title='Test Page') thread = page.discussion_thread comment = thread.post('Comment') url = page.url() + '?limit=50#' + comment.slug assert_equals(comment.url_paginated(), url)
def test_post_url_paginated_with_artifact(): """Post.url_paginated should return link to attached artifact, if any""" from forgewiki.model import Page page = Page.upsert(title='Test Page') thread = page.discussion_thread comment = thread.post('Comment') url = page.url() + '?limit=25#' + comment.slug assert_equals(comment.url_paginated(), url)
def test_authors(self): user = M.User.by_username('test-user') admin = M.User.by_username('test-admin') with h.push_config(c, user=admin): page = Page.upsert('test-admin') page.text = 'admin' page.commit() with h.push_config(c, user=user): page.text = 'user' page.commit() authors = page.authors() assert len(authors) == 2 assert user in authors assert admin in authors user.disabled = True session(user).flush(user) authors = page.authors() assert len(authors) == 1 assert user not in authors assert admin in authors