def test_delete_undelete(self): r = self.app.get('/admin/discussion/forums') r = self.app.get('/admin/discussion/forums') r.forms[1]['add_forum.shortname'] = 'testforum' r.forms[1]['add_forum.name'] = 'Test Forum' r = r.forms[1].submit() r = self.app.get('/admin/discussion/forums') assert len(r.html.findAll('input', {'value': 'Delete'})) == 2 h.set_context('test', 'Forum', neighborhood='Projects') frm = FM.Forum.query.get(shortname='testforum') r = self.app.post('/admin/discussion/update_forums', params={'forum-0.delete': 'on', 'forum-0.id': str(frm._id), 'forum-0.name': 'New Test Forum', 'forum-0.description': 'My desc'}) r = self.app.get('/admin/discussion/forums') assert len(r.html.findAll('input', {'value': 'Delete'})) == 1 r = self.app.post('/admin/discussion/update_forums', params={'forum-0.undelete': 'on', 'forum-0.id': str(frm._id), 'forum-0.name': 'New Test Forum', 'forum-0.description': 'My desc'}) r = self.app.get('/admin/discussion/forums') assert len(r.html.findAll('input', {'value': 'Delete'})) == 2
def test_app_globals(): g.oid_session() g.oid_session() h.set_context('test', 'wiki', neighborhood='Projects') assert g.app_static('css/wiki.css') == '/nf/_static_/wiki/css/wiki.css', g.app_static('css/wiki.css') assert g.url('/foo', a='foo bar') == 'http://localhost:80/foo?a=foo+bar', g.url('/foo', a='foo bar') assert g.url('/foo') == 'http://localhost:80/foo', g.url('/foo')
def test_paged_diffs_with_detect_copies(self): # setup h.set_context('test', 'src-weird', neighborhood='Projects') repo_dir = pkg_resources.resource_filename( 'forgegit', 'tests/data') repo = GM.Repository( name='weird-chars.git', fs_path=repo_dir, url_path='/src-weird/', tool='git', status='creating') repo.refresh() ThreadLocalORMSession.flush_all() ThreadLocalORMSession.close_all() diffs = repo.paged_diffs('346c52c1dddc729e2c2711f809336401f0ff925e') # Test copy expected = { 'added': [], 'removed': [], 'copied': [{'new': u'README.copy', 'old': u'README', 'ratio': 1.0}], 'renamed': [], 'changed': [u'README'], 'total': 2, } assert_equals(diffs, expected) diffs = repo.paged_diffs('3cb2bbcd7997f89060a14fe8b1a363f01883087f') # Test rename expected = { 'added': [], 'removed': [], 'copied': [], 'renamed': [{'new': u'README', 'old': u'README-copy.md', 'ratio': 1.0}], 'changed': [], 'total': 1, } assert_equals(diffs, expected)
def test_related_artifacts(self): summary = 'test sidebar logic for a ticket page' self.new_ticket(summary=summary) response = self.app.get('/p/test/bugs/1/') assert 'Related Pages' not in response self.app.post('/wiki/aaa/update', params={ 'title':'aaa', 'text':'', 'labels':'', 'labels_old':'', 'viewable_by-0.id':'all'}) self.new_ticket(summary='bbb') ThreadLocalORMSession.flush_all() M.MonQTask.run_ready() ThreadLocalORMSession.flush_all() h.set_context('test', 'wiki', neighborhood='Projects') a = wm.Page.query.find(dict(title='aaa')).first() a.text = '\n[bugs:#1]\n' ThreadLocalORMSession.flush_all() M.MonQTask.run_ready() ThreadLocalORMSession.flush_all() b = tm.Ticket.query.find(dict(ticket_num=2)).first() b.description = '\n[#1]\n' ThreadLocalORMSession.flush_all() M.MonQTask.run_ready() ThreadLocalORMSession.flush_all() response = self.app.get('/p/test/bugs/1/') assert 'Related' in response assert 'Wiki: aaa' in response assert 'Ticket: #2' in response
def test_make_app_admin_only(): h.set_context("test", "wiki", neighborhood="Projects") anon = M.User.anonymous() dev = M.User.query.get(username="******") admin = M.User.query.get(username="******") c.project.add_user(dev, ["Developer"]) ThreadLocalORMSession.flush_all() Credentials.get().clear() assert has_access(c.app, "read", user=anon)() assert has_access(c.app, "read", user=dev)() assert has_access(c.app, "read", user=admin)() assert not has_access(c.app, "create", user=anon)() assert has_access(c.app, "create", user=dev)() assert has_access(c.app, "create", user=admin)() assert c.app.is_visible_to(anon) assert c.app.is_visible_to(dev) assert c.app.is_visible_to(admin) h.make_app_admin_only(c.app) ThreadLocalORMSession.flush_all() Credentials.get().clear() assert not has_access(c.app, "read", user=anon)() assert not has_access(c.app, "read", user=dev)() assert has_access(c.app, "read", user=admin)() assert not has_access(c.app, "create", user=anon)() assert not has_access(c.app, "create", user=dev)() assert has_access(c.app, "create", user=admin)() assert not c.app.is_visible_to(anon) assert not c.app.is_visible_to(dev) assert c.app.is_visible_to(admin)
def set_context(self, rcpt): if rcpt == self.nick: return False chan = self.channels.get(rcpt, None) if not chan: return False h.set_context(chan.project_id, app_config_id=chan.app_config_id) return True
def markdown_to_html(self, markdown, neighborhood=None, project=None, app=None): """Convert markdown to html.""" if neighborhood is None or project is None: raise exc.HTTPBadRequest() h.set_context(project, app, neighborhood=neighborhood) html = g.markdown_wiki.convert(markdown) return html
def test_tarball_aware_of_branches(self): rev = '19' branch_content = sorted(['test-svn-tags-19-branches-aaa/', 'test-svn-tags-19-branches-aaa/aaa.txt', 'test-svn-tags-19-branches-aaa/svn-commit.tmp', 'test-svn-tags-19-branches-aaa/README']) h.set_context('test', 'svn-tags', neighborhood='Projects') tmpdir = tg.config['scm.repos.tarball.root'] tarball_path = os.path.join(tmpdir, 'svn/t/te/test/testsvn-trunk-tags-branches/') fn = tarball_path + 'test-svn-tags-19-branches-aaa.zip' self.svn_tags.tarball(rev, '/branches/aaa/') assert os.path.isfile(fn), fn snapshot = ZipFile(fn, 'r') assert_equal(sorted(snapshot.namelist()), branch_content) os.remove(fn) self.svn_tags.tarball(rev, '/branches/aaa/some/path/') assert os.path.isfile(fn), fn snapshot = ZipFile(fn, 'r') assert_equal(sorted(snapshot.namelist()), branch_content) os.remove(fn) # if inside of branches, but no branch is specified # expect snapshot of trunk fn = tarball_path + 'test-svn-tags-19-trunk.zip' self.svn_tags.tarball(rev, '/branches/') assert os.path.isfile(fn), fn snapshot = ZipFile(fn, 'r') assert_equal(sorted(snapshot.namelist()), sorted(['test-svn-tags-19-trunk/', 'test-svn-tags-19-trunk/aaa.txt', 'test-svn-tags-19-trunk/bbb.txt', 'test-svn-tags-19-trunk/ccc.txt', 'test-svn-tags-19-trunk/README'])) shutil.rmtree(tarball_path, ignore_errors=True)
def test_duplicate_forum_names(self): r = self.app.get('/admin/discussion/forums') r.forms[1]['add_forum.shortname'] = 'a' r.forms[1]['add_forum.name'] = 'Forum A' r = r.forms[1].submit() r = self.app.get('/admin/discussion/forums') r.forms[1]['add_forum.shortname'] = 'b' r.forms[1]['add_forum.name'] = 'Forum B' r = r.forms[1].submit() h.set_context('test', 'Forum', neighborhood='Projects') forum_a = FM.Forum.query.get(shortname='a') self.app.post('/admin/discussion/update_forums', params={'forum-0.delete': 'on', 'forum-0.id': str(forum_a._id), 'forum-0.name': 'Forum A', 'forum-0.description': '' }) # Now we have two forums: 'a', and 'b'. 'a' is deleted. # Let's try to create new forums with these names. r = self.app.get('/admin/discussion/forums') r.forms[1]['add_forum.shortname'] = 'a' r.forms[1]['add_forum.name'] = 'Forum A' r = r.forms[1].submit() assert 'error' in r r = self.app.get('/admin/discussion/forums') r.forms[1]['add_forum.shortname'] = 'b' r.forms[1]['add_forum.name'] = 'Forum B' r = r.forms[1].submit() assert 'error' in r
def test_upsert(self): h.set_context('test', 'test1', neighborhood='Projects') mr = M.MergeRequest.upsert( downstream=ming.base.Object( project_id=c.project._id, mount_point='test2', commit_id='foo:2'), target_branch='foobranch', summary='summary', description='description') u = M.User.by_username('test-admin') assert_equal(mr.creator, u) assert_equal(mr.creator_name, u.get_pref('display_name')) assert_equal(mr.creator_url, u.url()) assert_equal(mr.downstream_url, '/p/test/test2/') assert_equal(mr.downstream_repo_url, 'http://svn.localhost/p/test/test2/') with mock.patch('forgesvn.model.svn.SVNLibWrapper') as _svn,\ mock.patch('forgesvn.model.svn.SVNImplementation._map_log') as _map_log: mr.app.repo._impl.head = 1 _svn().log.return_value = [mock.Mock(revision=mock.Mock(number=2))] _map_log.return_value = 'bar' assert_equal(mr.commits, ['bar']) # can't do assert_called_once_with because pysvn.Revision doesn't compare nicely assert_equal(_svn().log.call_count, 1) assert_equal(_svn().log.call_args[0], ('file:///tmp/svn/p/test/test2',)) assert_equal(_svn().log.call_args[1]['revision_start'].number, 2) assert_equal(_svn().log.call_args[1]['limit'], 25) _map_log.assert_called_once_with(_svn().log.return_value[0], 'file:///tmp/svn/p/test/test2')
def test_new_image_attachment_content(self): self.app.post('/wiki/TEST/update', params={ 'title': 'TEST', 'text': 'sometext', 'labels': '', 'viewable_by-0.id': 'all'}) file_name = 'neo-icon-set-454545-256x350.png' file_path = os.path.join( allura.__path__[0], 'nf', 'allura', 'images', file_name) file_data = file(file_path).read() upload = ('file_info', file_name, file_data) self.app.post('/wiki/TEST/attach', upload_files=[upload]) h.set_context('test', 'wiki', neighborhood='Projects') page = model.Page.query.find(dict(title='TEST')).first() filename = page.attachments[0].filename uploaded = PIL.Image.open(file_path) r = self.app.get('/wiki/TEST/attachment/' + filename) downloaded = PIL.Image.open(StringIO.StringIO(r.body)) assert uploaded.size == downloaded.size r = self.app.get('/wiki/TEST/attachment/' + filename + '/thumb') thumbnail = PIL.Image.open(StringIO.StringIO(r.body)) assert thumbnail.size == (100, 100) # Make sure thumbnail is absent r = self.app.get('/wiki/TEST/') img_srcs = [i['src'] for i in r.html.findAll('img')] assert ('/p/test/wiki/TEST/attachment/' + filename) not in img_srcs, img_srcs
def test_make_app_admin_only(): h.set_context('test', 'wiki', neighborhood='Projects') anon = M.User.anonymous() dev = M.User.query.get(username='******') admin = M.User.query.get(username='******') c.project.add_user(dev, ['Developer']) ThreadLocalORMSession.flush_all() Credentials.get().clear() assert has_access(c.app, 'read', user=anon)() assert has_access(c.app, 'read', user=dev)() assert has_access(c.app, 'read', user=admin)() assert not has_access(c.app, 'create', user=anon)() assert has_access(c.app, 'create', user=dev)() assert has_access(c.app, 'create', user=admin)() assert c.app.is_visible_to(anon) assert c.app.is_visible_to(dev) assert c.app.is_visible_to(admin) h.make_app_admin_only(c.app) ThreadLocalORMSession.flush_all() Credentials.get().clear() assert not has_access(c.app, 'read', user=anon)() assert not has_access(c.app, 'read', user=dev)() assert has_access(c.app, 'read', user=admin)() assert not has_access(c.app, 'create', user=anon)() assert not has_access(c.app, 'create', user=dev)() assert has_access(c.app, 'create', user=admin)() assert not c.app.is_visible_to(anon) assert not c.app.is_visible_to(dev) assert c.app.is_visible_to(admin)
def test_related_links(self): response = self.app.get('/wiki/TEST/').follow() assert 'Edit TEST' in response assert 'Related' not in response self.app.post('/wiki/TEST/update', params={ 'title': 'TEST', 'text': 'sometext', 'labels': '', 'viewable_by-0.id': 'all'}) self.app.post('/wiki/aaa/update', params={ 'title': 'aaa', 'text': '', 'labels': '', 'viewable_by-0.id': 'all'}) self.app.post('/wiki/bbb/update', params={ 'title': 'bbb', 'text': '', 'labels': '', 'viewable_by-0.id': 'all'}) h.set_context('test', 'wiki', neighborhood='Projects') a = model.Page.query.find(dict(title='aaa')).first() a.text = '\n[TEST]\n' b = model.Page.query.find(dict(title='TEST')).first() b.text = '\n[bbb]\n' ThreadLocalORMSession.flush_all() M.MonQTask.run_ready() ThreadLocalORMSession.flush_all() ThreadLocalORMSession.close_all() response = self.app.get('/wiki/TEST/') assert 'Related' in response assert 'aaa' in response assert 'bbb' in response
def _setup_weird_chars_repo(self): h.set_context('test', 'weird-chars', neighborhood='Projects') repo_dir = pkg_resources.resource_filename('forgegit', 'tests/data') c.app.repo.fs_path = repo_dir c.app.repo.status = 'ready' c.app.repo.name = 'weird-chars.git' ThreadLocalORMSession.flush_all() c.app.repo.refresh()
def setup_with_tools(): h.set_context("test", "wiki", neighborhood="Projects") Checkmessage.query.remove({}) WM.Page.query.remove({}) WM.PageHistory.query.remove({}) M.Shortlink.query.remove({}) c.user = M.User.query.get(username="******") Checkmessage.project = c.project Checkmessage.app_config = c.app.config
def setUp(): controller = TestController() controller.setUp() controller.app.get("/wiki/Home/") setup_global_objects() ThreadLocalORMSession.close_all() h.set_context("test", "wiki", neighborhood="Projects") ThreadLocalORMSession.flush_all() ThreadLocalORMSession.close_all()
def setup_with_tools(): h.set_context('test', 'wiki', neighborhood='Projects') Checkmessage.query.remove({}) WM.Page.query.remove({}) WM.PageHistory.query.remove({}) M.Shortlink.query.remove({}) c.user = M.User.query.get(username='******') Checkmessage.project = c.project Checkmessage.app_config = c.app.config
def setup_with_tools(self): setup_global_objects() h.set_context(test_project_with_repo, "src-git", neighborhood="Projects") repo_dir = pkg_resources.resource_filename("forgeuserstats", "tests/data") c.app.repo.fs_path = repo_dir c.app.repo.name = "testgit.git" self.repo = c.app.repo self.repo.refresh() self.rev = self.repo.commit("HEAD")
def setUp(): controller = TestController() controller.setUp() controller.app.get('/wiki/Home/') setup_global_objects() ThreadLocalORMSession.close_all() h.set_context('test', 'wiki', neighborhood='Projects') ThreadLocalORMSession.flush_all() ThreadLocalORMSession.close_all()
def test_tarball_tags_aware(self): h.set_context('test', 'svn-tags', neighborhood='Projects') shutil.rmtree(c.app.repo.tarball_path, ignore_errors=True) r = self.app.get('/p/test/svn-tags/19/tree/') form = r.html.find('form', 'tarball') assert_equal(form.button.text, 'Download Snapshot') assert_equal(form.get('action'), '/p/test/svn-tags/19/tarball') r = self.app.get('/p/test/svn-tags/19/tree/tags/tag-1.0/') form = r.html.find('form', 'tarball') assert_equal(form.button.text, 'Download Snapshot') assert_equal(form.get('action'), '/p/test/svn-tags/19/tarball') assert_equal( form.find('input', attrs=dict(name='path')).get('value'), '/tags/tag-1.0') r = self.app.get( '/p/test/svn-tags/19/tarball_status?path=/tags/tag-1.0') assert_equal(r.json['status'], None) r = self.app.post('/p/test/svn-tags/19/tarball', dict(path='/tags/tag-1.0')).follow() assert 'Generating snapshot...' in r M.MonQTask.run_ready() r = self.app.get( '/p/test/svn-tags/19/tarball_status?path=/tags/tag-1.0') assert_equal(r.json['status'], 'complete') r = self.app.get('/p/test/svn-tags/19/tarball_status?path=/trunk') assert_equal(r.json['status'], None) r = self.app.post('/p/test/svn-tags/19/tarball', dict(path='/trunk/')).follow() assert 'Generating snapshot...' in r M.MonQTask.run_ready() r = self.app.get('/p/test/svn-tags/19/tarball_status?path=/trunk') assert_equal(r.json['status'], 'complete') r = self.app.get( '/p/test/svn-tags/19/tarball_status?path=/branches/aaa/') assert_equal(r.json['status'], None) # All of the following also should be ready because... # ...this is essentially the same as trunk snapshot r = self.app.get( '/p/test/svn-tags/19/tarball_status?path=/trunk/some/path/') assert_equal(r.json['status'], 'complete') r = self.app.get('/p/test/svn-tags/19/tarball_status') assert_equal(r.json['status'], 'complete') # ...the same as trunk, 'cause concrete tag isn't specified r = self.app.get('/p/test/svn-tags/19/tarball_status?path=/tags/') assert_equal(r.json['status'], 'complete') # ...the same as trunk, 'cause concrete branch isn't specified r = self.app.get('/p/test/svn-tags/19/tarball_status?path=/branches/') assert_equal(r.json['status'], 'complete') # ...this is essentially the same as tag snapshot r = self.app.get( '/p/test/svn-tags/19/tarball_status?path=/tags/tag-1.0/dir') assert_equal(r.json['status'], 'complete')
def setup_with_tools(self): h.set_context('test', 'src-git', neighborhood='Projects') repo_dir = pkg_resources.resource_filename('forgegit', 'tests/data') c.app.repo.fs_path = repo_dir c.app.repo.status = 'ready' c.app.repo.name = 'test_branch.git' ThreadLocalORMSession.flush_all() h.set_context('test', 'src-git', neighborhood='Projects') c.app.repo.refresh() ThreadLocalORMSession.flush_all()
def setup_with_tools(self): setup_global_objects() h.set_context("test", "src-git", neighborhood="Projects") repo_dir = pkg_resources.resource_filename("forgeuserstats", "tests/data") c.app.repo.fs_path = repo_dir c.app.repo.name = "testgit.git" self.repo = c.app.repo self.repo.refresh() self.rev = M.repo.Commit.query.get(_id=self.repo.heads[0]["object_id"]) self.rev.repo = self.repo
def setup_with_tools(self): setup_global_objects() h.set_context('test', 'git-userstats-stats', neighborhood='Projects') repo_dir = pkg_resources.resource_filename( 'forgeuserstats', 'tests/data') c.app.repo.fs_path = repo_dir c.app.repo.name = 'testgit.git' self.repo = c.app.repo self.repo.refresh() self.rev = self.repo.commit('HEAD')
def test_include_file_permissions(self): h.set_context('test', 'src-git', neighborhood='Projects') role = M.ProjectRole.by_name('*anonymous')._id read_perm = M.ACE.allow(role, 'read') acl = c.app.config.acl if read_perm in acl: acl.remove(read_perm) c.user = M.User.anonymous() expected = "[[include: you don't have a read permission for repo src-git]]" assert_equal(macro.include_file('src-git'), expected)
def test_commit(self): assert self.rev.primary() is self.rev assert self.rev.index_id().startswith('allura/model/repo/Commit#') self.rev.author_url self.rev.committer_url assert self.rev.tree._id == self.rev.tree_id assert self.rev.summary == self.rev.message.splitlines()[0] assert self.rev.shorthand_id() == '[1e146e]' assert self.rev.symbolic_ids == ( ['master'], ['foo']), self.rev.symbolic_ids assert self.rev.url() == ( '/p/test/src-git/ci/' '1e146e67985dcd71c74de79613719bef7bddca4a/') all_cis = list(self.repo.log(self.rev._id, id_only=True)) assert len(all_cis) == 4 c.lcid_cache = {} self.rev.tree.ls() # print self.rev.tree.readme() assert_equal(self.rev.tree.readme(), ( 'README', 'This is readme\nAnother Line\n')) assert self.rev.tree.path() == '/' assert self.rev.tree.url() == ( '/p/test/src-git/ci/' '1e146e67985dcd71c74de79613719bef7bddca4a/' 'tree/') self.rev.tree.by_name['README'] assert self.rev.tree.is_blob('README') == True ThreadLocalORMSession.close_all() c.app = None converted = g.markdown.convert('[1e146e]') assert '1e146e' in converted, converted h.set_context('test', 'wiki', neighborhood='Projects') pg = WM.Page( title='Test Page', text='This is a commit reference: [1e146e]') ThreadLocalORMSession.flush_all() M.MonQTask.run_ready() for ci in pg.related_artifacts(): assert ci.shorthand_id() == '[1e146e]', ci.shorthand_id() assert ci.url() == ( '/p/test/src-git/ci/' '1e146e67985dcd71c74de79613719bef7bddca4a/') assert_equal(self.rev.authored_user, None) assert_equal(self.rev.committed_user, None) user = M.User.upsert('rick') email = user.claim_address('*****@*****.**') email.confirmed = True session(email).flush(email) rev = self.repo.commit(self.rev._id) # to update cached values of LazyProperty assert_equal(rev.authored_user, user) assert_equal(rev.committed_user, user) assert_equal( sorted(rev.webhook_info.keys()), sorted(['id', 'url', 'timestamp', 'message', 'author', 'committer', 'added', 'removed', 'renamed', 'modified', 'copied']))
def setup_with_tools(self): h.set_context('test', 'src-git', neighborhood='Projects') repo_dir = pkg_resources.resource_filename('forgegit', 'tests/data') c.app.repo.fs_path = repo_dir c.app.repo.name = 'testui2.git' c.app.repo.status = 'ready' self.repo = c.app.repo self.repo.refresh() self.rev = self.repo.commit('HEAD') ThreadLocalORMSession.flush_all() ThreadLocalORMSession.close_all()
def setup_with_tools(self): setup_global_objects() h.set_context('test', 'src-git', neighborhood='Projects') repo_dir = pkg_resources.resource_filename( 'forgegit', 'tests/data') c.app.repo.fs_path = repo_dir c.app.repo.name = 'testgit.git' self.repo = c.app.repo self.repo.refresh() ThreadLocalORMSession.flush_all() ThreadLocalORMSession.close_all()
def test_tarball_paths(self): rev = '19' h.set_context('test', 'svn-tags', neighborhood='Projects') tmpdir = tg.config['scm.repos.tarball.root'] tarball_path = os.path.join(tmpdir, 'svn/t/te/test/testsvn-trunk-tags-branches/') # a tag self.svn_tags.tarball(rev, '/tags/tag-1.0/') fn = tarball_path + 'test-svn-tags-r19-tags-tag-1.0.zip' assert os.path.isfile(fn), fn snapshot = ZipFile(fn, 'r') tag_content = sorted(['test-svn-tags-r19-tags-tag-1.0/', 'test-svn-tags-r19-tags-tag-1.0/svn-commit.tmp', 'test-svn-tags-r19-tags-tag-1.0/README']) assert_equal(sorted(snapshot.namelist()), tag_content) os.remove(fn) # a directory (of tags) self.svn_tags.tarball(rev, '/tags/') fn = tarball_path + 'test-svn-tags-r19-tags.zip' assert os.path.isfile(fn), fn snapshot = ZipFile(fn, 'r') tags_content = sorted(['test-svn-tags-r19-tags/', 'test-svn-tags-r19-tags/tag-1.0/', 'test-svn-tags-r19-tags/tag-1.0/svn-commit.tmp', 'test-svn-tags-r19-tags/tag-1.0/README']) assert_equal(sorted(snapshot.namelist()), tags_content) os.remove(fn) # no path, but there are trunk in the repo # expect snapshot of trunk self.svn_tags.tarball(rev) fn = tarball_path + 'test-svn-tags-r19-trunk.zip' assert os.path.isfile(fn), fn snapshot = ZipFile(fn, 'r') trunk_content = sorted(['test-svn-tags-r19-trunk/', 'test-svn-tags-r19-trunk/aaa.txt', 'test-svn-tags-r19-trunk/bbb.txt', 'test-svn-tags-r19-trunk/ccc.txt', 'test-svn-tags-r19-trunk/README']) assert_equal(sorted(snapshot.namelist()), trunk_content) os.remove(fn) # no path, and no trunk dir # expect snapshot of repo root h.set_context('test', 'src', neighborhood='Projects') fn = os.path.join(tmpdir, 'svn/t/te/test/testsvn/test-src-r1.zip') self.repo.tarball('1') assert os.path.isfile(fn), fn snapshot = ZipFile(fn, 'r') assert_equal(snapshot.namelist(), ['test-src-r1/', 'test-src-r1/README']) shutil.rmtree(os.path.join(tmpdir, 'svn/t/te/test/testsvn/'), ignore_errors=True) shutil.rmtree(tarball_path, ignore_errors=True)
def _make_app(self, mount_point, name): h.set_context("test", mount_point, neighborhood="Projects") repo_dir = pkg_resources.resource_filename("forgesvn", "tests/data/") c.app.repo.fs_path = repo_dir c.app.repo.status = "ready" c.app.repo.name = name c.app.repo.refresh() if os.path.isdir(c.app.repo.tarball_path): shutil.rmtree(c.app.repo.tarball_path.encode("utf-8")) ThreadLocalORMSession.flush_all() ThreadLocalORMSession.close_all()
def setUp(self): super(TestMergeRequest, self).setUp() c.project.install_app('svn', 'test2') h.set_context('test', 'test2', neighborhood='Projects') self.repo2 = M.Repository(name='test2', tool='svn') self.repo2._impl = mock.Mock(spec=M.RepositoryImplementation()) self.repo2._impl.log = lambda *a,**kw:(['foo'], []) self.repo2._impl._repo = self.repo2 self.repo2.init_as_clone('/p/test/', 'test1', '/p/test/test1/') ThreadLocalORMSession.flush_all() ThreadLocalORMSession.close_all()
def setUp(self): TestController.setUp(self) self.app.get('/discussion/') r = self.app.get('/admin/discussion/forums') r.forms[1]['add_forum.shortname'] = 'testforum' r.forms[1]['add_forum.name'] = 'Test Forum' r.forms[1].submit() r = self.app.get('/admin/discussion/forums') assert 'Test Forum' in r r.forms[1]['add_forum.shortname'] = 'test1' r.forms[1]['add_forum.name'] = 'Test Forum 1' r.forms[1].submit() r = self.app.get('/admin/discussion/forums') assert 'Test Forum 1' in r h.set_context('test', 'discussion', neighborhood='Projects') self.user_id = M.User.query.get(username='******')._id
def setUp(self): bootstrap.wipe_database() project_reg = plugin.ProjectRegistrationProvider.get() c.user = bootstrap.create_user('Test User') neighborhood = M.Neighborhood(name='Projects', url_prefix='/p/', features=dict(private_projects=False, max_projects=None, css='none', google_analytics=False)) project_reg.register_neighborhood_project(neighborhood, [c.user]) c.project = neighborhood.register_project('test', c.user) c.project.install_app('Tickets', 'bugs') ThreadLocalORMSession.flush_all() h.set_context('test', 'bugs', neighborhood='Projects') tg.request_local.context.request = Request.blank('/')
def setUp(self): super(_TestWithRepo, self).setUp() h.set_context('test', neighborhood='Projects') c.project.install_app('svn', 'test1') h.set_context('test', 'test1', neighborhood='Projects') self.repo = M.Repository(name='test1', tool='svn') self.repo._impl = mock.Mock(spec=M.RepositoryImplementation()) self.repo._impl.shorthand_for_commit = M.RepositoryImplementation.shorthand_for_commit self.repo._impl.url_for_commit = ( lambda *a, **kw: M.RepositoryImplementation.url_for_commit( self.repo._impl, *a, **kw)) self.repo._impl.log = lambda *a, **kw: (['foo'], []) self.repo._impl._repo = self.repo self.repo._impl.all_commit_ids = lambda *a, **kw: [] self.repo._impl.commit().symbolic_ids = None ThreadLocalORMSession.flush_all()
def test_forum_CRUD_hier(self): r = self.app.get('/admin/discussion/forums') r.forms[1]['add_forum.shortname'] = 'testforum' r.forms[1]['add_forum.name'] = 'Test Forum' r = r.forms[1].submit().follow() r = self.app.get('/admin/discussion/forums') assert 'testforum' in r h.set_context('test', 'discussion', neighborhood='Projects') frm = FM.Forum.query.get(shortname='testforum') r = self.app.get('/admin/discussion/forums') r.forms[1]['add_forum.shortname'] = 'childforum' r.forms[1]['add_forum.name'] = 'Child Forum' r.forms[1]['add_forum.parent'] = str(frm._id) r.forms[1].submit() r = self.app.get('/admin/discussion/forums') assert 'Child Forum' in r
def test_markdown(): 'Just a test to get coverage in our markdown extension' h.set_context('test', 'wiki', neighborhood='Projects') assert '<a href=' in g.markdown.convert('# Foo!\n[Home]') assert '<a href=' not in g.markdown.convert('# Foo!\n[Rooted]') assert '<a href=' in g.markdown.convert('This is http://sf.net') tgt = 'http://everything2.com/?node=nate+oostendorp' s = g.markdown.convert('This is %s' % tgt) assert_equal( s, '<div class="markdown_content"><p>This is <a href="%s" rel="nofollow">%s</a></p></div>' % (tgt, tgt)) assert '<a href=' in g.markdown.convert('This is http://sf.net') # assert '<a href=' in g.markdown_wiki.convert('This is a WikiPage') # assert '<a href=' not in g.markdown_wiki.convert('This is a WIKIPAGE') assert '<br' in g.markdown.convert('Multi\nLine'), g.markdown.convert( 'Multi\nLine') assert '<br' not in g.markdown.convert('Multi\n\nLine') r = g.markdown.convert('[[projects]]') assert '[[projects]]' in r, r with h.push_context( M.Neighborhood.query.get( name='Projects').neighborhood_project._id): r = g.markdown_wiki.convert('[[projects]]') assert '<div class="border card">' in r, r r = g.markdown.convert('[[include ref=Home id=foo]]') assert '<div id="foo">' in r, r assert 'href="../foo"' in g.markdown.convert('[My foo](foo)') assert 'href="..' not in g.markdown.convert('[My foo](./foo)') h.set_context('--init--', 'wiki', neighborhood='Projects') r = g.markdown_wiki.convert('[[neighborhood_feeds tool_name=Wiki]]') assert 'WikiPage Home modified by Test Admin' in r, r g.markdown.convert("<class 'foo'>") # should not raise an exception assert '<br>' not in g.markdown.convert('''# Header Some text in a regular paragraph :::python for i in range(10): print i ''') assert 'http://localhost/' in g.forge_markdown( email=True).convert('[Home]') assert 'class="codehilite"' in g.markdown.convert(''' ~~~~ def foo(): pass ~~~~''')
def refresh_repo(self, *repo_path): # post-commit hooks use this if not repo_path: return 'No repo specified' repo_path = '/' + '/'.join(repo_path) project, rest = h.find_project(repo_path) if project is None: return 'No project at %s' % repo_path if not rest: return '%s does not include a repo mount point' % repo_path h.set_context(project.shortname, rest[0], neighborhood=project.neighborhood) if c.app is None or not getattr(c.app, 'repo'): return 'Cannot find repo at %s' % repo_path allura.tasks.repo_tasks.refresh.post() return '%r refresh queued.\n' % c.app.repo
def test_myprojects_macro(): h.set_context('u/%s' % (c.user.username), 'wiki', neighborhood='Users') r = g.markdown_wiki.convert('[[my_projects]]') for p in c.user.my_projects(): if p.deleted or p.is_nbhd_project: continue proj_title = '<h2><a href="%s">%s</a></h2>' % (p.url(), p.name) assert proj_title in r h.set_context('u/test-user-1', 'wiki', neighborhood='Users') user = M.User.query.get(username='******') r = g.markdown_wiki.convert('[[my_projects]]') for p in user.my_projects(): if p.deleted or p.is_nbhd_project: continue proj_title = '<h2><a href="%s">%s</a></h2>' % (p.url(), p.name) assert proj_title in r
def test_notification_email(self): setup_global_objects() h.set_context('test', 'src', neighborhood='Projects') repo_dir = pkg_resources.resource_filename('forgesvn', 'tests/data/') self.repo = SM.Repository(name='testsvn', fs_path=repo_dir, url_path='/test/', tool='svn', status='creating') self.repo.refresh() ThreadLocalORMSession.flush_all() send_notifications(self.repo, [self.repo.rev_to_commit_id(1)]) ThreadLocalORMSession.flush_all() n = M.Notification.query.find( dict(subject='[test:src] [r1] - rick446: Create readme')).first() assert n assert_equal(n.text, 'Create readme http://localhost/p/test/src/1/')
def setup_with_tools(self): setup_global_objects() h.set_context('test', 'src-git', neighborhood='Projects') repo_dir = pkg_resources.resource_filename('forgegit', 'tests/data') c.app.repo.fs_path = repo_dir c.app.repo.name = 'testgit.git' self.repo = c.app.repo #self.repo = GM.Repository( # name='testgit.git', # fs_path=repo_dir, # url_path = '/test/', # tool = 'git', # status = 'creating') self.repo.refresh() self.rev = self.repo.commit('master') ThreadLocalORMSession.flush_all() ThreadLocalORMSession.close_all()
def setup_with_tools(self): setup_global_objects() h.set_context('test', 'src', neighborhood='Projects') repo_dir = pkg_resources.resource_filename('forgesvn', 'tests/data/') self.repo = SM.Repository(name='testsvn', fs_path=repo_dir, url_path='/test/', tool='svn', status='creating') self.repo.refresh() self.svn_tags = SM.Repository(name='testsvn-trunk-tags-branches', fs_path=repo_dir, url_path='/test/', tool='svn', status='creating') self.svn_tags.refresh() ThreadLocalORMSession.flush_all() ThreadLocalORMSession.close_all()
def __init__(self, options): self.options = options self.nbhd = M.Neighborhood.query.get(name=options.nbhd) if not self.nbhd: raise ValueError("Can't find neighborhood with name %s" % options.nbhd) self.project = M.Project.query.get(shortname=options.project, neighborhood_id=self.nbhd._id) if not self.project: raise ValueError("Can't find project with shortname %s " "and neighborhood_id %s" % (options.project, self.nbhd._id)) self.wiki = self.project.app_instance('wiki') if not self.wiki: raise ValueError("Can't find wiki app in given project") h.set_context(self.project.shortname, 'wiki', neighborhood=self.nbhd)
def test_forum_CRUD(self): r = self.app.get('/admin/discussion/forums') r.forms[1]['add_forum.shortname'] = 'testforum' r.forms[1]['add_forum.name'] = 'Test Forum' r = r.forms[1].submit().follow() assert 'Test Forum' in r h.set_context('test', 'Forum', neighborhood='Projects') frm = FM.Forum.query.get(shortname='testforum') r = self.app.post('/admin/discussion/update_forums', params={'forum-0.delete':'', 'forum-0.id':str(frm._id), 'forum-0.name':'New Test Forum', 'forum-0.shortname':'NewTestForum', 'forum-0.description':'My desc', 'forum-0.monitoring_email':''}) r = self.app.get('/admin/discussion/forums') assert 'New Test Forum' in r assert 'My desc' in r
def command(self): self.basic_setup() h.set_context(self.args[1], neighborhood=self.args[2]) extra_status = [] for s in self.args[3:]: s = s.lower() if s == 'production': print('All projects always have access to prodcution tools,' ' so removing from list.') continue if s not in ('alpha', 'beta'): print('Unknown tool status %s' % s) sys.exit(1) extra_status.append(s) print('Setting project "%s" tool access to production + %r' % (self.args[1], extra_status)) c.project._extra_tool_status = extra_status session(c.project).flush()
def setup_with_tools(self): setup_global_objects() repo_dir = pkg_resources.resource_filename('forgesvn', 'tests/data/') with h.push_context('test', 'src', neighborhood='Projects'): c.app.repo.name = 'testsvn' c.app.repo.fs_path = repo_dir self.repo = c.app.repo self.repo.refresh() ThreadLocalORMSession.flush_all() ThreadLocalORMSession.close_all() with h.push_context('test', 'svn-tags', neighborhood='Projects'): c.app.repo.name = 'testsvn-trunk-tags-branches' c.app.repo.fs_path = repo_dir self.svn_tags = c.app.repo self.svn_tags.refresh() ThreadLocalORMSession.flush_all() ThreadLocalORMSession.close_all() h.set_context('test', 'src', neighborhood='Projects')
def test_commit(self): assert self.rev.primary() is self.rev assert self.rev.index_id().startswith('allura/model/repo/Commit#') self.rev.author_url self.rev.committer_url assert self.rev.tree._id == self.rev.tree_id assert self.rev.summary == self.rev.message.splitlines()[0] assert self.rev.shorthand_id() == '[1e146e]' assert self.rev.symbolic_ids == (['master', 'zz'], []) assert self.rev.url() == ( '/p/test/src-git/ci/' '1e146e67985dcd71c74de79613719bef7bddca4a/') all_cis = self.repo.log(self.rev._id, 0, 1000) assert len(all_cis) == 4 assert_equal(self.repo.log(self.rev._id, 1,1000), all_cis[1:]) assert_equal(self.repo.log(self.rev._id, 0,3), all_cis[:3]) assert_equal(self.repo.log(self.rev._id, 1,2), all_cis[1:3]) for ci in all_cis: ci.context() self.rev.tree.ls() # print self.rev.tree.readme() assert_equal(self.rev.tree.readme(), ( 'README', 'This is readme\nAnother Line\n')) assert self.rev.tree.path() == '/' assert self.rev.tree.url() == ( '/p/test/src-git/ci/' '1e146e67985dcd71c74de79613719bef7bddca4a/' 'tree/') self.rev.tree.by_name['README'] assert self.rev.tree.is_blob('README') == True ThreadLocalORMSession.close_all() c.app = None converted = g.markdown.convert('[1e146e]') assert '1e146e' in converted, converted h.set_context('test', 'wiki', neighborhood='Projects') pg = WM.Page( title='Test Page', text='This is a commit reference: [1e146e]') ThreadLocalORMSession.flush_all() M.MonQTask.run_ready() for ci in pg.related_artifacts(): assert ci.shorthand_id() == '[1e146e]', ci.shorthand_id() assert ci.url() == ( '/p/test/src-git/ci/' '1e146e67985dcd71c74de79613719bef7bddca4a/')
def test_new_image_attachment_content(self): self.app.post('/wiki/TEST/update', params={ 'title': 'TEST', 'text': 'sometext', 'labels': '', 'labels_old': '', 'viewable_by-0.id': 'all' }) file_name = 'neo-icon-set-454545-256x350.png' file_path = os.path.join(allura.__path__[0], 'nf', 'allura', 'images', file_name) file_data = file(file_path).read() upload = ('file_info', file_name, file_data) self.app.post('/wiki/TEST/attach', upload_files=[upload]) h.set_context('test', 'wiki', neighborhood='Projects') page = model.Page.query.find(dict(title='TEST')).first() filename = page.attachments.first().filename uploaded = Image.open(file_path) r = self.app.get('/wiki/TEST/attachment/' + filename) downloaded = Image.open(StringIO.StringIO(r.body)) assert uploaded.size == downloaded.size r = self.app.get('/wiki/TEST/attachment/' + filename + '/thumb') thumbnail = Image.open(StringIO.StringIO(r.body)) assert thumbnail.size == (255, 255) # Make sure thumbnail is present r = self.app.get('/wiki/TEST/') img_srcs = [i['src'] for i in r.html.findAll('img')] assert ('/p/test/wiki/TEST/attachment/' + filename + '/thumb') in img_srcs, img_srcs # Update the page to embed the image, make sure the thumbnail is absent self.app.post('/wiki/TEST/update', params=dict(title='TEST', text='sometext\n[[img src=%s alt=]]' % file_name)) r = self.app.get('/wiki/TEST/') img_srcs = [i['src'] for i in r.html.findAll('img')] assert ('/p/test/wiki/TEST/attachment/' + filename) not in img_srcs, img_srcs assert ('./attachment/' + file_name) in img_srcs, img_srcs
def test_related_links(self): response = self.app.get('/wiki/TEST/').follow() assert 'Edit TEST' in response assert 'Related' not in response self.app.post('/wiki/TEST/update', params={ 'title': 'TEST', 'text': 'sometext', 'labels': '', 'labels_old': '', 'viewable_by-0.id': 'all' }) self.app.post('/wiki/aaa/update', params={ 'title': 'aaa', 'text': '', 'labels': '', 'labels_old': '', 'viewable_by-0.id': 'all' }) self.app.post('/wiki/bbb/update', params={ 'title': 'bbb', 'text': '', 'labels': '', 'labels_old': '', 'viewable_by-0.id': 'all' }) h.set_context('test', 'wiki', neighborhood='Projects') a = model.Page.query.find(dict(title='aaa')).first() a.text = '\n[TEST]\n' b = model.Page.query.find(dict(title='TEST')).first() b.text = '\n[bbb]\n' ThreadLocalORMSession.flush_all() M.MonQTask.run_ready() ThreadLocalORMSession.flush_all() ThreadLocalORMSession.close_all() response = self.app.get('/wiki/TEST/') assert 'Related' in response assert 'aaa' in response assert 'bbb' in response
def test_paged_diffs_with_detect_copies(self): # setup h.set_context('test', 'src-weird', neighborhood='Projects') repo_dir = pkg_resources.resource_filename('forgegit', 'tests/data') repo = GM.Repository(name='weird-chars.git', fs_path=repo_dir, url_path='/src-weird/', tool='git', status='creating') repo.refresh() ThreadLocalORMSession.flush_all() ThreadLocalORMSession.close_all() diffs = repo.paged_diffs( '346c52c1dddc729e2c2711f809336401f0ff925e') # Test copy expected = { 'added': [], 'removed': [], 'copied': [{ 'new': 'README.copy', 'old': 'README', 'ratio': 1.0 }], 'renamed': [], 'changed': ['README'], 'total': 2, } assert_equals(diffs, expected) diffs = repo.paged_diffs( '3cb2bbcd7997f89060a14fe8b1a363f01883087f') # Test rename expected = { 'added': [], 'removed': [], 'copied': [], 'renamed': [{ 'new': 'README', 'old': 'README-copy.md', 'ratio': 1.0 }], 'changed': [], 'total': 1, } assert_equals(diffs, expected)
def test_tarball_path(self): h.set_context('test', 'svn-tags', neighborhood='Projects') shutil.rmtree(c.app.repo.tarball_path, ignore_errors=True) r = self.app.get('/p/test/svn-tags/19/tree/') form = r.html.find('form', 'tarball') assert_equal(form.button.text, ' Download Snapshot') assert_equal(form.get('action'), '/p/test/svn-tags/19/tarball') r = self.app.get('/p/test/svn-tags/19/tree/tags/tag-1.0/') form = r.html.find('form', 'tarball') assert_equal(form.button.text, ' Download Snapshot') assert_equal(form.get('action'), '/p/test/svn-tags/19/tarball') assert_equal( form.find('input', attrs=dict(name='path')).get('value'), '/tags/tag-1.0') r = self.app.get( '/p/test/svn-tags/19/tarball_status?path=/tags/tag-1.0') assert_equal(r.json['status'], None) r = self.app.post('/p/test/svn-tags/19/tarball', dict(path='/tags/tag-1.0')).follow() assert 'Generating snapshot...' in r M.MonQTask.run_ready() r = self.app.get( '/p/test/svn-tags/19/tarball_status?path=/tags/tag-1.0') assert_equal(r.json['status'], 'complete') r = self.app.get('/p/test/svn-tags/19/tarball_status?path=/trunk') assert_equal(r.json['status'], None) r = self.app.post('/p/test/svn-tags/19/tarball', dict(path='/trunk/')).follow() assert 'Generating snapshot...' in r M.MonQTask.run_ready() r = self.app.get('/p/test/svn-tags/19/tarball_status?path=/trunk') assert_equal(r.json['status'], 'complete') r = self.app.get( '/p/test/svn-tags/19/tarball_status?path=/branches/aaa/') assert_equal(r.json['status'], None) # this is is the same as trunk snapshot, so it's ready already r = self.app.get('/p/test/svn-tags/19/tarball_status') assert_equal(r.json['status'], 'complete')
def test_forum_icon(self): file_name = 'neo-icon-set-454545-256x350.png' file_path = os.path.join(allura.__path__[0],'nf','allura','images',file_name) file_data = file(file_path).read() upload = ('add_forum.icon', file_name, file_data) h.set_context('test', 'discussion', neighborhood='Projects') r = self.app.get('/admin/discussion/forums') app_id = r.forms[1]['add_forum.app_id'].value r = self.app.post('/admin/discussion/add_forum', params={'add_forum.shortname':'testforum', 'add_forum.app_id':app_id, 'add_forum.name':'Test Forum', 'add_forum.description':'', 'add_forum.parent':'', }, upload_files=[upload]), r = self.app.get('/discussion/testforum/icon') image = Image.open(StringIO(r.body)) assert image.size == (48,48)
def test_notification_email(self): setup_global_objects() h.set_context('test', 'src', neighborhood='Projects') repo_dir = pkg_resources.resource_filename('forgesvn', 'tests/data/') self.repo = SM.Repository(name='testsvn', fs_path=repo_dir, url_path='/test/', tool='svn', status='creating') self.repo.refresh() ThreadLocalORMSession.flush_all() send_notifications(self.repo, [self.repo.rev_to_commit_id(1)]) ThreadLocalORMSession.flush_all() n = M.Notification.query.find({ u'subject': u'[test:src] New commit by rick446' }).first() assert n assert_in(u'By rick446', n.text) assert_in(u'Create readme', n.text)
def test_project(): assert type(c.project.sidebar_menu()) == list assert c.project.script_name in c.project.url() old_proj = c.project h.set_context('test/sub1', neighborhood='Projects') assert type(c.project.sidebar_menu()) == list assert type(c.project.sitemap()) == list assert c.project.sitemap()[0].label == 'Admin' assert old_proj in list(c.project.parent_iter()) h.set_context('test', 'wiki', neighborhood='Projects') adobe_nbhd = M.Neighborhood.query.get(name='Adobe') p = M.Project.query.get(shortname='adobe-1', neighborhood_id=adobe_nbhd._id) # assert 'http' in p.url() # We moved adobe into /adobe/, not http://adobe.... assert p.script_name in p.url() assert c.project.shortname == 'test' assert '<p>' in c.project.description_html c.project.uninstall_app('hello-test-mount-point') ThreadLocalORMSession.flush_all() c.project.install_app('Wiki', 'hello-test-mount-point') c.project.support_page = 'hello-test-mount-point' ThreadLocalORMSession.flush_all() with td.raises(ToolError): # already installed c.project.install_app('Wiki', 'hello-test-mount-point') ThreadLocalORMSession.flush_all() c.project.uninstall_app('hello-test-mount-point') ThreadLocalORMSession.flush_all() with td.raises(ToolError): # mount point reserved c.project.install_app('Wiki', 'feed') # Make sure the project support page is reset if the tool it was pointing # to is uninstalled. assert c.project.support_page == '' app_config = c.project.app_config('hello') app_inst = c.project.app_instance(app_config) app_inst = c.project.app_instance('hello') app_inst = c.project.app_instance('hello2123') c.project.breadcrumbs() c.app.config.breadcrumbs()
def test_new_image_attachment_content(self): h.set_context('test', 'bugs', neighborhood='Projects') file_name = 'neo-icon-set-454545-256x350.png' file_path = os.path.join(allura.__path__[0],'nf','allura','images',file_name) file_data = file(file_path).read() upload = ('attachment', file_name, file_data) self.new_ticket(summary='test new attachment') ticket_editor = self.app.post('/bugs/1/update_ticket',{ 'summary':'zzz' }, upload_files=[upload]).follow() ticket = tm.Ticket.query.find({'ticket_num':1}).first() filename = ticket.attachments.first().filename uploaded = Image.open(file_path) r = self.app.get('/bugs/1/attachment/'+filename) downloaded = Image.open(StringIO.StringIO(r.body)) assert uploaded.size == downloaded.size r = self.app.get('/bugs/1/attachment/'+filename+'/thumb') thumbnail = Image.open(StringIO.StringIO(r.body)) assert thumbnail.size == (100,100)
def setUp(self): TestController.setUp(self) self.app.get('/discussion/') r = self.app.get('/admin/discussion/forums') form = r.forms[3] form['add_forum.shortname'] = 'testforum' form['add_forum.name'] = 'Test Forum' form.submit() r = self.app.get('/admin/discussion/forums') frm = FM.Forum.query.get(shortname='testforum') assert 'testforum' in r h.set_context('test', 'discussion', neighborhood='Projects') frm = FM.Forum.query.get(shortname='testforum') r = self.app.get('/admin/discussion/forums') form = r.forms[3] form['add_forum.shortname'] = 'childforum' form['add_forum.name'] = 'Child Forum' form['add_forum.parent'] = str(frm._id) form.submit() r = self.app.get('/admin/discussion/forums') assert 'childforum' in r
def test_tarball_aware_of_trunk(self): rev = '19' trunk_content = sorted([ 'test-svn-tags-19-trunk/', 'test-svn-tags-19-trunk/aaa.txt', 'test-svn-tags-19-trunk/bbb.txt', 'test-svn-tags-19-trunk/ccc.txt', 'test-svn-tags-19-trunk/README' ]) h.set_context('test', 'svn-tags', neighborhood='Projects') tmpdir = tg.config['scm.repos.tarball.root'] tarball_path = os.path.join( tmpdir, 'svn/t/te/test/testsvn-trunk-tags-branches/') fn = tarball_path + 'test-svn-tags-19-trunk.zip' self.svn_tags.tarball(rev, '/trunk/') assert os.path.isfile(fn), fn snapshot = ZipFile(fn, 'r') assert_equal(sorted(snapshot.namelist()), trunk_content) os.remove(fn) self.svn_tags.tarball(rev, '/trunk/some/path/') assert os.path.isfile(fn), fn snapshot = ZipFile(fn, 'r') assert_equal(sorted(snapshot.namelist()), trunk_content) os.remove(fn) # no path, but there are trunk in the repo # expect snapshot of trunk self.svn_tags.tarball(rev) assert os.path.isfile(fn), fn snapshot = ZipFile(fn, 'r') assert_equal(sorted(snapshot.namelist()), trunk_content) os.remove(fn) # no path, and no trunk dir # expect snapshot of repo root h.set_context('test', 'src', neighborhood='Projects') fn = os.path.join(tmpdir, 'svn/t/te/test/testsvn/test-src-1.zip') self.repo.tarball('1') assert os.path.isfile(fn), fn snapshot = ZipFile(fn, 'r') assert_equal(snapshot.namelist(), ['test-src-1/', 'test-src-1/README']) shutil.rmtree(os.path.join(tmpdir, 'svn/t/te/test/testsvn/'), ignore_errors=True) shutil.rmtree(tarball_path, ignore_errors=True)
def test_context_setters(): h.set_context('test', 'wiki', neighborhood='Projects') 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, neighborhood='Projects') assert c.project is not None assert c.app is not None h.set_context('test', app_config_id=str(cfg_id), neighborhood='Projects') assert c.project is not None assert c.app is not None c.project = c.app = None with h.push_context('test', 'wiki', neighborhood='Projects'): 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, neighborhood='Projects'): 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), neighborhood='Projects'): 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), neighborhood='Projects'): assert c.project is not None assert c.app is not None assert not hasattr(c, 'project') assert not hasattr(c, 'app')
def import_news(project, pid, frs_mapping, sf_project_shortname, nbhd): from forgeblog import model as BM posts = os.listdir(os.path.join(options.output_dir, pid, 'news')) if len(posts): news_app = project.app_instance('news') if not news_app: news_app = project.install_app('blog', 'news', mount_label='News') h.set_context(project.shortname, 'news', neighborhood=nbhd) # make all the blog posts for post in posts: if '.json' == post[-5:]: post_data = loadjson(pid, 'news', post) create_date = datetime.strptime(post_data.createdOn, '%Y-%m-%d %H:%M:%S') p = BM.BlogPost.query.get(title=post_data.title, timestamp=create_date, app_config_id=news_app.config._id) if not p: p = BM.BlogPost(title=post_data.title, timestamp=create_date, app_config_id=news_app.config._id) p.text = convert_post_content(frs_mapping, sf_project_shortname, post_data.body, nbhd) p.mod_date = create_date p.state = 'published' if not p.slug: p.make_slug() if not p.history().first(): p.commit() ThreadLocalORMSession.flush_all() M.Thread(discussion_id=p.app_config.discussion_id, ref_id=p.index_id(), subject='%s discussion' % p.title) user = get_user(post_data.createdByUsername) p.history().first().author = dict( id=user._id, username=user.username, display_name=user.get_pref('display_name')) ThreadLocalORMSession.flush_all()
def __init__(self, options): self.options = options self.nbhd = M.Neighborhood.query.get(name=options.nbhd) if not self.nbhd: allura_base.log.error("Can't find neighborhood with name %s" % options.nbhd) exit(2) self.project = M.Project.query.get(shortname=options.project, neighborhood_id=self.nbhd._id) if not self.project: allura_base.log.error("Can't find project with shortname %s " "and neighborhood_id %s" % (options.project, self.nbhd._id)) exit(2) self.wiki = self.project.app_instance('wiki') if not self.wiki: allura_base.log.error("Can't find wiki app in given project") exit(2) h.set_context(self.project.shortname, 'wiki', neighborhood=self.nbhd) self.project.notifications_disabled = True
def test_tarball_aware_of_branches(self): rev = '19' branch_content = sorted([ 'test-svn-tags-19-branches-aaa/', 'test-svn-tags-19-branches-aaa/aaa.txt', 'test-svn-tags-19-branches-aaa/svn-commit.tmp', 'test-svn-tags-19-branches-aaa/README' ]) h.set_context('test', 'svn-tags', neighborhood='Projects') tmpdir = tg.config['scm.repos.tarball.root'] tarball_path = os.path.join( tmpdir, 'svn/t/te/test/testsvn-trunk-tags-branches/') fn = tarball_path + 'test-svn-tags-19-branches-aaa.zip' self.svn_tags.tarball(rev, '/branches/aaa/') assert os.path.isfile(fn), fn snapshot = ZipFile(fn, 'r') assert_equal(sorted(snapshot.namelist()), branch_content) os.remove(fn) self.svn_tags.tarball(rev, '/branches/aaa/some/path/') assert os.path.isfile(fn), fn snapshot = ZipFile(fn, 'r') assert_equal(sorted(snapshot.namelist()), branch_content) os.remove(fn) # if inside of branches, but no branch is specified # expect snapshot of trunk fn = tarball_path + 'test-svn-tags-19-trunk.zip' self.svn_tags.tarball(rev, '/branches/') assert os.path.isfile(fn), fn snapshot = ZipFile(fn, 'r') assert_equal( sorted(snapshot.namelist()), sorted([ 'test-svn-tags-19-trunk/', 'test-svn-tags-19-trunk/aaa.txt', 'test-svn-tags-19-trunk/bbb.txt', 'test-svn-tags-19-trunk/ccc.txt', 'test-svn-tags-19-trunk/README' ])) shutil.rmtree(tarball_path, ignore_errors=True)
def setup_with_tools(self): h.set_context('test', 'src', neighborhood='Projects') repo_dir = pkg_resources.resource_filename('forgesvn', 'tests/data/') c.app.repo.fs_path = repo_dir c.app.repo.status = 'ready' c.app.repo.name = 'testsvn' ThreadLocalORMSession.flush_all() ThreadLocalORMSession.close_all() h.set_context('test', 'src', neighborhood='Projects') c.app.repo.refresh() ThreadLocalORMSession.flush_all() ThreadLocalORMSession.close_all() h.set_context('test', 'src', neighborhood='Projects')