You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2014/01/10 19:19:33 UTC
[09/32] PEP8 cleanup
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeImporters/forgeimporters/tests/google/test_extractor.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/google/test_extractor.py b/ForgeImporters/forgeimporters/tests/google/test_extractor.py
index 0752755..3635ac5 100644
--- a/ForgeImporters/forgeimporters/tests/google/test_extractor.py
+++ b/ForgeImporters/forgeimporters/tests/google/test_extractor.py
@@ -30,6 +30,7 @@ from forgeimporters import base
class TestGoogleCodeProjectExtractor(TestCase):
+
def setUp(self):
self._p_urlopen = mock.patch.object(base.ProjectExtractor, 'urlopen')
# self._p_soup = mock.patch.object(google, 'BeautifulSoup')
@@ -50,24 +51,30 @@ class TestGoogleCodeProjectExtractor(TestCase):
raise
def test_init(self):
- extractor = google.GoogleCodeProjectExtractor('my-project', 'project_info')
+ extractor = google.GoogleCodeProjectExtractor(
+ 'my-project', 'project_info')
- self.urlopen.assert_called_once_with('http://code.google.com/p/my-project/')
+ self.urlopen.assert_called_once_with(
+ 'http://code.google.com/p/my-project/')
self.soup.assert_called_once_with(self.urlopen.return_value)
self.assertEqual(extractor.page, self.soup.return_value)
def test_get_page(self):
- extractor = google.GoogleCodeProjectExtractor('my-project', 'project_info')
+ extractor = google.GoogleCodeProjectExtractor(
+ 'my-project', 'project_info')
self.assertEqual(1, self.urlopen.call_count)
page = extractor.get_page('project_info')
self.assertEqual(1, self.urlopen.call_count)
- self.assertEqual(page, extractor._page_cache['http://code.google.com/p/my-project/'])
+ self.assertEqual(
+ page, extractor._page_cache['http://code.google.com/p/my-project/'])
page = extractor.get_page('project_info')
self.assertEqual(1, self.urlopen.call_count)
- self.assertEqual(page, extractor._page_cache['http://code.google.com/p/my-project/'])
+ self.assertEqual(
+ page, extractor._page_cache['http://code.google.com/p/my-project/'])
page = extractor.get_page('source_browse')
self.assertEqual(2, self.urlopen.call_count)
- self.assertEqual(page, extractor._page_cache['http://code.google.com/p/my-project/source/browse/'])
+ self.assertEqual(
+ page, extractor._page_cache['http://code.google.com/p/my-project/source/browse/'])
parser = mock.Mock(return_value='parsed')
page = extractor.get_page('url', parser=parser)
self.assertEqual(page, 'parsed')
@@ -76,10 +83,11 @@ class TestGoogleCodeProjectExtractor(TestCase):
def test_get_page_url(self):
extractor = google.GoogleCodeProjectExtractor('my-project')
self.assertEqual(extractor.get_page_url('project_info'),
- 'http://code.google.com/p/my-project/')
+ 'http://code.google.com/p/my-project/')
def test_get_short_description(self):
- extractor = google.GoogleCodeProjectExtractor('my-project', 'project_info')
+ extractor = google.GoogleCodeProjectExtractor(
+ 'my-project', 'project_info')
extractor.page.find.return_value.text = 'My Super Project'
extractor.get_short_description(self.project)
@@ -92,22 +100,25 @@ class TestGoogleCodeProjectExtractor(TestCase):
def test_get_icon(self, M, File):
File.return_value.type = 'image/png'
File.return_value.file = 'data'
- extractor = google.GoogleCodeProjectExtractor('my-project', 'project_info')
+ extractor = google.GoogleCodeProjectExtractor(
+ 'my-project', 'project_info')
extractor.page.find.return_value.get.return_value = 'http://example.com/foo/bar/my-logo.png'
extractor.get_icon(self.project)
extractor.page.find.assert_called_once_with(itemprop='image')
- File.assert_called_once_with('http://example.com/foo/bar/my-logo.png', 'my-logo.png')
+ File.assert_called_once_with(
+ 'http://example.com/foo/bar/my-logo.png', 'my-logo.png')
M.ProjectFile.save_image.assert_called_once_with(
'my-logo.png', 'data', 'image/png', square=True,
- thumbnail_size=(48,48), thumbnail_meta={
+ thumbnail_size=(48, 48), thumbnail_meta={
'project_id': self.project._id, 'category': 'icon'})
@mock.patch.object(google, 'M')
def test_get_license(self, M):
self.project.trove_license = []
- extractor = google.GoogleCodeProjectExtractor('my-project', 'project_info')
+ extractor = google.GoogleCodeProjectExtractor(
+ 'my-project', 'project_info')
extractor.page.find.return_value.findNext.return_value.find.return_value.text = ' New BSD License '
trove = M.TroveCategory.query.get.return_value
@@ -115,27 +126,31 @@ class TestGoogleCodeProjectExtractor(TestCase):
extractor.page.find.assert_called_once_with(text='Code license')
extractor.page.find.return_value.findNext.assert_called_once_with()
- extractor.page.find.return_value.findNext.return_value.find.assert_called_once_with('a')
+ extractor.page.find.return_value.findNext.return_value.find.assert_called_once_with(
+ 'a')
self.assertEqual(self.project.trove_license, [trove._id])
- M.TroveCategory.query.get.assert_called_once_with(fullname='BSD License')
+ M.TroveCategory.query.get.assert_called_once_with(
+ fullname='BSD License')
M.TroveCategory.query.get.reset_mock()
extractor.page.find.return_value.findNext.return_value.find.return_value.text = 'non-existant license'
extractor.get_license(self.project)
- M.TroveCategory.query.get.assert_called_once_with(fullname='Other/Proprietary License')
+ M.TroveCategory.query.get.assert_called_once_with(
+ fullname='Other/Proprietary License')
def _make_extractor(self, html):
from BeautifulSoup import BeautifulSoup
with mock.patch.object(base.ProjectExtractor, 'urlopen'):
- extractor = google.GoogleCodeProjectExtractor('allura-google-importer')
+ extractor = google.GoogleCodeProjectExtractor(
+ 'allura-google-importer')
extractor.page = BeautifulSoup(html)
extractor.get_page = lambda pagename: extractor.page
- extractor.url="http://test/source/browse"
+ extractor.url = "http://test/source/browse"
return extractor
def test_get_repo_type_happy_path(self):
extractor = self._make_extractor(
- '<span id="crumb_root">\nsvn/ </span>')
+ '<span id="crumb_root">\nsvn/ </span>')
self.assertEqual('svn', extractor.get_repo_type())
def test_get_repo_type_no_crumb_root(self):
@@ -143,18 +158,19 @@ class TestGoogleCodeProjectExtractor(TestCase):
with self.assertRaises(Exception) as cm:
extractor.get_repo_type()
self.assertEqual(str(cm.exception),
- "Couldn't detect repo type: no #crumb_root in "
- "http://test/source/browse")
+ "Couldn't detect repo type: no #crumb_root in "
+ "http://test/source/browse")
def test_get_repo_type_unknown_repo_type(self):
extractor = self._make_extractor(
- '<span id="crumb_root">cvs</span>')
+ '<span id="crumb_root">cvs</span>')
with self.assertRaises(Exception) as cm:
extractor.get_repo_type()
self.assertEqual(str(cm.exception), "Unknown repo type: cvs")
def test_empty_issue(self):
- empty_issue = open(pkg_resources.resource_filename('forgeimporters', 'tests/data/google/empty-issue.html')).read()
+ empty_issue = open(pkg_resources.resource_filename(
+ 'forgeimporters', 'tests/data/google/empty-issue.html')).read()
gpe = self._make_extractor(empty_issue)
self.assertIsNone(gpe.get_issue_owner())
self.assertEqual(gpe.get_issue_status(), '')
@@ -164,74 +180,82 @@ class TestGoogleCodeProjectExtractor(TestCase):
@without_module('html2text')
def test_get_issue_basic_fields(self):
- test_issue = open(pkg_resources.resource_filename('forgeimporters', 'tests/data/google/test-issue.html')).read()
+ test_issue = open(pkg_resources.resource_filename(
+ 'forgeimporters', 'tests/data/google/test-issue.html')).read()
gpe = self._make_extractor(test_issue)
self.assertEqual(gpe.get_issue_creator().name, 'john...@gmail.com')
- self.assertEqual(gpe.get_issue_creator().url, 'http://code.google.com/u/101557263855536553789/')
+ self.assertEqual(gpe.get_issue_creator().url,
+ 'http://code.google.com/u/101557263855536553789/')
self.assertEqual(gpe.get_issue_owner().name, 'john...@gmail.com')
- self.assertEqual(gpe.get_issue_owner().url, 'http://code.google.com/u/101557263855536553789/')
+ self.assertEqual(gpe.get_issue_owner().url,
+ 'http://code.google.com/u/101557263855536553789/')
self.assertEqual(gpe.get_issue_status(), 'Started')
self._p_soup.stop()
self.assertEqual(gpe.get_issue_summary(), 'Test "Issue"')
assert_equal(gpe.get_issue_description(),
- 'Test \\*Issue\\* for testing\n'
- '\n'
- ' 1\\. Test List\n'
- ' 2\\. Item\n'
- '\n'
- '\\*\\*Testing\\*\\*\n'
- '\n'
- ' \\* Test list 2\n'
- ' \\* Item\n'
- '\n'
- '\\# Test Section\n'
- '\n'
- ' p = source\\.test\\_issue\\.post\\(\\)\n'
- ' p\\.count = p\\.count \\*5 \\#\\* 6\n'
- ' if p\\.count > 5:\n'
- ' print "Not < 5 & \\!= 5"\n'
- '\n'
- 'References: [issue 1](#1), [r2]\n'
- '\n'
- 'That\'s all'
- )
- self.assertEqual(gpe.get_issue_created_date(), 'Thu Aug 8 15:33:52 2013')
+ 'Test \\*Issue\\* for testing\n'
+ '\n'
+ ' 1\\. Test List\n'
+ ' 2\\. Item\n'
+ '\n'
+ '\\*\\*Testing\\*\\*\n'
+ '\n'
+ ' \\* Test list 2\n'
+ ' \\* Item\n'
+ '\n'
+ '\\# Test Section\n'
+ '\n'
+ ' p = source\\.test\\_issue\\.post\\(\\)\n'
+ ' p\\.count = p\\.count \\*5 \\#\\* 6\n'
+ ' if p\\.count > 5:\n'
+ ' print "Not < 5 & \\!= 5"\n'
+ '\n'
+ 'References: [issue 1](#1), [r2]\n'
+ '\n'
+ 'That\'s all'
+ )
+ self.assertEqual(gpe.get_issue_created_date(),
+ 'Thu Aug 8 15:33:52 2013')
self.assertEqual(gpe.get_issue_stars(), 1)
@skipif(module_not_available('html2text'))
def test_get_issue_basic_fields_html2text(self):
- test_issue = open(pkg_resources.resource_filename('forgeimporters', 'tests/data/google/test-issue.html')).read()
+ test_issue = open(pkg_resources.resource_filename(
+ 'forgeimporters', 'tests/data/google/test-issue.html')).read()
gpe = self._make_extractor(test_issue)
self.assertEqual(gpe.get_issue_creator().name, 'john...@gmail.com')
- self.assertEqual(gpe.get_issue_creator().url, 'http://code.google.com/u/101557263855536553789/')
+ self.assertEqual(gpe.get_issue_creator().url,
+ 'http://code.google.com/u/101557263855536553789/')
self.assertEqual(gpe.get_issue_owner().name, 'john...@gmail.com')
- self.assertEqual(gpe.get_issue_owner().url, 'http://code.google.com/u/101557263855536553789/')
+ self.assertEqual(gpe.get_issue_owner().url,
+ 'http://code.google.com/u/101557263855536553789/')
self.assertEqual(gpe.get_issue_status(), 'Started')
self._p_soup.stop()
self.assertEqual(gpe.get_issue_summary(), 'Test "Issue"')
assert_equal(gpe.get_issue_description(),
- 'Test \\*Issue\\* for testing\n'
- '\n'
- ' 1. Test List\n'
- ' 2. Item\n'
- '\n'
- '\\*\\*Testing\\*\\*\n'
- '\n'
- ' \\* Test list 2\n'
- ' \\* Item\n'
- '\n'
- '\\# Test Section\n'
- '\n'
- ' p = source.test\\_issue.post\\(\\)\n'
- ' p.count = p.count \\*5 \\#\\* 6\n'
- ' if p.count > 5:\n'
- ' print "Not < 5 & \\!= 5"\n'
- '\n'
- 'References: [issue 1](#1), [r2]\n'
- '\n'
- 'That\'s all'
- )
- self.assertEqual(gpe.get_issue_created_date(), 'Thu Aug 8 15:33:52 2013')
+ 'Test \\*Issue\\* for testing\n'
+ '\n'
+ ' 1. Test List\n'
+ ' 2. Item\n'
+ '\n'
+ '\\*\\*Testing\\*\\*\n'
+ '\n'
+ ' \\* Test list 2\n'
+ ' \\* Item\n'
+ '\n'
+ '\\# Test Section\n'
+ '\n'
+ ' p = source.test\\_issue.post\\(\\)\n'
+ ' p.count = p.count \\*5 \\#\\* 6\n'
+ ' if p.count > 5:\n'
+ ' print "Not < 5 & \\!= 5"\n'
+ '\n'
+ 'References: [issue 1](#1), [r2]\n'
+ '\n'
+ 'That\'s all'
+ )
+ self.assertEqual(gpe.get_issue_created_date(),
+ 'Thu Aug 8 15:33:52 2013')
self.assertEqual(gpe.get_issue_stars(), 1)
def test_get_issue_summary(self):
@@ -253,168 +277,180 @@ class TestGoogleCodeProjectExtractor(TestCase):
self.assertEqual(gpe.get_issue_summary(), u'My Summary')
def test_get_issue_mod_date(self):
- test_issue = open(pkg_resources.resource_filename('forgeimporters', 'tests/data/google/test-issue.html')).read()
+ test_issue = open(pkg_resources.resource_filename(
+ 'forgeimporters', 'tests/data/google/test-issue.html')).read()
gpe = self._make_extractor(test_issue)
self.assertEqual(gpe.get_issue_mod_date(), 'Thu Aug 8 15:36:57 2013')
def test_get_issue_labels(self):
- test_issue = open(pkg_resources.resource_filename('forgeimporters', 'tests/data/google/test-issue.html')).read()
+ test_issue = open(pkg_resources.resource_filename(
+ 'forgeimporters', 'tests/data/google/test-issue.html')).read()
gpe = self._make_extractor(test_issue)
self.assertEqual(gpe.get_issue_labels(), [
- 'Type-Defect',
- 'Priority-Medium',
- 'Milestone-Release1.0',
- 'OpSys-All',
- 'Component-Logic',
- 'Performance',
- 'Security',
- 'OpSys-Windows',
- 'OpSys-OSX',
- ])
+ 'Type-Defect',
+ 'Priority-Medium',
+ 'Milestone-Release1.0',
+ 'OpSys-All',
+ 'Component-Logic',
+ 'Performance',
+ 'Security',
+ 'OpSys-Windows',
+ 'OpSys-OSX',
+ ])
@mock.patch.object(base, 'StringIO')
def test_get_issue_attachments(self, StringIO):
- self.urlopen.return_value.info.return_value = {'content-type': 'text/plain; foo'}
- test_issue = open(pkg_resources.resource_filename('forgeimporters', 'tests/data/google/test-issue.html')).read()
+ self.urlopen.return_value.info.return_value = {
+ 'content-type': 'text/plain; foo'}
+ test_issue = open(pkg_resources.resource_filename(
+ 'forgeimporters', 'tests/data/google/test-issue.html')).read()
gpe = self._make_extractor(test_issue)
attachments = gpe.get_issue_attachments()
self.assertEqual(len(attachments), 1)
self.assertEqual(attachments[0].filename, 'at1.txt')
- self.assertEqual(attachments[0].url, 'http://allura-google-importer.googlecode.com/issues/attachment?aid=70000000&name=at1.txt&token=3REU1M3JUUMt0rJUg7ldcELt6LA%3A1376059941255')
+ self.assertEqual(
+ attachments[0].url, 'http://allura-google-importer.googlecode.com/issues/attachment?aid=70000000&name=at1.txt&token=3REU1M3JUUMt0rJUg7ldcELt6LA%3A1376059941255')
self.assertEqual(attachments[0].type, 'text/plain')
@without_module('html2text')
@mock.patch.object(base, 'StringIO')
def test_iter_comments(self, StringIO):
- test_issue = open(pkg_resources.resource_filename('forgeimporters', 'tests/data/google/test-issue.html')).read()
+ test_issue = open(pkg_resources.resource_filename(
+ 'forgeimporters', 'tests/data/google/test-issue.html')).read()
gpe = self._make_extractor(test_issue)
comments = list(gpe.iter_comments())
self.assertEqual(len(comments), 4)
expected = [
- {
- 'author.name': 'john...@gmail.com',
- 'author.url': 'http://code.google.com/u/101557263855536553789/',
- 'created_date': 'Thu Aug 8 15:35:15 2013',
- 'body': 'Test \\*comment\\* is a comment',
- 'updates': {'Status:': 'Started', 'Labels:': '-OpSys-Linux OpSys-Windows'},
- 'attachments': ['at2.txt'],
- },
- {
- 'author.name': 'john...@gmail.com',
- 'author.url': 'http://code.google.com/u/101557263855536553789/',
- 'created_date': 'Thu Aug 8 15:35:34 2013',
- 'body': 'Another comment with references: [issue 2](#2), [r1]',
- 'updates': {},
- 'attachments': [],
- },
- {
- 'author.name': 'john...@gmail.com',
- 'author.url': 'http://code.google.com/u/101557263855536553789/',
- 'created_date': 'Thu Aug 8 15:36:39 2013',
- 'body': 'Last comment',
- 'updates': {},
- 'attachments': ['at4.txt', 'at1.txt'],
- },
- {
- 'author.name': 'john...@gmail.com',
- 'author.url': 'http://code.google.com/u/101557263855536553789/',
- 'created_date': 'Thu Aug 8 15:36:57 2013',
- 'body': 'Oh, I forgot one \\(with an inter\\-project reference to [issue other\\-project:1](https://code.google.com/p/other-project/issues/detail?id=1)\\)',
- 'updates': {'Labels:': 'OpSys-OSX'},
- 'attachments': [],
- },
- ]
+ {
+ 'author.name': 'john...@gmail.com',
+ 'author.url': 'http://code.google.com/u/101557263855536553789/',
+ 'created_date': 'Thu Aug 8 15:35:15 2013',
+ 'body': 'Test \\*comment\\* is a comment',
+ 'updates': {'Status:': 'Started', 'Labels:': '-OpSys-Linux OpSys-Windows'},
+ 'attachments': ['at2.txt'],
+ },
+ {
+ 'author.name': 'john...@gmail.com',
+ 'author.url': 'http://code.google.com/u/101557263855536553789/',
+ 'created_date': 'Thu Aug 8 15:35:34 2013',
+ 'body': 'Another comment with references: [issue 2](#2), [r1]',
+ 'updates': {},
+ 'attachments': [],
+ },
+ {
+ 'author.name': 'john...@gmail.com',
+ 'author.url': 'http://code.google.com/u/101557263855536553789/',
+ 'created_date': 'Thu Aug 8 15:36:39 2013',
+ 'body': 'Last comment',
+ 'updates': {},
+ 'attachments': ['at4.txt', 'at1.txt'],
+ },
+ {
+ 'author.name': 'john...@gmail.com',
+ 'author.url': 'http://code.google.com/u/101557263855536553789/',
+ 'created_date': 'Thu Aug 8 15:36:57 2013',
+ 'body': 'Oh, I forgot one \\(with an inter\\-project reference to [issue other\\-project:1](https://code.google.com/p/other-project/issues/detail?id=1)\\)',
+ 'updates': {'Labels:': 'OpSys-OSX'},
+ 'attachments': [],
+ },
+ ]
for actual, expected in zip(comments, expected):
self.assertEqual(actual.author.name, expected['author.name'])
self.assertEqual(actual.author.url, expected['author.url'])
self.assertEqual(actual.created_date, expected['created_date'])
self.assertEqual(actual.body, expected['body'])
self.assertEqual(actual.updates, expected['updates'])
- self.assertEqual([a.filename for a in actual.attachments], expected['attachments'])
+ self.assertEqual(
+ [a.filename for a in actual.attachments], expected['attachments'])
@skipif(module_not_available('html2text'))
@mock.patch.object(base, 'StringIO')
def test_iter_comments_html2text(self, StringIO):
- test_issue = open(pkg_resources.resource_filename('forgeimporters', 'tests/data/google/test-issue.html')).read()
+ test_issue = open(pkg_resources.resource_filename(
+ 'forgeimporters', 'tests/data/google/test-issue.html')).read()
gpe = self._make_extractor(test_issue)
comments = list(gpe.iter_comments())
self.assertEqual(len(comments), 4)
expected = [
- {
- 'author.name': 'john...@gmail.com',
- 'author.url': 'http://code.google.com/u/101557263855536553789/',
- 'created_date': 'Thu Aug 8 15:35:15 2013',
- 'body': 'Test \\*comment\\* is a comment',
- 'updates': {'Status:': 'Started', 'Labels:': '-OpSys-Linux OpSys-Windows'},
- 'attachments': ['at2.txt'],
- },
- {
- 'author.name': 'john...@gmail.com',
- 'author.url': 'http://code.google.com/u/101557263855536553789/',
- 'created_date': 'Thu Aug 8 15:35:34 2013',
- 'body': 'Another comment with references: [issue 2](#2), [r1]',
- 'updates': {},
- 'attachments': [],
- },
- {
- 'author.name': 'john...@gmail.com',
- 'author.url': 'http://code.google.com/u/101557263855536553789/',
- 'created_date': 'Thu Aug 8 15:36:39 2013',
- 'body': 'Last comment',
- 'updates': {},
- 'attachments': ['at4.txt', 'at1.txt'],
- },
- {
- 'author.name': 'john...@gmail.com',
- 'author.url': 'http://code.google.com/u/101557263855536553789/',
- 'created_date': 'Thu Aug 8 15:36:57 2013',
- 'body': 'Oh, I forgot one \\(with an inter-project reference to [issue other-project:1](https://code.google.com/p/other-project/issues/detail?id=1)\\)',
- 'updates': {'Labels:': 'OpSys-OSX'},
- 'attachments': [],
- },
- ]
+ {
+ 'author.name': 'john...@gmail.com',
+ 'author.url': 'http://code.google.com/u/101557263855536553789/',
+ 'created_date': 'Thu Aug 8 15:35:15 2013',
+ 'body': 'Test \\*comment\\* is a comment',
+ 'updates': {'Status:': 'Started', 'Labels:': '-OpSys-Linux OpSys-Windows'},
+ 'attachments': ['at2.txt'],
+ },
+ {
+ 'author.name': 'john...@gmail.com',
+ 'author.url': 'http://code.google.com/u/101557263855536553789/',
+ 'created_date': 'Thu Aug 8 15:35:34 2013',
+ 'body': 'Another comment with references: [issue 2](#2), [r1]',
+ 'updates': {},
+ 'attachments': [],
+ },
+ {
+ 'author.name': 'john...@gmail.com',
+ 'author.url': 'http://code.google.com/u/101557263855536553789/',
+ 'created_date': 'Thu Aug 8 15:36:39 2013',
+ 'body': 'Last comment',
+ 'updates': {},
+ 'attachments': ['at4.txt', 'at1.txt'],
+ },
+ {
+ 'author.name': 'john...@gmail.com',
+ 'author.url': 'http://code.google.com/u/101557263855536553789/',
+ 'created_date': 'Thu Aug 8 15:36:57 2013',
+ 'body': 'Oh, I forgot one \\(with an inter-project reference to [issue other-project:1](https://code.google.com/p/other-project/issues/detail?id=1)\\)',
+ 'updates': {'Labels:': 'OpSys-OSX'},
+ 'attachments': [],
+ },
+ ]
for actual, expected in zip(comments, expected):
self.assertEqual(actual.author.name, expected['author.name'])
self.assertEqual(actual.author.url, expected['author.url'])
self.assertEqual(actual.created_date, expected['created_date'])
self.assertEqual(actual.body, expected['body'])
self.assertEqual(actual.updates, expected['updates'])
- self.assertEqual([a.filename for a in actual.attachments], expected['attachments'])
+ self.assertEqual(
+ [a.filename for a in actual.attachments], expected['attachments'])
def test_get_issue_ids(self):
extractor = google.GoogleCodeProjectExtractor(None)
- extractor.get_page = mock.Mock(side_effect=((1, 2, 3),(2, 3, 4), ()))
+ extractor.get_page = mock.Mock(side_effect=((1, 2, 3), (2, 3, 4), ()))
self.assertItemsEqual(extractor.get_issue_ids(start=10), (1, 2, 3, 4))
self.assertEqual(extractor.get_page.call_count, 3)
extractor.get_page.assert_has_calls([
- mock.call('issues_csv', parser=google.csv_parser, start=10),
- mock.call('issues_csv', parser=google.csv_parser, start=110),
- mock.call('issues_csv', parser=google.csv_parser, start=210),
- ])
+ mock.call('issues_csv', parser=google.csv_parser, start=10),
+ mock.call('issues_csv', parser=google.csv_parser, start=110),
+ mock.call('issues_csv', parser=google.csv_parser, start=210),
+ ])
@mock.patch.object(google.GoogleCodeProjectExtractor, 'get_page')
@mock.patch.object(google.GoogleCodeProjectExtractor, 'get_issue_ids')
def test_iter_issue_ids(self, get_issue_ids, get_page):
get_issue_ids.side_effect = [set([1, 2]), set([2, 3, 4])]
- issue_ids = [i for i,e in list(google.GoogleCodeProjectExtractor.iter_issues('foo'))]
+ issue_ids = [i for i,
+ e in list(google.GoogleCodeProjectExtractor.iter_issues('foo'))]
self.assertEqual(issue_ids, [1, 2, 3, 4])
get_issue_ids.assert_has_calls([
- mock.call(start=0),
- mock.call(start=-8),
- ])
+ mock.call(start=0),
+ mock.call(start=-8),
+ ])
@mock.patch.object(google.GoogleCodeProjectExtractor, '__init__')
@mock.patch.object(google.GoogleCodeProjectExtractor, 'get_issue_ids')
def test_iter_issue_ids_raises(self, get_issue_ids, __init__):
get_issue_ids.side_effect = [set([1, 2, 3, 4, 5])]
__init__.side_effect = [
- None,
- None,
- HTTPError('fourohfour', 404, 'fourohfour', {}, mock.Mock()), # should skip but keep going
- None,
- HTTPError('fubar', 500, 'fubar', {}, mock.Mock()), # should be re-raised
- None,
- ]
+ None,
+ None,
+ # should skip but keep going
+ HTTPError('fourohfour', 404, 'fourohfour', {}, mock.Mock()),
+ None,
+ # should be re-raised
+ HTTPError('fubar', 500, 'fubar', {}, mock.Mock()),
+ None,
+ ]
issue_ids = []
try:
for issue_id, extractor in google.GoogleCodeProjectExtractor.iter_issues('foo'):
@@ -425,7 +461,9 @@ class TestGoogleCodeProjectExtractor(TestCase):
assert False, 'Missing expected raised exception'
self.assertEqual(issue_ids, [1, 3])
+
class TestUserLink(TestCase):
+
def test_plain(self):
tag = mock.Mock()
tag.text.strip.return_value = 'name'
@@ -484,10 +522,11 @@ class TestComment(TestCase):
self.assertEqual(comment.updates, {
u'Summary:': u'Make PyChess keyboard accessible',
u'Status:': u'Accepted',
- })
+ })
class TestAsMarkdown(TestCase):
+
def soup(self, tag):
return BeautifulSoup(u'<pre>%s</pre>' % tag).first()
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeImporters/forgeimporters/tests/google/test_tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/google/test_tracker.py b/ForgeImporters/forgeimporters/tests/google/test_tracker.py
index 7003e32..cfb8d97 100644
--- a/ForgeImporters/forgeimporters/tests/google/test_tracker.py
+++ b/ForgeImporters/forgeimporters/tests/google/test_tracker.py
@@ -30,6 +30,7 @@ from forgeimporters.google import tracker
class TestTrackerImporter(TestCase):
+
@mock.patch.object(tracker, 'g')
@mock.patch.object(tracker, 'c')
@mock.patch.object(tracker, 'ThreadLocalORMSession')
@@ -47,55 +48,57 @@ class TestTrackerImporter(TestCase):
app = project.install_app.return_value
app.config.options.mount_point = 'mount_point'
app.config.options.import_id = {
- 'source': 'Google Code',
- 'project_name': 'project_name',
- }
+ 'source': 'Google Code',
+ 'project_name': 'project_name',
+ }
app.config.options.get = lambda *a: getattr(app.config.options, *a)
app.url = 'foo'
- issues = gpe.iter_issues.return_value = [(50, mock.Mock()), (100, mock.Mock())]
+ issues = gpe.iter_issues.return_value = [
+ (50, mock.Mock()), (100, mock.Mock())]
tickets = TM.Ticket.side_effect = [mock.Mock(), mock.Mock()]
importer.import_tool(project, user, project_name='project_name',
- mount_point='mount_point', mount_label='mount_label')
+ mount_point='mount_point', mount_label='mount_label')
- project.install_app.assert_called_once_with('tickets', 'mount_point', 'mount_label',
- EnableVoting=True,
- open_status_names='New Accepted Started',
- closed_status_names='Fixed Verified Invalid Duplicate WontFix Done',
- import_id={
- 'source': 'Google Code',
- 'project_name': 'project_name',
- }
- )
+ project.install_app.assert_called_once_with(
+ 'tickets', 'mount_point', 'mount_label',
+ EnableVoting=True,
+ open_status_names='New Accepted Started',
+ closed_status_names='Fixed Verified Invalid Duplicate WontFix Done',
+ import_id={
+ 'source': 'Google Code',
+ 'project_name': 'project_name',
+ }
+ )
gpe.iter_issues.assert_called_once_with('project_name')
self.assertEqual(importer.process_fields.call_args_list, [
- mock.call(tickets[0], issues[0][1]),
- mock.call(tickets[1], issues[1][1]),
- ])
+ mock.call(tickets[0], issues[0][1]),
+ mock.call(tickets[1], issues[1][1]),
+ ])
self.assertEqual(importer.process_labels.call_args_list, [
- mock.call(tickets[0], issues[0][1]),
- mock.call(tickets[1], issues[1][1]),
- ])
+ mock.call(tickets[0], issues[0][1]),
+ mock.call(tickets[1], issues[1][1]),
+ ])
self.assertEqual(importer.process_comments.call_args_list, [
- mock.call(tickets[0], issues[0][1]),
- mock.call(tickets[1], issues[1][1]),
- ])
+ mock.call(tickets[0], issues[0][1]),
+ mock.call(tickets[1], issues[1][1]),
+ ])
self.assertEqual(tlos.flush_all.call_args_list, [
- mock.call(),
- mock.call(),
- ])
+ mock.call(),
+ mock.call(),
+ ])
self.assertEqual(session.return_value.flush.call_args_list, [
- mock.call(tickets[0]),
- mock.call(tickets[1]),
- ])
+ mock.call(tickets[0]),
+ mock.call(tickets[1]),
+ ])
self.assertEqual(session.return_value.expunge.call_args_list, [
- mock.call(tickets[0]),
- mock.call(tickets[1]),
- ])
+ mock.call(tickets[0]),
+ mock.call(tickets[1]),
+ ])
self.assertEqual(app.globals.last_ticket_num, 100)
M.AuditLog.log.assert_called_once_with(
- 'import tool mount_point from project_name on Google Code',
- project=project, user=user, url='foo')
+ 'import tool mount_point from project_name on Google Code',
+ project=project, user=user, url='foo')
g.post_event.assert_called_once_with('project_updated')
app.globals.invalidate_bin_counts.assert_called_once_with()
@@ -108,10 +111,12 @@ class TestTrackerImporter(TestCase):
user = mock.Mock()
importer = tracker.GoogleCodeTrackerImporter()
- self.assertRaises(ValueError, importer.import_tool, project, user, project_name='project_name',
- mount_point='mount_point', mount_label='mount_label')
+ self.assertRaises(
+ ValueError, importer.import_tool, project, user, project_name='project_name',
+ mount_point='mount_point', mount_label='mount_label')
- h.make_app_admin_only.assert_called_once_with(project.install_app.return_value)
+ h.make_app_admin_only.assert_called_once_with(
+ project.install_app.return_value)
def test_custom_fields(self):
importer = tracker.GoogleCodeTrackerImporter()
@@ -121,31 +126,31 @@ class TestTrackerImporter(TestCase):
importer.custom_field('Priority')
importer.custom_field('Type')
self.assertEqual(importer.custom_fields, {
- 'Foo': {
- 'type': 'string',
- 'label': 'Foo',
- 'name': '_foo',
- 'options': set(),
- },
- 'Milestone': {
- 'type': 'milestone',
- 'label': 'Milestone',
- 'name': '_milestone',
- 'options': set(),
- },
- 'Priority': {
- 'type': 'select',
- 'label': 'Priority',
- 'name': '_priority',
- 'options': set(),
- },
- 'Type': {
- 'type': 'select',
- 'label': 'Type',
- 'name': '_type',
- 'options': set(),
- },
- })
+ 'Foo': {
+ 'type': 'string',
+ 'label': 'Foo',
+ 'name': '_foo',
+ 'options': set(),
+ },
+ 'Milestone': {
+ 'type': 'milestone',
+ 'label': 'Milestone',
+ 'name': '_milestone',
+ 'options': set(),
+ },
+ 'Priority': {
+ 'type': 'select',
+ 'label': 'Priority',
+ 'name': '_priority',
+ 'options': set(),
+ },
+ 'Type': {
+ 'type': 'select',
+ 'label': 'Type',
+ 'name': '_type',
+ 'options': set(),
+ },
+ })
importer.custom_fields = {'Foo': {}}
importer.custom_field('Foo')
self.assertEqual(importer.custom_fields, {'Foo': {}})
@@ -153,33 +158,36 @@ class TestTrackerImporter(TestCase):
def test_process_fields(self):
ticket = mock.Mock()
issue = mock.Mock(
- get_issue_summary=lambda:'summary',
- get_issue_description=lambda:'my *description* fool',
- get_issue_status=lambda:'status',
- get_issue_created_date=lambda:'created_date',
- get_issue_mod_date=lambda:'mod_date',
- get_issue_creator=lambda:'creator',
- get_issue_owner=lambda:'owner',
- )
+ get_issue_summary=lambda: 'summary',
+ get_issue_description=lambda: 'my *description* fool',
+ get_issue_status=lambda: 'status',
+ get_issue_created_date=lambda: 'created_date',
+ get_issue_mod_date=lambda: 'mod_date',
+ get_issue_creator=lambda: 'creator',
+ get_issue_owner=lambda: 'owner',
+ )
importer = tracker.GoogleCodeTrackerImporter()
with mock.patch.object(tracker, 'dateutil') as dt:
dt.parser.parse.side_effect = lambda s: s
importer.process_fields(ticket, issue)
self.assertEqual(ticket.summary, 'summary')
- self.assertEqual(ticket.description, '*Originally created by:* creator\n*Originally owned by:* owner\n\nmy *description* fool')
+ self.assertEqual(ticket.description,
+ '*Originally created by:* creator\n*Originally owned by:* owner\n\nmy *description* fool')
self.assertEqual(ticket.status, 'status')
self.assertEqual(ticket.created_date, 'created_date')
self.assertEqual(ticket.mod_date, 'mod_date')
self.assertEqual(dt.parser.parse.call_args_list, [
- mock.call('created_date'),
- mock.call('mod_date'),
- ])
+ mock.call('created_date'),
+ mock.call('mod_date'),
+ ])
def test_process_labels(self):
ticket = mock.Mock(custom_fields={}, labels=[])
- issue = mock.Mock(get_issue_labels=lambda:['Foo-Bar', 'Baz', 'Foo-Qux'])
+ issue = mock.Mock(get_issue_labels=lambda:
+ ['Foo-Bar', 'Baz', 'Foo-Qux'])
importer = tracker.GoogleCodeTrackerImporter()
- importer.custom_field = mock.Mock(side_effect=lambda n: {'name': '_%s' % n.lower(), 'options': set()})
+ importer.custom_field = mock.Mock(
+ side_effect=lambda n: {'name': '_%s' % n.lower(), 'options': set()})
importer.process_labels(ticket, issue)
self.assertEqual(ticket.labels, ['Baz'])
self.assertEqual(ticket.custom_fields, {'_foo': 'Bar, Qux'})
@@ -193,94 +201,99 @@ class TestTrackerImporter(TestCase):
ticket = mock.Mock()
issue = mock.Mock()
comments = issue.iter_comments.return_value = [
- mock.Mock(
- author=_author(1),
- body='text1',
- annotated_text='annotated1',
- attachments='attachments1',
- created_date='Mon Jul 15 00:00:00 2013',
- ),
- mock.Mock(
- author=_author(2),
- body='text2',
- annotated_text='annotated2',
- attachments='attachments2',
- created_date='Mon Jul 16 00:00:00 2013',
- ),
- ]
- comments[0].updates.items.return_value = [('Foo:', 'Bar'), ('Baz:', 'Qux')]
+ mock.Mock(
+ author=_author(1),
+ body='text1',
+ annotated_text='annotated1',
+ attachments='attachments1',
+ created_date='Mon Jul 15 00:00:00 2013',
+ ),
+ mock.Mock(
+ author=_author(2),
+ body='text2',
+ annotated_text='annotated2',
+ attachments='attachments2',
+ created_date='Mon Jul 16 00:00:00 2013',
+ ),
+ ]
+ comments[0].updates.items.return_value = [
+ ('Foo:', 'Bar'), ('Baz:', 'Qux')]
comments[1].updates.items.return_value = []
posts = ticket.discussion_thread.add_post.side_effect = [
- mock.Mock(),
- mock.Mock(),
- ]
+ mock.Mock(),
+ mock.Mock(),
+ ]
importer = tracker.GoogleCodeTrackerImporter()
importer.process_comments(ticket, issue)
self.assertEqual(ticket.discussion_thread.add_post.call_args_list[0], mock.call(
- text='annotated1',
- timestamp=datetime(2013, 7, 15),
- ignore_security=True,
- ))
- posts[0].add_multiple_attachments.assert_called_once_with('attachments1')
+ text='annotated1',
+ timestamp=datetime(2013, 7, 15),
+ ignore_security=True,
+ ))
+ posts[0].add_multiple_attachments.assert_called_once_with(
+ 'attachments1')
self.assertEqual(ticket.discussion_thread.add_post.call_args_list[1], mock.call(
- text='annotated2',
- timestamp=datetime(2013, 7, 16),
- ignore_security=True,
- ))
- posts[1].add_multiple_attachments.assert_called_once_with('attachments2')
+ text='annotated2',
+ timestamp=datetime(2013, 7, 16),
+ ignore_security=True,
+ ))
+ posts[1].add_multiple_attachments.assert_called_once_with(
+ 'attachments2')
@mock.patch.object(tracker, 'c')
def test_postprocess_custom_fields(self, c):
importer = tracker.GoogleCodeTrackerImporter()
importer.open_milestones = set(['m2', 'm3'])
importer.custom_fields = {
- 'Foo': {
- 'name': '_foo',
- 'type': 'string',
- 'options': set(['foo', 'bar']),
- },
- 'Milestone': {
- 'name': '_milestone',
- 'type': 'milestone',
- 'options': set(['m3', 'm1', 'm2']),
- },
- 'Priority': {
- 'name': '_priority',
- 'type': 'select',
- 'options': set(['foo', 'bar']),
- },
- }
+ 'Foo': {
+ 'name': '_foo',
+ 'type': 'string',
+ 'options': set(['foo', 'bar']),
+ },
+ 'Milestone': {
+ 'name': '_milestone',
+ 'type': 'milestone',
+ 'options': set(['m3', 'm1', 'm2']),
+ },
+ 'Priority': {
+ 'name': '_priority',
+ 'type': 'select',
+ 'options': set(['foo', 'bar']),
+ },
+ }
custom_fields = importer.postprocess_custom_fields()
self.assertItemsEqual(custom_fields, [
- {
- 'name': '_foo',
- 'type': 'string',
- 'options': '',
- },
- {
- 'name': '_milestone',
- 'type': 'milestone',
- 'options': '',
- 'milestones': [
+ {
+ 'name': '_foo',
+ 'type': 'string',
+ 'options': '',
+ },
+ {
+ 'name': '_milestone',
+ 'type': 'milestone',
+ 'options': '',
+ 'milestones': [
{'name': 'm1', 'due_date': None, 'complete': True},
- {'name': 'm2', 'due_date': None, 'complete': False},
- {'name': 'm3', 'due_date': None, 'complete': False},
- ],
- },
- {
- 'name': '_priority',
- 'type': 'select',
- 'options': 'foo bar',
- },
- ])
+ {'name': 'm2', 'due_date': None, 'complete': False},
+ {'name': 'm3', 'due_date': None, 'complete': False},
+ ],
+ },
+ {
+ 'name': '_priority',
+ 'type': 'select',
+ 'options': 'foo bar',
+ },
+ ])
class TestGoogleCodeTrackerImportController(TestController, TestCase):
+
def setUp(self):
"""Mount Google Code importer on the Tracker admin controller"""
super(TestGoogleCodeTrackerImportController, self).setUp()
from forgetracker.tracker_main import TrackerAdminController
- TrackerAdminController._importer = tracker.GoogleCodeTrackerImportController()
+ TrackerAdminController._importer = tracker.GoogleCodeTrackerImportController(
+ )
@with_tracker
def test_index(self):
@@ -293,15 +306,18 @@ class TestGoogleCodeTrackerImportController(TestController, TestCase):
@patch('forgeimporters.base.import_tool')
def test_create(self, import_tool):
params = dict(gc_project_name='test',
- mount_label='mylabel',
- mount_point='mymount',
- )
+ mount_label='mylabel',
+ mount_point='mymount',
+ )
r = self.app.post('/p/test/admin/bugs/_importer/create', params,
- status=302)
+ status=302)
self.assertEqual(r.location, 'http://localhost/p/test/admin/')
- self.assertEqual(u'mymount', import_tool.post.call_args[1]['mount_point'])
- self.assertEqual(u'mylabel', import_tool.post.call_args[1]['mount_label'])
- self.assertEqual(u'test', import_tool.post.call_args[1]['project_name'])
+ self.assertEqual(
+ u'mymount', import_tool.post.call_args[1]['mount_point'])
+ self.assertEqual(
+ u'mylabel', import_tool.post.call_args[1]['mount_label'])
+ self.assertEqual(
+ u'test', import_tool.post.call_args[1]['project_name'])
@with_tracker
@patch('forgeimporters.base.import_tool')
@@ -310,10 +326,10 @@ class TestGoogleCodeTrackerImportController(TestController, TestCase):
project.set_tool_data('GoogleCodeTrackerImporter', pending=1)
ThreadLocalORMSession.flush_all()
params = dict(gc_project_name='test',
- mount_label='mylabel',
- mount_point='mymount',
- )
+ mount_label='mylabel',
+ mount_point='mymount',
+ )
r = self.app.post('/p/test/admin/bugs/_importer/create', params,
- status=302).follow()
+ status=302).follow()
self.assertIn('Please wait and try again', r)
self.assertEqual(import_tool.post.call_count, 0)
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeImporters/forgeimporters/tests/test_base.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/test_base.py b/ForgeImporters/forgeimporters/tests/test_base.py
index ade7b7a..91d9dff 100644
--- a/ForgeImporters/forgeimporters/tests/test_base.py
+++ b/ForgeImporters/forgeimporters/tests/test_base.py
@@ -32,6 +32,7 @@ from forgeimporters import base
class TestProjectExtractor(TestCase):
+
@mock.patch('forgeimporters.base.h.urlopen')
@mock.patch('forgeimporters.base.urllib2.Request')
def test_urlopen(self, Request, urlopen):
@@ -39,7 +40,7 @@ class TestProjectExtractor(TestCase):
Request.assert_called_once_with('myurl', data='foo')
req = Request.return_value
req.add_header.assert_called_once_with(
- 'User-Agent', 'Allura Data Importer (https://forge-allura.apache.org/p/allura/)')
+ 'User-Agent', 'Allura Data Importer (https://forge-allura.apache.org/p/allura/)')
urlopen.assert_called_once_with(req, retries=3, codes=(408,))
self.assertEqual(r, urlopen.return_value)
@@ -53,16 +54,17 @@ def test_import_tool(g, c, object_from_path):
object_from_path.return_value = importer = mock.Mock()
importer.return_value.source = 'source'
importer.return_value.tool_label = 'label'
- base.import_tool('forgeimporters.base.ToolImporter', project_name='project_name',
- mount_point='mount_point', mount_label='mount_label')
+ base.import_tool(
+ 'forgeimporters.base.ToolImporter', project_name='project_name',
+ mount_point='mount_point', mount_label='mount_label')
importer.return_value.import_tool.assert_called_once_with(c.project,
- c.user, project_name='project_name', mount_point='mount_point',
- mount_label='mount_label')
+ c.user, project_name='project_name', mount_point='mount_point',
+ mount_label='mount_label')
g.post_event.assert_called_once_with(
- 'import_tool_task_succeeded',
- 'source',
- 'label',
- )
+ 'import_tool_task_succeeded',
+ 'source',
+ 'label',
+ )
@mock.patch.object(base.traceback, 'format_exc')
@@ -72,20 +74,21 @@ def test_import_tool_failed(g, ToolImporter, format_exc):
format_exc.return_value = 'my traceback'
importer = mock.Mock(source='importer_source',
- tool_label='importer_tool_label')
+ tool_label='importer_tool_label')
importer.import_tool.side_effect = RuntimeError('my error')
ToolImporter.return_value = importer
- assert_raises(RuntimeError, base.import_tool, 'forgeimporters.base.ToolImporter',
- project_name='project_name')
+ assert_raises(
+ RuntimeError, base.import_tool, 'forgeimporters.base.ToolImporter',
+ project_name='project_name')
g.post_event.assert_called_once_with(
- 'import_tool_task_failed',
- error=str(importer.import_tool.side_effect),
- traceback='my traceback',
- importer_source='importer_source',
- importer_tool_label='importer_tool_label',
- project_name='project_name',
- )
+ 'import_tool_task_failed',
+ error=str(importer.import_tool.side_effect),
+ traceback='my traceback',
+ importer_source='importer_source',
+ importer_tool_label='importer_tool_label',
+ project_name='project_name',
+ )
def ep(name, source=None, importer=None, **kw):
@@ -101,12 +104,15 @@ def ep(name, source=None, importer=None, **kw):
class TestProjectImporter(TestCase):
+
@mock.patch.object(base.h, 'iter_entry_points')
def test_tool_importers(self, iep):
- eps = iep.return_value = [ep('ep1', 'foo'), ep('ep2', 'bar'), ep('ep3', 'foo')]
+ eps = iep.return_value = [
+ ep('ep1', 'foo'), ep('ep2', 'bar'), ep('ep3', 'foo')]
pi = base.ProjectImporter(mock.Mock(name='neighborhood'))
pi.source = 'foo'
- self.assertEqual(pi.tool_importers, {'ep1': eps[0].lv, 'ep3': eps[2].lv})
+ self.assertEqual(pi.tool_importers,
+ {'ep1': eps[0].lv, 'ep3': eps[2].lv})
iep.assert_called_once_with('allura.importers')
@mock.patch.object(base.ToolImporter, 'by_name')
@@ -123,15 +129,17 @@ class TestProjectImporter(TestCase):
pi.after_project_create = mock.Mock()
pi.neighborhood.register_project.return_value.script_name = 'script_name/'
kw = {
- 'project_name': 'project_name',
- 'project_shortname': 'shortname',
- 'tools': ['tool'],
- }
+ 'project_name': 'project_name',
+ 'project_shortname': 'shortname',
+ 'tools': ['tool'],
+ }
with mock.patch.dict(base.config, {'site_name': 'foo'}):
pi.process(**kw)
- pi.neighborhood.register_project.assert_called_once_with('shortname', project_name='project_name')
+ pi.neighborhood.register_project.assert_called_once_with(
+ 'shortname', project_name='project_name')
pi.after_project_create.assert_called_once_with(c.project, **kw)
- import_tool.post.assert_called_once_with('forgeimporters.base.ToolImporter', **kw)
+ import_tool.post.assert_called_once_with(
+ 'forgeimporters.base.ToolImporter', **kw)
M.AuditLog.log.assert_called_once_with('import project from Source')
self.assertEqual(flash.call_count, 1)
redirect.assert_called_once_with('script_name/admin/overview')
@@ -160,30 +168,34 @@ class TestProjectImporter(TestCase):
self.assertEqual(c.show_login_overlay, False)
-
TA1 = mock.Mock(tool_label='foo', tool_description='foo_desc')
TA2 = mock.Mock(tool_label='qux', tool_description='qux_desc')
TA3 = mock.Mock(tool_label='baz', tool_description='baz_desc')
+
class TI1Controller(object):
+
@expose()
def index(self, *a, **kw):
return 'test importer 1 controller webpage'
+
class TI1(base.ToolImporter):
target_app = TA1
controller = TI1Controller
+
class TI2(base.ToolImporter):
target_app = TA2
tool_label = 'bar'
tool_description = 'bar_desc'
+
class TI3(base.ToolImporter):
target_app = [TA2, TA2]
-class TestToolImporter(TestCase):
+class TestToolImporter(TestCase):
@mock.patch.object(base.h, 'iter_entry_points')
def test_by_name(self, iep):
@@ -201,15 +213,15 @@ class TestToolImporter(TestCase):
@mock.patch.object(base.h, 'iter_entry_points')
def test_by_app(self, iep):
eps = iep.return_value = [
- ep('importer1', importer=TI1),
- ep('importer2', importer=TI2),
- ep('importer3', importer=TI3),
- ]
+ ep('importer1', importer=TI1),
+ ep('importer2', importer=TI2),
+ ep('importer3', importer=TI3),
+ ]
importers = base.ToolImporter.by_app(TA2)
self.assertEqual(set(importers.keys()), set([
- 'importer2',
- 'importer3',
- ]))
+ 'importer2',
+ 'importer3',
+ ]))
self.assertIsInstance(importers['importer2'], TI2)
self.assertIsInstance(importers['importer3'], TI3)
@@ -225,6 +237,7 @@ class TestToolImporter(TestCase):
class TestToolsValidator(TestCase):
+
def setUp(self):
self.tv = base.ToolsValidator('good-source')
@@ -251,24 +264,28 @@ class TestToolsValidator(TestCase):
@mock.patch.object(base.ToolImporter, 'by_name')
def test_multiple(self, by_name):
- eps = by_name.side_effect = [ep('ep1', 'bad-source').lv, ep('ep2', 'good-source').lv, ep('ep3', 'bad-source').lv]
+ eps = by_name.side_effect = [
+ ep('ep1', 'bad-source').lv, ep('ep2', 'good-source').lv, ep('ep3', 'bad-source').lv]
with self.assertRaises(Invalid) as cm:
self.tv.to_python(['value1', 'value2', 'value3'])
- self.assertEqual(cm.exception.msg, 'Invalid tools selected: value1, value3')
+ self.assertEqual(cm.exception.msg,
+ 'Invalid tools selected: value1, value3')
self.assertEqual(by_name.call_args_list, [
- mock.call('value1'),
- mock.call('value2'),
- mock.call('value3'),
- ])
+ mock.call('value1'),
+ mock.call('value2'),
+ mock.call('value3'),
+ ])
@mock.patch.object(base.ToolImporter, 'by_name')
def test_valid(self, by_name):
- eps = by_name.side_effect = [ep('ep1', 'good-source').lv, ep('ep2', 'good-source').lv, ep('ep3', 'bad-source').lv]
- self.assertEqual(self.tv.to_python(['value1', 'value2']), ['value1', 'value2'])
+ eps = by_name.side_effect = [
+ ep('ep1', 'good-source').lv, ep('ep2', 'good-source').lv, ep('ep3', 'bad-source').lv]
+ self.assertEqual(
+ self.tv.to_python(['value1', 'value2']), ['value1', 'value2'])
self.assertEqual(by_name.call_args_list, [
- mock.call('value1'),
- mock.call('value2'),
- ])
+ mock.call('value1'),
+ mock.call('value2'),
+ ])
class TestProjectToolsImportController(TestController):
@@ -309,23 +326,26 @@ class TestProjectToolsImportController(TestController):
def test_get_importer_upload_path():
project = mock.Mock(
- shortname='prefix/shortname',
- is_nbhd_project=False,
- is_user_project=False,
- is_root=False,
- url=lambda: 'n_url/',
- neighborhood=mock.Mock(url_prefix='p/'),
- )
+ shortname='prefix/shortname',
+ is_nbhd_project=False,
+ is_user_project=False,
+ is_root=False,
+ url=lambda: 'n_url/',
+ neighborhood=mock.Mock(url_prefix='p/'),
+ )
with h.push_config(config, importer_upload_path='path/{nbhd}/{project}'):
assert_equal(base.get_importer_upload_path(project), 'path/p/prefix')
project.is_nbhd_project = True
assert_equal(base.get_importer_upload_path(project), 'path/p/n_url')
project.is_nbhd_project = False
project.is_user_project = True
- assert_equal(base.get_importer_upload_path(project), 'path/p/shortname')
+ assert_equal(base.get_importer_upload_path(project),
+ 'path/p/shortname')
project.is_user_project = False
project.is_root = True
- assert_equal(base.get_importer_upload_path(project), 'path/p/prefix/shortname')
+ assert_equal(base.get_importer_upload_path(project),
+ 'path/p/prefix/shortname')
+
@mock.patch.object(base, 'os')
@mock.patch.object(base, 'get_importer_upload_path')
@@ -342,7 +362,8 @@ def test_save_importer_upload(giup, os):
fp.write.assert_called_once_with('data')
os.makedirs.side_effect = OSError(errno.EACCES, 'foo')
- assert_raises(OSError, base.save_importer_upload, 'project', 'file', 'data')
+ assert_raises(OSError, base.save_importer_upload,
+ 'project', 'file', 'data')
class TestFile(object):
@@ -350,9 +371,9 @@ class TestFile(object):
@mock.patch.object(base, 'ProjectExtractor')
def test_type(self, PE):
PE().page = {
- 'content-type': 'image/png',
- 'data': 'data',
- }
+ 'content-type': 'image/png',
+ 'data': 'data',
+ }
f = base.File('http://example.com/barbaz.jpg')
assert_equal(f.type, 'image/jpeg')
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeImporters/forgeimporters/trac/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/trac/__init__.py b/ForgeImporters/forgeimporters/trac/__init__.py
index 77505f1..144e298 100644
--- a/ForgeImporters/forgeimporters/trac/__init__.py
+++ b/ForgeImporters/forgeimporters/trac/__init__.py
@@ -14,4 +14,3 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeImporters/forgeimporters/trac/project.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/trac/project.py b/ForgeImporters/forgeimporters/trac/project.py
index 71ef5f4..1dba980 100644
--- a/ForgeImporters/forgeimporters/trac/project.py
+++ b/ForgeImporters/forgeimporters/trac/project.py
@@ -37,6 +37,7 @@ class TracProjectForm(base.ProjectImportForm):
class TracProjectImporter(base.ProjectImporter):
+
"""
Project importer for Trac.
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeImporters/forgeimporters/trac/tests/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/trac/tests/__init__.py b/ForgeImporters/forgeimporters/trac/tests/__init__.py
index 77505f1..144e298 100644
--- a/ForgeImporters/forgeimporters/trac/tests/__init__.py
+++ b/ForgeImporters/forgeimporters/trac/tests/__init__.py
@@ -14,4 +14,3 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeImporters/forgeimporters/trac/tests/test_tickets.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/trac/tests/test_tickets.py b/ForgeImporters/forgeimporters/trac/tests/test_tickets.py
index eb97946..7ddb729 100644
--- a/ForgeImporters/forgeimporters/trac/tests/test_tickets.py
+++ b/ForgeImporters/forgeimporters/trac/tests/test_tickets.py
@@ -36,17 +36,18 @@ from forgeimporters.trac.tickets import (
TracTicketImporter,
TracTicketImportController,
TracImportSupport,
- )
+)
class TestTracTicketImporter(TestCase):
+
@patch('forgeimporters.trac.tickets.session')
@patch('forgeimporters.trac.tickets.g')
@patch('forgeimporters.trac.tickets.AuditLog')
@patch('forgeimporters.trac.tickets.TracImportSupport')
@patch('forgeimporters.trac.tickets.export')
def test_import_tool(self, export, ImportSupport, AuditLog, g, session):
- user_map = {"orig_user":"new_user"}
+ user_map = {"orig_user": "new_user"}
importer = TracTicketImporter()
app = Mock(name='ForgeTrackerApp')
app.config.options.mount_point = 'bugs'
@@ -57,31 +58,31 @@ class TestTracTicketImporter(TestCase):
user = Mock(name='User', _id='id')
export.return_value = []
res = importer.import_tool(project, user,
- mount_point='bugs',
- mount_label='Bugs',
- trac_url='http://example.com/trac/url',
- user_map=json.dumps(user_map),
- )
+ mount_point='bugs',
+ mount_label='Bugs',
+ trac_url='http://example.com/trac/url',
+ user_map=json.dumps(user_map),
+ )
self.assertEqual(res, app)
project.install_app.assert_called_once_with(
- 'Tickets', mount_point='bugs', mount_label='Bugs',
- open_status_names='new assigned accepted reopened',
- closed_status_names='closed',
- import_id={
- 'source': 'Trac',
- 'trac_url': 'http://example.com/trac/url/',
- })
+ 'Tickets', mount_point='bugs', mount_label='Bugs',
+ open_status_names='new assigned accepted reopened',
+ closed_status_names='closed',
+ import_id={
+ 'source': 'Trac',
+ 'trac_url': 'http://example.com/trac/url/',
+ })
export.assert_called_once_with('http://example.com/trac/url/')
ImportSupport.return_value.perform_import.assert_called_once_with(
- json.dumps(export.return_value),
- json.dumps({
- "user_map": user_map,
- "usernames_match": False,
- }),
- )
+ json.dumps(export.return_value),
+ json.dumps({
+ "user_map": user_map,
+ "usernames_match": False,
+ }),
+ )
AuditLog.log.assert_called_once_with(
- 'import tool bugs from http://example.com/trac/url/',
- project=project, user=user, url='foo')
+ 'import tool bugs from http://example.com/trac/url/',
+ project=project, user=user, url='foo')
g.post_event.assert_called_once_with('project_updated')
@patch('forgeimporters.trac.tickets.session')
@@ -96,21 +97,23 @@ class TestTracTicketImporter(TestCase):
export.side_effect = ValueError
self.assertRaises(ValueError, importer.import_tool, project, user,
- mount_point='bugs',
- mount_label='Bugs',
- trac_url='http://example.com/trac/url',
- user_map=None,
- )
+ mount_point='bugs',
+ mount_label='Bugs',
+ trac_url='http://example.com/trac/url',
+ user_map=None,
+ )
h.make_app_admin_only.assert_called_once_with(app)
class TestTracTicketImportController(TestController, TestCase):
+
def setUp(self):
"""Mount Trac import controller on the Tracker admin controller"""
super(TestTracTicketImportController, self).setUp()
from forgetracker.tracker_main import TrackerAdminController
- self.importer = TrackerAdminController._importer = TracTicketImportController()
+ self.importer = TrackerAdminController._importer = TracTicketImportController(
+ )
@with_tracker
def test_index(self):
@@ -123,17 +126,22 @@ class TestTracTicketImportController(TestController, TestCase):
@patch('forgeimporters.base.import_tool')
def test_create(self, import_tool):
params = dict(trac_url='http://example.com/trac/url',
- mount_label='mylabel',
- mount_point='mymount',
- )
+ mount_label='mylabel',
+ mount_point='mymount',
+ )
r = self.app.post('/p/test/admin/bugs/_importer/create', params,
- upload_files=[('user_map', 'myfile', '{"orig_user": "new_user"}')],
- status=302)
+ upload_files=[
+ ('user_map', 'myfile', '{"orig_user": "new_user"}')],
+ status=302)
self.assertEqual(r.location, 'http://localhost/p/test/admin/')
- self.assertEqual(u'mymount', import_tool.post.call_args[1]['mount_point'])
- self.assertEqual(u'mylabel', import_tool.post.call_args[1]['mount_label'])
- self.assertEqual('{"orig_user": "new_user"}', import_tool.post.call_args[1]['user_map'])
- self.assertEqual(u'http://example.com/trac/url', import_tool.post.call_args[1]['trac_url'])
+ self.assertEqual(
+ u'mymount', import_tool.post.call_args[1]['mount_point'])
+ self.assertEqual(
+ u'mylabel', import_tool.post.call_args[1]['mount_label'])
+ self.assertEqual('{"orig_user": "new_user"}',
+ import_tool.post.call_args[1]['user_map'])
+ self.assertEqual(u'http://example.com/trac/url',
+ import_tool.post.call_args[1]['trac_url'])
@with_tracker
@patch('forgeimporters.base.import_tool')
@@ -142,58 +150,62 @@ class TestTracTicketImportController(TestController, TestCase):
project.set_tool_data('TracTicketImporter', pending=1)
ThreadLocalORMSession.flush_all()
params = dict(trac_url='http://example.com/trac/url',
- mount_label='mylabel',
- mount_point='mymount',
- )
+ mount_label='mylabel',
+ mount_point='mymount',
+ )
r = self.app.post('/p/test/admin/bugs/_importer/create', params,
- upload_files=[('user_map', 'myfile', '{"orig_user": "new_user"}')],
- status=302).follow()
+ upload_files=[
+ ('user_map', 'myfile', '{"orig_user": "new_user"}')],
+ status=302).follow()
self.assertIn('Please wait and try again', r)
self.assertEqual(import_tool.post.call_count, 0)
class TestTracImportSupport(TestCase):
+
def test_link_processing(self):
import_support = TracImportSupport()
import_support.get_slug_by_id = lambda ticket, comment: '123'
cases = {
- 'test link [[2496]](http://testlink.com)':
- "test link [\[2496\]](http://testlink.com)",
+ 'test link [[2496]](http://testlink.com)':
+ "test link [\[2496\]](http://testlink.com)",
- 'test ticket ([#201](http://site.net/apps/trac/project/ticket/201))':
- 'test ticket ([#201](201))',
+ 'test ticket ([#201](http://site.net/apps/trac/project/ticket/201))':
+ 'test ticket ([#201](201))',
- 'Replying to [someuser](http://site.net/apps/trac/project/ticket/204#comment:1)':
- 'Replying to [someuser](204/#123)',
+ 'Replying to [someuser](http://site.net/apps/trac/project/ticket/204#comment:1)':
+ 'Replying to [someuser](204/#123)',
- '**description** modified ([diff](http://site.net/apps/trac/project/ticket/205?action=diff&version=1))':
- '**description** modified ([diff](205))',
+ '**description** modified ([diff](http://site.net/apps/trac/project/ticket/205?action=diff&version=1))':
+ '**description** modified ([diff](205))',
- 'Fixed in [r1000](http://site.net/apps/trac/project/changeset/1000)':
- 'Fixed in [r1000](r1000)',
+ 'Fixed in [r1000](http://site.net/apps/trac/project/changeset/1000)':
+ 'Fixed in [r1000](r1000)',
- '[[Double brackets]](1) the [[whole way]](2).':
- '[\[Double brackets\]](1) the [\[whole way\]](2).',
+ '[[Double brackets]](1) the [[whole way]](2).':
+ '[\[Double brackets\]](1) the [\[whole way\]](2).',
- '#200 unchanged':
- '#200 unchanged',
- }
+ '#200 unchanged':
+ '#200 unchanged',
+ }
for input, expected in cases.items():
actual = import_support.link_processing(input)
self.assertEqual(actual, expected)
class TestTracImportSupportFunctional(TestRestApiBase, TestCase):
+
@with_tracker
def test_links(self):
- doc_text = open(os.path.dirname(__file__) + '/data/trac-export.json').read()
+ doc_text = open(os.path.dirname(__file__)
+ + '/data/trac-export.json').read()
TracImportSupport().perform_import(doc_text,
- '{"user_map": {"hinojosa4": "test-admin", "ma_boehm": "test-user"}}')
+ '{"user_map": {"hinojosa4": "test-admin", "ma_boehm": "test-user"}}')
r = self.app.get('/p/test/bugs/204/')
ticket = TM.Ticket.query.get(app_config_id=c.app.config._id,
- ticket_num=204)
+ ticket_num=204)
slug = ticket.discussion_thread.post_class().query.find(dict(
discussion_id=ticket.discussion_thread.discussion_id,
thread_id=ticket.discussion_thread._id,
@@ -205,21 +217,24 @@ class TestTracImportSupportFunctional(TestRestApiBase, TestCase):
@with_tracker
def test_slug(self):
- doc_text = open(os.path.dirname(__file__) + '/data/trac-export.json').read()
+ doc_text = open(os.path.dirname(__file__)
+ + '/data/trac-export.json').read()
TracImportSupport().perform_import(doc_text,
- '{"user_map": {"hinojosa4": "test-admin", "ma_boehm": "test-user"}}')
+ '{"user_map": {"hinojosa4": "test-admin", "ma_boehm": "test-user"}}')
ticket = TM.Ticket.query.get(app_config_id=c.app.config._id,
- ticket_num=204)
+ ticket_num=204)
comments = ticket.discussion_thread.post_class().query.find(dict(
discussion_id=ticket.discussion_thread.discussion_id,
thread_id=ticket.discussion_thread._id,
status={'$in': ['ok', 'pending']})).sort('timestamp').all()
import_support = TracImportSupport()
- self.assertEqual(import_support.get_slug_by_id('204', '1'), comments[0].slug)
- self.assertEqual(import_support.get_slug_by_id('204', '2'), comments[1].slug)
+ self.assertEqual(
+ import_support.get_slug_by_id('204', '1'), comments[0].slug)
+ self.assertEqual(
+ import_support.get_slug_by_id('204', '2'), comments[1].slug)
@with_tracker
@skipif(module_not_available('html2text'))
@@ -233,14 +248,16 @@ class TestTracImportSupportFunctional(TestRestApiBase, TestCase):
te.csvopen = lambda s: csv_fp
with patch('allura.scripts.trac_export.urlopen', return_value=html_fp):
json_data = {
- 'class': 'PROJECT',
- 'trackers': {'default': {'artifacts': list(te)}},
- }
+ 'class': 'PROJECT',
+ 'trackers': {'default': {'artifacts': list(te)}},
+ }
TracImportSupport().perform_import(
- json.dumps(json_data, cls=DateJSONEncoder),
- '{"user_map": {}}')
+ json.dumps(json_data, cls=DateJSONEncoder),
+ '{"user_map": {}}')
ticket = TM.Ticket.query.get(app_config_id=c.app.config._id,
- ticket_num=390)
- self.assertIn('To reproduce: \n\\- open an mzML file', ticket.description)
- self.assertIn('duplicate of: \n\\- [#316](316)', ticket.discussion_thread.find_posts()[0].text)
+ ticket_num=390)
+ self.assertIn('To reproduce: \n\\- open an mzML file',
+ ticket.description)
+ self.assertIn('duplicate of: \n\\- [#316](316)',
+ ticket.discussion_thread.find_posts()[0].text)
self.assertIn('will crash TOPPView.', ticket.description)
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeImporters/forgeimporters/trac/tickets.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/trac/tickets.py b/ForgeImporters/forgeimporters/trac/tickets.py
index 4fd8fdf..c2c28c1 100644
--- a/ForgeImporters/forgeimporters/trac/tickets.py
+++ b/ForgeImporters/forgeimporters/trac/tickets.py
@@ -24,15 +24,15 @@ from ming.orm import session
from pylons import tmpl_context as c
from pylons import app_globals as g
from tg import (
- expose,
- flash,
- redirect,
- validate,
- )
+ expose,
+ flash,
+ redirect,
+ validate,
+)
from tg.decorators import (
- with_trailing_slash,
- without_trailing_slash,
- )
+ with_trailing_slash,
+ without_trailing_slash,
+)
from allura.controllers import BaseController
from allura.lib.decorators import require_post
@@ -40,14 +40,14 @@ from allura.lib import validators as v
from allura.lib import helpers as h
from allura.model import AuditLog
from allura.scripts.trac_export import (
- export,
- DateJSONEncoder,
- )
+ export,
+ DateJSONEncoder,
+)
from forgeimporters.base import (
- ToolImporter,
- ToolImportForm,
- )
+ ToolImporter,
+ ToolImportForm,
+)
from forgetracker.tracker_main import ForgeTrackerApp
from forgetracker.import_support import ImportSupport
from forgetracker import model as TM
@@ -59,6 +59,7 @@ class TracTicketImportForm(ToolImportForm):
class TracTicketImportController(BaseController):
+
def __init__(self):
self.importer = TracTicketImporter()
@@ -70,7 +71,7 @@ class TracTicketImportController(BaseController):
@expose('jinja:forgeimporters.trac:templates/tickets/index.html')
def index(self, **kw):
return dict(importer=self.importer,
- target_app=self.target_app)
+ target_app=self.target_app)
@without_trailing_slash
@expose()
@@ -79,15 +80,16 @@ class TracTicketImportController(BaseController):
def create(self, trac_url, mount_point, mount_label, user_map=None, **kw):
if self.importer.enforce_limit(c.project):
self.importer.post(
- project_name=trac_url,
- mount_point=mount_point,
- mount_label=mount_label,
- trac_url=trac_url,
- user_map=user_map)
+ project_name=trac_url,
+ mount_point=mount_point,
+ mount_label=mount_label,
+ trac_url=trac_url,
+ user_map=user_map)
flash('Ticket import has begun. Your new tracker will be available '
- 'when the import is complete.')
+ 'when the import is complete.')
else:
- flash('There are too many imports pending at this time. Please wait and try again.', 'error')
+ flash(
+ 'There are too many imports pending at this time. Please wait and try again.', 'error')
redirect(c.project.url() + 'admin/')
@@ -99,39 +101,39 @@ class TracTicketImporter(ToolImporter):
tool_description = 'Import your tickets from Trac'
def import_tool(self, project, user, project_name=None, mount_point=None,
- mount_label=None, trac_url=None, user_map=None, **kw):
+ mount_label=None, trac_url=None, user_map=None, **kw):
""" Import Trac tickets into a new Allura Tracker tool.
"""
trac_url = trac_url.rstrip('/') + '/'
mount_point = mount_point or 'tickets'
app = project.install_app(
- 'Tickets',
- mount_point=mount_point,
- mount_label=mount_label or 'Tickets',
- open_status_names='new assigned accepted reopened',
- closed_status_names='closed',
- import_id={
- 'source': self.source,
- 'trac_url': trac_url,
- },
- )
+ 'Tickets',
+ mount_point=mount_point,
+ mount_label=mount_label or 'Tickets',
+ open_status_names='new assigned accepted reopened',
+ closed_status_names='closed',
+ import_id={
+ 'source': self.source,
+ 'trac_url': trac_url,
+ },
+ )
session(app.config).flush(app.config)
session(app.globals).flush(app.globals)
try:
with h.push_config(c, app=app):
TracImportSupport().perform_import(
- json.dumps(export(trac_url), cls=DateJSONEncoder),
- json.dumps({
- 'user_map': json.loads(user_map) if user_map else {},
- 'usernames_match': self.usernames_match(trac_url),
- }),
- )
+ json.dumps(export(trac_url), cls=DateJSONEncoder),
+ json.dumps({
+ 'user_map': json.loads(user_map) if user_map else {},
+ 'usernames_match': self.usernames_match(trac_url),
+ }),
+ )
AuditLog.log(
'import tool %s from %s' % (
- app.config.options.mount_point,
- trac_url,
- ),
+ app.config.options.mount_point,
+ trac_url,
+ ),
project=project, user=user, url=app.url,
)
g.post_event('project_updated')
@@ -156,6 +158,7 @@ class TracTicketImporter(ToolImporter):
class TracImportSupport(ImportSupport):
+
"""Provides Trac-specific ticket and comment text processing."""
def ticket_link(self, m):
@@ -176,7 +179,7 @@ class TracImportSupport(ImportSupport):
status={'$in': ['ok', 'pending']})).sort('timestamp')
if comment <= comments.count():
- return comments.all()[comment-1].slug
+ return comments.all()[comment - 1].slug
def comment_link(self, m):
"""Convert a Trac-style comment url to it's equivalent Allura url."""
@@ -205,9 +208,11 @@ class TracImportSupport(ImportSupport):
* Escape double-brackets
"""
- comment_pattern = re.compile('\[(\S*\s*\S*)\]\(\S*/(\d+\n*\d*)#comment:(\d+)\)')
+ comment_pattern = re.compile(
+ '\[(\S*\s*\S*)\]\(\S*/(\d+\n*\d*)#comment:(\d+)\)')
ticket_pattern = re.compile('(?<=\])\(\S*ticket/(\d+)(?:\?[^)]*)?\)')
- changeset_pattern = re.compile(r'(?<=\])\(\S*/changeset/(\d+)(?:\?[^]]*)?\)')
+ changeset_pattern = re.compile(
+ r'(?<=\])\(\S*/changeset/(\d+)(?:\?[^]]*)?\)')
brackets_pattern = re.compile('\[\[([^]]*)\]\]')
text = comment_pattern.sub(self.comment_link, text)
@@ -223,4 +228,3 @@ class TracImportSupport(ImportSupport):
def description_processing(self, description_text):
"""Modify ticket description before ticket is created."""
return self.link_processing(description_text)
-
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeLink/forgelink/link_main.py
----------------------------------------------------------------------
diff --git a/ForgeLink/forgelink/link_main.py b/ForgeLink/forgelink/link_main.py
index d37db1b..0f2292a 100644
--- a/ForgeLink/forgelink/link_main.py
+++ b/ForgeLink/forgelink/link_main.py
@@ -40,25 +40,26 @@ log = logging.getLogger(__name__)
class ForgeLinkApp(Application):
+
'''This is the Link app for PyForge'''
__version__ = version.__version__
- permissions = [ 'configure', 'read' ]
+ permissions = ['configure', 'read']
permissions_desc = {
'read': 'View link.',
}
config_options = Application.config_options + [
ConfigOption('url', str, None)
]
- searchable=True
- exportable=True
- tool_label='External Link'
- default_mount_label='Link name'
- default_mount_point='link'
- ordinal=1
- icons={
- 24:'images/ext_24.png',
- 32:'images/ext_32.png',
- 48:'images/ext_48.png'
+ searchable = True
+ exportable = True
+ tool_label = 'External Link'
+ default_mount_label = 'Link name'
+ default_mount_point = 'link'
+ ordinal = 1
+ icons = {
+ 24: 'images/ext_24.png',
+ 32: 'images/ext_32.png',
+ 48: 'images/ext_48.png'
}
def __init__(self, project, config):
@@ -71,7 +72,7 @@ class ForgeLinkApp(Application):
@h.exceptionless([], log)
def sitemap(self):
menu_id = self.config.options.mount_label
- return [SitemapEntry(menu_id, '.')[self.sidebar_menu()] ]
+ return [SitemapEntry(menu_id, '.')[self.sidebar_menu()]]
def sidebar_menu(self):
return []
@@ -89,14 +90,15 @@ class ForgeLinkApp(Application):
self.config.acl = [
M.ACE.allow(role_anon, 'read'),
M.ACE.allow(role_admin, 'configure'),
- ]
+ ]
def uninstall(self, project):
"Remove all the tool's artifacts from the database"
super(ForgeLinkApp, self).uninstall(project)
def bulk_export(self, f):
- json.dump(RootRestController(self).link_json(), f, cls=jsonify.GenericJSON, indent=2)
+ json.dump(RootRestController(self).link_json(),
+ f, cls=jsonify.GenericJSON, indent=2)
class RootController(BaseController):
@@ -125,7 +127,7 @@ class LinkAdminController(DefaultAdminController):
@expose()
def index(self, **kw):
flash('External link URL updated.')
- redirect(c.project.url()+'admin/tools')
+ redirect(c.project.url() + 'admin/tools')
class RootRestController(BaseController):
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeLink/forgelink/tests/functional/test_rest.py
----------------------------------------------------------------------
diff --git a/ForgeLink/forgelink/tests/functional/test_rest.py b/ForgeLink/forgelink/tests/functional/test_rest.py
index 05a55a2..d7bb7da 100644
--- a/ForgeLink/forgelink/tests/functional/test_rest.py
+++ b/ForgeLink/forgelink/tests/functional/test_rest.py
@@ -38,10 +38,12 @@ class TestLinkApi(TestRestApiBase):
r = self.api_get(u'/rest/p/test/link'.encode('utf-8'))
assert_equal(r.json['url'], None)
- r = self.api_post(u'/rest/p/test/link'.encode('utf-8'), url='http://google.com')
+ r = self.api_post(u'/rest/p/test/link'.encode('utf-8'),
+ url='http://google.com')
assert_equal(r.json['url'], 'http://google.com')
- self.api_post(u'/rest/p/test/link'.encode('utf-8'), url='http://yahoo.com')
+ self.api_post(u'/rest/p/test/link'.encode('utf-8'),
+ url='http://yahoo.com')
r = self.api_get(u'/rest/p/test/link'.encode('utf-8'))
assert_equal(r.json['url'], 'http://yahoo.com')
@@ -50,13 +52,15 @@ class TestLinkApi(TestRestApiBase):
assert_equal(r.json['url'], 'http://yahoo.com')
def test_rest_link_get_permissions(self):
- self.app.get('/rest/p/test/link', extra_environ={'username': '*anonymous'}, status=200)
+ self.app.get('/rest/p/test/link',
+ extra_environ={'username': '*anonymous'}, status=200)
p = M.Project.query.get(shortname='test')
acl = p.app_instance('link').config.acl
anon = M.ProjectRole.by_name('*anonymous')._id
anon_read = M.ACE.allow(anon, 'read')
acl.remove(anon_read)
- self.app.get('/rest/p/test/link', extra_environ={'username': '*anonymous'}, status=401)
+ self.app.get('/rest/p/test/link',
+ extra_environ={'username': '*anonymous'}, status=401)
def test_rest_link_post_permissions(self):
self.app.post('/rest/p/test/link',
@@ -74,7 +78,3 @@ class TestLinkApi(TestRestApiBase):
status=200)
r = self.api_get(u'/rest/p/test/link'.encode('utf-8'))
assert_equal(r.json['url'], 'http://yahoo.com')
-
-
-
-
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeLink/forgelink/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeLink/forgelink/tests/functional/test_root.py b/ForgeLink/forgelink/tests/functional/test_root.py
index a8f6778..ca57244 100644
--- a/ForgeLink/forgelink/tests/functional/test_root.py
+++ b/ForgeLink/forgelink/tests/functional/test_root.py
@@ -20,6 +20,7 @@ from alluratest.controller import TestController
class TestRootController(TestController):
+
def test_root_index_no_url(self):
response = self.app.get('/link/index')
assert 'Link is not configured' in response
@@ -57,4 +58,3 @@ class TestRootController(TestController):
response = self.app.get('/link/help')
# HACK: support for remote redirects is limited in follow()
assert 'http://www.google.de/search?q=help' in response
-