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:34 UTC
[10/32] PEP8 cleanup
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeImporters/forgeimporters/google/tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/google/tracker.py b/ForgeImporters/forgeimporters/google/tracker.py
index 48bfbfe..ab131a8 100644
--- a/ForgeImporters/forgeimporters/google/tracker.py
+++ b/ForgeImporters/forgeimporters/google/tracker.py
@@ -26,15 +26,15 @@ from ming.orm import session, ThreadLocalORMSession
import dateutil.parser
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 import helpers as h
@@ -47,9 +47,9 @@ from forgetracker import model as TM
from forgeimporters.google import GoogleCodeProjectExtractor
from forgeimporters.google import GoogleCodeProjectNameValidator
from forgeimporters.base import (
- ToolImporter,
- ToolImportForm,
- )
+ ToolImporter,
+ ToolImportForm,
+)
class GoogleCodeTrackerImportForm(ToolImportForm):
@@ -57,6 +57,7 @@ class GoogleCodeTrackerImportForm(ToolImportForm):
class GoogleCodeTrackerImportController(BaseController):
+
def __init__(self):
self.importer = GoogleCodeTrackerImporter()
@@ -68,7 +69,7 @@ class GoogleCodeTrackerImportController(BaseController):
@expose('jinja:forgeimporters.google:templates/tracker/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()
@@ -77,14 +78,15 @@ class GoogleCodeTrackerImportController(BaseController):
def create(self, gc_project_name, mount_point, mount_label, **kw):
if self.importer.enforce_limit(c.project):
self.importer.post(
- project_name=gc_project_name,
- mount_point=mount_point,
- mount_label=mount_label,
- )
+ project_name=gc_project_name,
+ mount_point=mount_point,
+ mount_label=mount_label,
+ )
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/')
@@ -96,10 +98,10 @@ class GoogleCodeTrackerImporter(ToolImporter):
tool_description = 'Import your public tickets from Google Code'
field_types = defaultdict(lambda: 'string',
- milestone='milestone',
- priority='select',
- type='select',
- )
+ milestone='milestone',
+ priority='select',
+ type='select',
+ )
def __init__(self, *args, **kwargs):
super(GoogleCodeTrackerImporter, self).__init__(*args, **kwargs)
@@ -108,17 +110,17 @@ class GoogleCodeTrackerImporter(ToolImporter):
self.max_ticket_num = 0
def import_tool(self, project, user, project_name, mount_point=None,
- mount_label=None, **kw):
+ mount_label=None, **kw):
import_id_converter = ImportIdConverter.get()
app = project.install_app('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': self.source,
- 'project_name': project_name,
- },
- )
+ EnableVoting=True,
+ open_status_names='New Accepted Started',
+ closed_status_names='Fixed Verified Invalid Duplicate WontFix Done',
+ import_id={
+ 'source': self.source,
+ 'project_name': project_name,
+ },
+ )
ThreadLocalORMSession.flush_all()
try:
M.session.artifact_orm_session._get().skip_mod_date = True
@@ -139,14 +141,14 @@ class GoogleCodeTrackerImporter(ToolImporter):
app.globals.last_ticket_num = self.max_ticket_num
ThreadLocalORMSession.flush_all()
M.AuditLog.log(
- 'import tool %s from %s on %s' % (
- app.config.options.mount_point,
- project_name, self.source,
- ),
- project=project,
- user=user,
- url=app.url,
- )
+ 'import tool %s from %s on %s' % (
+ app.config.options.mount_point,
+ project_name, self.source,
+ ),
+ project=project,
+ user=user,
+ url=app.url,
+ )
g.post_event('project_updated')
app.globals.invalidate_bin_counts()
return app
@@ -159,17 +161,18 @@ class GoogleCodeTrackerImporter(ToolImporter):
def custom_field(self, name):
if name not in self.custom_fields:
self.custom_fields[name] = {
- 'type': self.field_types[name.lower()],
- 'label': name,
- 'name': u'_%s' % name.lower(),
- 'options': set(),
- }
+ 'type': self.field_types[name.lower()],
+ 'label': name,
+ 'name': u'_%s' % name.lower(),
+ 'options': set(),
+ }
return self.custom_fields[name]
def process_fields(self, ticket, issue):
ticket.summary = issue.get_issue_summary()
ticket.status = issue.get_issue_status()
- ticket.created_date = dateutil.parser.parse(issue.get_issue_created_date())
+ ticket.created_date = dateutil.parser.parse(
+ issue.get_issue_created_date())
ticket.mod_date = dateutil.parser.parse(issue.get_issue_mod_date())
ticket.votes_up = issue.get_issue_stars()
ticket.votes = issue.get_issue_stars()
@@ -179,14 +182,14 @@ class GoogleCodeTrackerImporter(ToolImporter):
else:
owner_line = ''
ticket.description = (
- u'*Originally created by:* {creator}\n'
- u'{owner}'
- u'\n'
- u'{body}').format(
- creator=issue.get_issue_creator(),
- owner=owner_line,
- body=issue.get_issue_description(),
- )
+ u'*Originally created by:* {creator}\n'
+ u'{owner}'
+ u'\n'
+ u'{body}').format(
+ creator=issue.get_issue_creator(),
+ owner=owner_line,
+ body=issue.get_issue_description(),
+ )
ticket.add_multiple_attachments(issue.get_issue_attachments())
def process_labels(self, ticket, issue):
@@ -203,15 +206,16 @@ class GoogleCodeTrackerImporter(ToolImporter):
else:
labels.add(label)
ticket.labels = list(labels)
- ticket.custom_fields = {n: u', '.join(sorted(v)) for n,v in custom_fields.iteritems()}
+ ticket.custom_fields = {n: u', '.join(sorted(v))
+ for n, v in custom_fields.iteritems()}
def process_comments(self, ticket, issue):
for comment in issue.iter_comments():
p = ticket.discussion_thread.add_post(
- text = comment.annotated_text,
- ignore_security = True,
- timestamp = dateutil.parser.parse(comment.created_date),
- )
+ text=comment.annotated_text,
+ ignore_security=True,
+ timestamp=dateutil.parser.parse(comment.created_date),
+ )
p.add_multiple_attachments(comment.attachments)
def postprocess_custom_fields(self):
@@ -219,10 +223,10 @@ class GoogleCodeTrackerImporter(ToolImporter):
for name, field in self.custom_fields.iteritems():
if field['name'] == '_milestone':
field['milestones'] = [{
- 'name': milestone,
- 'due_date': None,
- 'complete': milestone not in self.open_milestones,
- } for milestone in sorted(field['options'])]
+ 'name': milestone,
+ 'due_date': None,
+ 'complete': milestone not in self.open_milestones,
+ } for milestone in sorted(field['options'])]
field['options'] = ''
elif field['type'] == 'select':
field['options'] = ' '.join(field['options'])
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeImporters/forgeimporters/tests/forge/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/forge/__init__.py b/ForgeImporters/forgeimporters/tests/forge/__init__.py
index 77505f1..144e298 100644
--- a/ForgeImporters/forgeimporters/tests/forge/__init__.py
+++ b/ForgeImporters/forgeimporters/tests/forge/__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/tests/forge/test_tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/forge/test_tracker.py b/ForgeImporters/forgeimporters/tests/forge/test_tracker.py
index 85f4650..152e5bc 100644
--- a/ForgeImporters/forgeimporters/tests/forge/test_tracker.py
+++ b/ForgeImporters/forgeimporters/tests/forge/test_tracker.py
@@ -30,6 +30,7 @@ from forgeimporters.forge import tracker
class TestTrackerImporter(TestCase):
+
@mock.patch.object(tracker.h, 'make_app_admin_only')
@mock.patch.object(tracker, 'g')
@mock.patch.object(tracker, 'c')
@@ -40,156 +41,158 @@ class TestTrackerImporter(TestCase):
def test_import_tool(self, TM, M, session, tlos, c, g, mao):
importer = tracker.ForgeTrackerImporter()
importer._load_json = mock.Mock(return_value={
- 'tracker_config': {
- '_id': 'orig_id',
- 'options': {
- 'foo': 'bar',
- },
- },
- 'open_status_names': 'open statuses',
- 'closed_status_names': 'closed statuses',
- 'custom_fields': 'fields',
- 'saved_bins': 'bins',
- 'tickets': [
- {
- 'reported_by': 'rb1',
- 'assigned_to': 'at1',
- 'ticket_num': 1,
- 'description': 'd1',
- 'created_date': '2013-09-01',
- 'mod_date': '2013-09-02',
- 'summary': 's1',
- 'custom_fields': 'cf1',
- 'status': 'st1',
- 'labels': 'l1',
- 'votes_down': 1,
- 'votes_up': 2,
- 'private': False,
- 'discussion_thread': {'posts': 'comments1'},
- },
- {
- 'reported_by': 'rb2',
- 'assigned_to': 'at2',
- 'ticket_num': 100,
- 'description': 'd2',
- 'created_date': '2013-09-03',
- 'mod_date': '2013-09-04',
- 'summary': 's2',
- 'custom_fields': 'cf2',
- 'status': 'st2',
- 'labels': 'l2',
- 'votes_down': 3,
- 'votes_up': 5,
- 'private': True,
- 'discussion_thread': {'posts': 'comments2'},
- },
- ],
- })
- anonymous = mock.Mock(_id=None, is_anonymous=lambda:True)
- reporter = mock.Mock(is_anonymous=lambda:False)
- author = mock.Mock(is_anonymous=lambda:False)
+ 'tracker_config': {
+ '_id': 'orig_id',
+ 'options': {
+ 'foo': 'bar',
+ },
+ },
+ 'open_status_names': 'open statuses',
+ 'closed_status_names': 'closed statuses',
+ 'custom_fields': 'fields',
+ 'saved_bins': 'bins',
+ 'tickets': [
+ {
+ 'reported_by': 'rb1',
+ 'assigned_to': 'at1',
+ 'ticket_num': 1,
+ 'description': 'd1',
+ 'created_date': '2013-09-01',
+ 'mod_date': '2013-09-02',
+ 'summary': 's1',
+ 'custom_fields': 'cf1',
+ 'status': 'st1',
+ 'labels': 'l1',
+ 'votes_down': 1,
+ 'votes_up': 2,
+ 'private': False,
+ 'discussion_thread': {'posts': 'comments1'},
+ },
+ {
+ 'reported_by': 'rb2',
+ 'assigned_to': 'at2',
+ 'ticket_num': 100,
+ 'description': 'd2',
+ 'created_date': '2013-09-03',
+ 'mod_date': '2013-09-04',
+ 'summary': 's2',
+ 'custom_fields': 'cf2',
+ 'status': 'st2',
+ 'labels': 'l2',
+ 'votes_down': 3,
+ 'votes_up': 5,
+ 'private': True,
+ 'discussion_thread': {'posts': 'comments2'},
+ },
+ ],
+ })
+ anonymous = mock.Mock(_id=None, is_anonymous=lambda: True)
+ reporter = mock.Mock(is_anonymous=lambda: False)
+ author = mock.Mock(is_anonymous=lambda: False)
importer.get_user = mock.Mock(side_effect=[
- reporter, author,
- anonymous, anonymous,
- ])
- importer.annotate = mock.Mock(side_effect=['ad1', 'aad1', 'ad2', 'aad2'])
+ reporter, author,
+ anonymous, anonymous,
+ ])
+ importer.annotate = mock.Mock(
+ side_effect=['ad1', 'aad1', 'ad2', 'aad2'])
importer.process_comments = mock.Mock()
importer.process_bins = mock.Mock()
project, user = mock.Mock(), mock.Mock()
app = project.install_app.return_value
app.config.options.mount_point = 'mount_point'
app.config.options.import_id = {
- 'source': 'Allura',
- 'app_config_id': 'orig_id',
- }
+ 'source': 'Allura',
+ 'app_config_id': 'orig_id',
+ }
app.config.options.get = lambda *a: getattr(app.config.options, *a)
app.url = 'foo'
tickets = TM.Ticket.side_effect = [mock.Mock(), mock.Mock()]
importer.import_tool(project, user,
- 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',
- open_status_names='open statuses',
- closed_status_names='closed statuses',
- import_id={
- 'source': 'Allura',
- 'app_config_id': 'orig_id',
- },
- foo='bar',
- )
+ project.install_app.assert_called_once_with(
+ 'tickets', 'mount_point', 'mount_label',
+ open_status_names='open statuses',
+ closed_status_names='closed statuses',
+ import_id={
+ 'source': 'Allura',
+ 'app_config_id': 'orig_id',
+ },
+ foo='bar',
+ )
self.assertEqual(importer.annotate.call_args_list, [
- mock.call('d1', author, 'at1', label=' owned'),
- mock.call('ad1', reporter, 'rb1', label=' created'),
- mock.call('d2', anonymous, 'at2', label=' owned'),
- mock.call('ad2', anonymous, 'rb2', label=' created'),
- ])
+ mock.call('d1', author, 'at1', label=' owned'),
+ mock.call('ad1', reporter, 'rb1', label=' created'),
+ mock.call('d2', anonymous, 'at2', label=' owned'),
+ mock.call('ad2', anonymous, 'rb2', label=' created'),
+ ])
self.assertEqual(TM.Ticket.call_args_list, [
- mock.call(
- app_config_id=app.config._id,
- import_id={
- 'source': 'Allura',
- 'app_config_id': 'orig_id',
- 'source_id': 1,
- },
- description='aad1',
- created_date=datetime(2013, 9, 1),
- mod_date=datetime(2013, 9, 2),
- ticket_num=1,
- summary='s1',
- custom_fields='cf1',
- status='st1',
- labels='l1',
- votes_down=1,
- votes_up=2,
- votes=1,
- assigned_to_id=author._id,
- ),
- mock.call(
- app_config_id=app.config._id,
- import_id={
- 'source': 'Allura',
- 'app_config_id': 'orig_id',
- 'source_id': 100,
- },
- description='aad2',
- created_date=datetime(2013, 9, 3),
- mod_date=datetime(2013, 9, 4),
- ticket_num=100,
- summary='s2',
- custom_fields='cf2',
- status='st2',
- labels='l2',
- votes_down=3,
- votes_up=5,
- votes=2,
- assigned_to_id=None,
- ),
- ])
+ mock.call(
+ app_config_id=app.config._id,
+ import_id={
+ 'source': 'Allura',
+ 'app_config_id': 'orig_id',
+ 'source_id': 1,
+ },
+ description='aad1',
+ created_date=datetime(2013, 9, 1),
+ mod_date=datetime(2013, 9, 2),
+ ticket_num=1,
+ summary='s1',
+ custom_fields='cf1',
+ status='st1',
+ labels='l1',
+ votes_down=1,
+ votes_up=2,
+ votes=1,
+ assigned_to_id=author._id,
+ ),
+ mock.call(
+ app_config_id=app.config._id,
+ import_id={
+ 'source': 'Allura',
+ 'app_config_id': 'orig_id',
+ 'source_id': 100,
+ },
+ description='aad2',
+ created_date=datetime(2013, 9, 3),
+ mod_date=datetime(2013, 9, 4),
+ ticket_num=100,
+ summary='s2',
+ custom_fields='cf2',
+ status='st2',
+ labels='l2',
+ votes_down=3,
+ votes_up=5,
+ votes=2,
+ assigned_to_id=None,
+ ),
+ ])
self.assertEqual(tickets[0].private, False)
self.assertEqual(tickets[1].private, True)
self.assertEqual(importer.process_comments.call_args_list, [
- mock.call(tickets[0], 'comments1'),
- mock.call(tickets[1], 'comments2'),
- ])
+ mock.call(tickets[0], 'comments1'),
+ mock.call(tickets[1], 'comments2'),
+ ])
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.custom_fields, 'fields')
importer.process_bins.assert_called_once_with(app, 'bins')
self.assertEqual(app.globals.last_ticket_num, 100)
M.AuditLog.log.assert_called_once_with(
- 'import tool mount_point from exported Allura JSON',
- project=project, user=user, url='foo')
+ 'import tool mount_point from exported Allura JSON',
+ project=project, user=user, url='foo')
g.post_event.assert_called_once_with('project_updated')
app.globals.invalidate_bin_counts.assert_called_once_with()
@@ -201,17 +204,19 @@ class TestTrackerImporter(TestCase):
project = mock.Mock()
user = mock.Mock()
tracker_json = {
- 'tracker_config': {'_id': 'orig_id', 'options': {}},
- 'open_status_names': 'os',
- 'closed_status_names': 'cs',
- }
+ 'tracker_config': {'_id': 'orig_id', 'options': {}},
+ 'open_status_names': 'os',
+ 'closed_status_names': 'cs',
+ }
importer = tracker.ForgeTrackerImporter()
importer._load_json = mock.Mock(return_value=tracker_json)
- 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)
@mock.patch.object(tracker, 'M')
def test_get_user(self, M):
@@ -235,7 +240,8 @@ class TestTrackerImporter(TestCase):
user.is_anonymous.return_value = False
self.assertEqual(importer.annotate('foo', user, 'bar'), 'foo')
user.is_anonymous.return_value = True
- self.assertEqual(importer.annotate('foo', user, 'bar'), '*Originally by:* bar\n\nfoo')
+ self.assertEqual(importer.annotate('foo', user, 'bar'),
+ '*Originally by:* bar\n\nfoo')
self.assertEqual(importer.annotate('foo', user, 'nobody'), 'foo')
self.assertEqual(importer.annotate('foo', user, None), 'foo')
@@ -251,41 +257,44 @@ class TestTrackerImporter(TestCase):
ama = add_post.return_value.add_multiple_attachments
File.side_effect = ['f1', 'f2', 'f3', 'f4']
comments = [
- {
- 'author': 'a1',
- 'text': 't1',
- 'timestamp': '2013-09-01',
- 'attachments': [{'url': 'u1'}, {'url': 'u2'}],
- },
- {
- 'author': 'a2',
- 'text': 't2',
- 'timestamp': '2013-09-02',
- 'attachments': [{'url': 'u3'}, {'url': 'u4'}],
- },
- ]
+ {
+ 'author': 'a1',
+ 'text': 't1',
+ 'timestamp': '2013-09-01',
+ 'attachments': [{'url': 'u1'}, {'url': 'u2'}],
+ },
+ {
+ 'author': 'a2',
+ 'text': 't2',
+ 'timestamp': '2013-09-02',
+ 'attachments': [{'url': 'u3'}, {'url': 'u4'}],
+ },
+ ]
importer.process_comments(ticket, comments)
- self.assertEqual(importer.get_user.call_args_list, [mock.call('a1'), mock.call('a2')])
+ self.assertEqual(importer.get_user.call_args_list,
+ [mock.call('a1'), mock.call('a2')])
self.assertEqual(importer.annotate.call_args_list, [
- mock.call('t1', author, 'a1'),
- mock.call('t2', author, 'a2'),
- ])
+ mock.call('t1', author, 'a1'),
+ mock.call('t2', author, 'a2'),
+ ])
self.assertEqual(add_post.call_args_list, [
- mock.call(text='at1', ignore_security=True, timestamp=datetime(2013, 9, 1)),
- mock.call(text='at2', ignore_security=True, timestamp=datetime(2013, 9, 2)),
- ])
+ mock.call(text='at1', ignore_security=True,
+ timestamp=datetime(2013, 9, 1)),
+ mock.call(text='at2', ignore_security=True,
+ timestamp=datetime(2013, 9, 2)),
+ ])
self.assertEqual(File.call_args_list, [
- mock.call('u1'),
- mock.call('u2'),
- mock.call('u3'),
- mock.call('u4'),
- ])
+ mock.call('u1'),
+ mock.call('u2'),
+ mock.call('u3'),
+ mock.call('u4'),
+ ])
self.assertEqual(ama.call_args_list, [
- mock.call(['f1', 'f2']),
- mock.call(['f3', 'f4']),
- ])
+ mock.call(['f1', 'f2']),
+ mock.call(['f3', 'f4']),
+ ])
@mock.patch.object(tracker, 'TM')
def test_process_bins(self, TM):
@@ -295,17 +304,19 @@ class TestTrackerImporter(TestCase):
importer.process_bins(app, [{'_id': 1, 'b': 1}, {'b': 2}])
TM.Bin.query.remove.assert_called_once_with({'app_config_id': 1})
self.assertEqual(TM.Bin.call_args_list, [
- mock.call(app_config_id=1, b=1),
- mock.call(app_config_id=1, b=2),
- ])
+ mock.call(app_config_id=1, b=1),
+ mock.call(app_config_id=1, b=2),
+ ])
class TestForgeTrackerImportController(TestController, TestCase):
+
def setUp(self):
"""Mount Allura importer on the Tracker admin controller"""
super(TestForgeTrackerImportController, self).setUp()
from forgetracker.tracker_main import TrackerAdminController
- TrackerAdminController._importer = tracker.ForgeTrackerImportController()
+ TrackerAdminController._importer = tracker.ForgeTrackerImportController(
+ )
@with_tracker
def test_index(self):
@@ -320,16 +331,18 @@ class TestForgeTrackerImportController(TestController, TestCase):
def test_create(self, import_tool, sui):
project = M.Project.query.get(shortname='test')
params = {
- 'tickets_json': webtest.Upload('tickets.json', '{"key": "val"}'),
- 'mount_label': 'mylabel',
- 'mount_point': 'mymount',
- }
+ 'tickets_json': webtest.Upload('tickets.json', '{"key": "val"}'),
+ '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/')
sui.assert_called_once_with(project, 'tickets.json', '{"key": "val"}')
- 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'mymount', import_tool.post.call_args[1]['mount_point'])
+ self.assertEqual(
+ u'mylabel', import_tool.post.call_args[1]['mount_label'])
@with_tracker
@mock.patch('forgeimporters.forge.tracker.save_importer_upload')
@@ -339,11 +352,11 @@ class TestForgeTrackerImportController(TestController, TestCase):
project.set_tool_data('ForgeTrackerImporter', pending=1)
ThreadLocalORMSession.flush_all()
params = {
- 'tickets_json': webtest.Upload('tickets.json', '{"key": "val"}'),
- 'mount_label': 'mylabel',
- 'mount_point': 'mymount',
- }
+ 'tickets_json': webtest.Upload('tickets.json', '{"key": "val"}'),
+ '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/github/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/github/__init__.py b/ForgeImporters/forgeimporters/tests/github/__init__.py
index 77505f1..144e298 100644
--- a/ForgeImporters/forgeimporters/tests/github/__init__.py
+++ b/ForgeImporters/forgeimporters/tests/github/__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/tests/github/functional/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/github/functional/__init__.py b/ForgeImporters/forgeimporters/tests/github/functional/__init__.py
index 77505f1..144e298 100644
--- a/ForgeImporters/forgeimporters/tests/github/functional/__init__.py
+++ b/ForgeImporters/forgeimporters/tests/github/functional/__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/tests/github/functional/test_github.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/github/functional/test_github.py b/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
index a9c5052..6577e4d 100644
--- a/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
+++ b/ForgeImporters/forgeimporters/tests/github/functional/test_github.py
@@ -23,6 +23,7 @@ from unittest import TestCase
from allura.tests import TestController
from allura import model as M
+
class TestGitHubImportController(TestController, TestCase):
def test_index(self):
@@ -34,11 +35,13 @@ class TestGitHubImportController(TestController, TestCase):
assert '<input name="tool_option" value="import_history" type="checkbox" checked="checked"/>' in r
def test_login_overlay(self):
- r = self.app.get('/p/import_project/github/', extra_environ=dict(username='*anonymous'))
+ r = self.app.get('/p/import_project/github/',
+ extra_environ=dict(username='*anonymous'))
self.assertIn('GitHub Project Importer', r)
self.assertIn('Login Required', r)
- r = self.app.post('/p/import_project/github/process', extra_environ=dict(username='*anonymous'), status=302)
+ r = self.app.post('/p/import_project/github/process',
+ extra_environ=dict(username='*anonymous'), status=302)
self.assertIn('/auth/', r.location)
@@ -65,7 +68,8 @@ class TestGitHubOAuth(TestController):
assert_equal(r.location, redirect)
session.__setitem__.assert_has_calls([
call('github.oauth.state', 'state'),
- call('github.oauth.redirect', 'http://localhost/p/import_project/github/')
+ call('github.oauth.redirect',
+ 'http://localhost/p/import_project/github/')
])
session.save.assert_called_once()
@@ -78,4 +82,5 @@ class TestGitHubOAuth(TestController):
assert_equal(user.get_tool_data('GitHubProjectImport', 'token'), 'abc')
r = self.app.get('/p/import_project/github/')
- assert_equal(r.status_int, 200) # token in user data, so oauth isn't triggered
+ # token in user data, so oauth isn't triggered
+ assert_equal(r.status_int, 200)
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeImporters/forgeimporters/tests/github/test_extractor.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/github/test_extractor.py b/ForgeImporters/forgeimporters/tests/github/test_extractor.py
index e6c96e3..a8ae0a5 100644
--- a/ForgeImporters/forgeimporters/tests/github/test_extractor.py
+++ b/ForgeImporters/forgeimporters/tests/github/test_extractor.py
@@ -93,11 +93,11 @@ class TestGitHubProjectExtractor(TestCase):
self.assertIsNone(self.extractor.get_next_page_url(''))
link = '<https://api.github.com/repositories/8560576/issues?state=open&page=2>; rel="next", <https://api.github.com/repositories/8560576/issues?state=open&page=10>; rel="last"'
self.assertEqual(self.extractor.get_next_page_url(link),
- 'https://api.github.com/repositories/8560576/issues?state=open&page=2')
+ 'https://api.github.com/repositories/8560576/issues?state=open&page=2')
link = '<https://api.github.com/repositories/8560576/issues?state=open&page=2>; rel="next"'
self.assertEqual(self.extractor.get_next_page_url(link),
- 'https://api.github.com/repositories/8560576/issues?state=open&page=2')
+ 'https://api.github.com/repositories/8560576/issues?state=open&page=2')
link = '<https://api.github.com/repositories/8560576/issues?state=open&page=1>; rel="prev"'
self.assertIsNone(self.extractor.get_next_page_url(link))
@@ -110,7 +110,7 @@ class TestGitHubProjectExtractor(TestCase):
def test_iter_issues(self):
issues = list(self.extractor.iter_issues())
- all_issues = zip((1,2), self.CLOSED_ISSUES_LIST)
+ all_issues = zip((1, 2), self.CLOSED_ISSUES_LIST)
all_issues += zip((3, 4, 5), self.OPENED_ISSUES_LIST)
all_issues += zip((6, 7, 8), self.OPENED_ISSUES_LIST_PAGE2)
self.assertEqual(issues, all_issues)
@@ -118,18 +118,21 @@ class TestGitHubProjectExtractor(TestCase):
def test_iter_comments(self):
mock_issue = {'comments_url': '/issues/1/comments'}
comments = list(self.extractor.iter_comments(mock_issue))
- self.assertEqual(comments, self.ISSUE_COMMENTS + self.ISSUE_COMMENTS_PAGE2)
+ self.assertEqual(comments, self.ISSUE_COMMENTS +
+ self.ISSUE_COMMENTS_PAGE2)
def test_iter_events(self):
mock_issue = {'events_url': '/issues/1/events'}
events = list(self.extractor.iter_events(mock_issue))
- self.assertEqual(events, self.ISSUE_EVENTS + self.ISSUE_EVENTS_PAGE2[:1])
+ self.assertEqual(events, self.ISSUE_EVENTS +
+ self.ISSUE_EVENTS_PAGE2[:1])
def test_has_wiki(self):
assert self.extractor.has_wiki()
def test_get_wiki_url(self):
- self.assertEqual(self.extractor.get_page_url('wiki_url'), 'https://github.com/test_project.wiki')
+ self.assertEqual(self.extractor.get_page_url('wiki_url'),
+ 'https://github.com/test_project.wiki')
@patch('forgeimporters.base.h.urlopen')
def test_urlopen(self, urlopen):
@@ -173,7 +176,9 @@ class TestGitHubProjectExtractor(TestCase):
'Rate limit exceeded (10 requests/hour). '
'Sleeping until 2013-10-25 09:32:02 UTC'
)
- sleep.reset_mock(); urlopen.reset_mock(); log.warn.reset_mock()
+ sleep.reset_mock()
+ urlopen.reset_mock()
+ log.warn.reset_mock()
response_ok = StringIO('{}')
response_ok.info = lambda: {}
urlopen.side_effect = [response_ok]
@@ -192,6 +197,7 @@ class TestGitHubProjectExtractor(TestCase):
'X-RateLimit-Remaining': '0',
'X-RateLimit-Reset': '1382693522',
}
+
def urlopen_side_effect(*a, **kw):
mock_resp = StringIO('{}')
mock_resp.info = lambda: {}
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeImporters/forgeimporters/tests/github/test_tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/github/test_tracker.py b/ForgeImporters/forgeimporters/tests/github/test_tracker.py
index b32df0a..e02ac5a 100644
--- a/ForgeImporters/forgeimporters/tests/github/test_tracker.py
+++ b/ForgeImporters/forgeimporters/tests/github/test_tracker.py
@@ -25,6 +25,7 @@ from forgeimporters.github.utils import GitHubMarkdownConverter
class TestTrackerImporter(TestCase):
+
@mock.patch.object(tracker, 'g')
@mock.patch.object(tracker, 'c')
@mock.patch.object(tracker, 'ThreadLocalORMSession')
@@ -37,7 +38,7 @@ class TestTrackerImporter(TestCase):
importer.process_fields = mock.Mock()
importer.process_milestones = mock.Mock()
importer.process_comments = mock.Mock()
- importer.postprocess_milestones= mock.Mock()
+ importer.postprocess_milestones = mock.Mock()
project, user = mock.Mock(), mock.Mock()
app = project.install_app.return_value
app.config.options.mount_point = 'mount_point'
@@ -45,25 +46,26 @@ class TestTrackerImporter(TestCase):
gpe.iter_issues.return_value = [(50, mock.Mock()), (100, mock.Mock())]
importer.import_tool(project, user, project_name='project_name',
- mount_point='mount_point', mount_label='mount_label', user_name='me')
+ mount_point='mount_point', mount_label='mount_label', user_name='me')
- project.install_app.assert_called_once_with('tickets', 'mount_point', 'mount_label',
- EnableVoting=False,
- open_status_names='open',
- closed_status_names='closed',
- import_id={
- 'source': 'GitHub',
- 'project_name': 'me/project_name',
- }
- )
+ project.install_app.assert_called_once_with(
+ 'tickets', 'mount_point', 'mount_label',
+ EnableVoting=False,
+ open_status_names='open',
+ closed_status_names='closed',
+ import_id={
+ 'source': 'GitHub',
+ 'project_name': 'me/project_name',
+ }
+ )
gpe.iter_issues.assert_called_once()
self.assertEqual(tlos.flush_all.call_args_list, [
- mock.call(),
- mock.call(),
- ])
+ mock.call(),
+ mock.call(),
+ ])
M.AuditLog.log.assert_called_once_with(
- 'import tool mount_point from me/project_name on GitHub',
- project=project, user=user, url='foo')
+ 'import tool mount_point from me/project_name on GitHub',
+ project=project, user=user, url='foo')
g.post_event.assert_called_once_with('project_updated')
app.globals.invalidate_bin_counts.assert_called_once_with()
@@ -80,21 +82,23 @@ class TestTrackerImporter(TestCase):
'labels': [{'name': 'first'}, {'name': 'second'}],
}
importer = tracker.GitHubTrackerImporter()
- importer.github_markdown_converter = GitHubMarkdownConverter('user', 'project')
+ importer.github_markdown_converter = GitHubMarkdownConverter(
+ 'user', 'project')
extractor = mock.Mock()
extractor.urlopen().read.return_value = 'data'
with mock.patch.object(tracker, 'datetime') as dt:
- dt.strptime.side_effect = lambda s,f: s
+ dt.strptime.side_effect = lambda s, f: s
importer.process_fields(extractor, ticket, issue)
self.assertEqual(ticket.summary, 'title')
- self.assertEqual(ticket.description, '*Originally created by:* [creator](https://github.com/creator)\n*Originally owned by:* [owner](https://github.com/owner)\n\nhello')
+ self.assertEqual(ticket.description,
+ '*Originally created by:* [creator](https://github.com/creator)\n*Originally owned by:* [owner](https://github.com/owner)\n\nhello')
self.assertEqual(ticket.status, 'New')
self.assertEqual(ticket.created_date, 'created_at')
self.assertEqual(ticket.mod_date, 'updated_at')
self.assertEqual(dt.strptime.call_args_list, [
- mock.call('created_at', '%Y-%m-%dT%H:%M:%SZ'),
- mock.call('updated_at', '%Y-%m-%dT%H:%M:%SZ'),
- ])
+ mock.call('created_at', '%Y-%m-%dT%H:%M:%SZ'),
+ mock.call('updated_at', '%Y-%m-%dT%H:%M:%SZ'),
+ ])
self.assertEqual(ticket.labels, ['first', 'second'])
@mock.patch.object(tracker, 'c')
@@ -102,40 +106,45 @@ class TestTrackerImporter(TestCase):
importer = tracker.GitHubTrackerImporter()
importer.open_milestones = set([
('first', datetime(day=23, month=4, year=2015)),
- ('second',datetime(day=25, month=4, year=2015))
+ ('second', datetime(day=25, month=4, year=2015))
])
milestones = importer.postprocess_milestones()
self.assertItemsEqual(milestones, [
- {
- 'name': '_milestone',
- 'type': 'milestone',
- 'label': 'Milestone',
- 'milestones': [
- {'name': 'first', 'due_date': u'2015-04-23', 'complete': False},
- {'name': 'second', 'due_date': u'2015-04-25', 'complete': False},
- ],
- },
- ])
+ {
+ 'name': '_milestone',
+ 'type': 'milestone',
+ 'label': 'Milestone',
+ 'milestones': [
+ {'name': 'first', 'due_date':
+ u'2015-04-23', 'complete': False},
+ {'name': 'second', 'due_date':
+ u'2015-04-25', 'complete': False},
+ ],
+ },
+ ])
def test_get_attachments(self):
importer = tracker.GitHubTrackerImporter()
extractor = mock.Mock()
extractor.urlopen().read.return_value = 'data'
body = 'hello\n' \
- '![cdbpzjc5ex4](https://f.cloud.github.com/assets/979771/1027411/a393ab5e-0e70-11e3-8a38-b93a3df904cf.jpg)\r\n' \
- '![screensh0t](http://f.cl.ly/items/13453x43053r2G0d3x0v/Screen%20Shot%202012-04-28%20at%2010.48.17%20AM.png)'
+ '![cdbpzjc5ex4](https://f.cloud.github.com/assets/979771/1027411/a393ab5e-0e70-11e3-8a38-b93a3df904cf.jpg)\r\n' \
+ '![screensh0t](http://f.cl.ly/items/13453x43053r2G0d3x0v/Screen%20Shot%202012-04-28%20at%2010.48.17%20AM.png)'
new_body, attachments = importer._get_attachments(extractor, body)
self.assertEqual(new_body, 'hello\n')
self.assertEqual(len(attachments), 2)
- self.assertEqual(attachments[0].url, 'https://f.cloud.github.com/assets/979771/1027411/a393ab5e-0e70-11e3-8a38-b93a3df904cf.jpg')
- self.assertEqual(attachments[1].url, 'http://f.cl.ly/items/13453x43053r2G0d3x0v/Screen%20Shot%202012-04-28%20at%2010.48.17%20AM.png')
+ self.assertEqual(
+ attachments[0].url, 'https://f.cloud.github.com/assets/979771/1027411/a393ab5e-0e70-11e3-8a38-b93a3df904cf.jpg')
+ self.assertEqual(
+ attachments[1].url, 'http://f.cl.ly/items/13453x43053r2G0d3x0v/Screen%20Shot%202012-04-28%20at%2010.48.17%20AM.png')
self.assertEqual(attachments[0].file.read(), 'data')
self.assertEqual(attachments[1].file.read(), 'data')
def test_get_attachments_404(self):
importer = tracker.GitHubTrackerImporter()
extractor = mock.Mock()
- extractor.urlopen.side_effect = HTTPError('url', 404, 'mock', None, None)
+ extractor.urlopen.side_effect = HTTPError(
+ 'url', 404, 'mock', None, None)
body = 'hello\n' \
'![cdbpzjc5ex4](https://f.cloud.github.com/assets/979771/1027411/a393ab5e-0e70-11e3-8a38-b93a3df904cf.jpg)\r\n'
new_body, attachments = importer._get_attachments(extractor, body)
@@ -147,20 +156,21 @@ class TestTrackerImporter(TestCase):
extractor = mock.Mock()
issue = {'comments_url': '/comments'}
extractor.iter_comments.return_value = [
- {
- 'body': 'hello',
- 'created_at': '2013-08-26T16:57:53Z',
- 'user': {'login': 'me'},
- }
- ]
+ {
+ 'body': 'hello',
+ 'created_at': '2013-08-26T16:57:53Z',
+ 'user': {'login': 'me'},
+ }
+ ]
importer = tracker.GitHubTrackerImporter()
- importer.github_markdown_converter = GitHubMarkdownConverter('user', 'project')
+ importer.github_markdown_converter = GitHubMarkdownConverter(
+ 'user', 'project')
importer.process_comments(extractor, ticket, issue)
self.assertEqual(ticket.discussion_thread.add_post.call_args_list[0], mock.call(
- text='*Originally posted by:* [me](https://github.com/me)\n\nhello',
- timestamp=datetime(2013, 8, 26, 16, 57, 53),
- ignore_security=True,
- ))
+ text='*Originally posted by:* [me](https://github.com/me)\n\nhello',
+ timestamp=datetime(2013, 8, 26, 16, 57, 53),
+ ignore_security=True,
+ ))
def test_process_events(self):
ticket = mock.Mock()
@@ -229,11 +239,12 @@ Hello
'labels': [{'name': 'first'}, {'name': 'second'}],
}
importer = tracker.GitHubTrackerImporter()
- importer.github_markdown_converter = GitHubMarkdownConverter('user', 'project')
+ importer.github_markdown_converter = GitHubMarkdownConverter(
+ 'user', 'project')
extractor = mock.Mock()
extractor.urlopen().read.return_value = 'data'
with mock.patch.object(tracker, 'datetime') as dt:
- dt.strptime.side_effect = lambda s,f: s
+ dt.strptime.side_effect = lambda s, f: s
importer.process_fields(extractor, ticket, issue)
self.assertEqual(ticket.description.strip(), body_converted.strip())
@@ -256,17 +267,18 @@ Hello
issue = {'comments_url': '/comments'}
extractor.iter_comments.return_value = [
- {
- 'body': body,
- 'created_at': '2013-08-26T16:57:53Z',
- 'user': {'login': 'me'},
- }
- ]
+ {
+ 'body': body,
+ 'created_at': '2013-08-26T16:57:53Z',
+ 'user': {'login': 'me'},
+ }
+ ]
importer = tracker.GitHubTrackerImporter()
- importer.github_markdown_converter = GitHubMarkdownConverter('user', 'project')
+ importer.github_markdown_converter = GitHubMarkdownConverter(
+ 'user', 'project')
importer.process_comments(extractor, ticket, issue)
self.assertEqual(ticket.discussion_thread.add_post.call_args_list[0], mock.call(
- text=body_converted,
- timestamp=datetime(2013, 8, 26, 16, 57, 53),
- ignore_security=True,
- ))
+ text=body_converted,
+ timestamp=datetime(2013, 8, 26, 16, 57, 53),
+ ignore_security=True,
+ ))
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeImporters/forgeimporters/tests/google/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/google/__init__.py b/ForgeImporters/forgeimporters/tests/google/__init__.py
index 77505f1..144e298 100644
--- a/ForgeImporters/forgeimporters/tests/google/__init__.py
+++ b/ForgeImporters/forgeimporters/tests/google/__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/tests/google/functional/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/google/functional/__init__.py b/ForgeImporters/forgeimporters/tests/google/functional/__init__.py
index 77505f1..144e298 100644
--- a/ForgeImporters/forgeimporters/tests/google/functional/__init__.py
+++ b/ForgeImporters/forgeimporters/tests/google/functional/__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/tests/google/functional/test_tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/google/functional/test_tracker.py b/ForgeImporters/forgeimporters/tests/google/functional/test_tracker.py
index c22f7d0..e689971 100644
--- a/ForgeImporters/forgeimporters/tests/google/functional/test_tracker.py
+++ b/ForgeImporters/forgeimporters/tests/google/functional/test_tracker.py
@@ -38,10 +38,12 @@ from forgeimporters.google import tracker
class TestGCTrackerImporter(TestCase):
+
def _make_extractor(self, html):
with mock.patch.object(base.h, 'urlopen') as urlopen:
urlopen.return_value = ''
- extractor = google.GoogleCodeProjectExtractor('allura-google-importer', 'project_info')
+ extractor = google.GoogleCodeProjectExtractor(
+ 'allura-google-importer', 'project_info')
extractor.page = BeautifulSoup(html)
extractor.url = "http://test/issue/?id=1"
return extractor
@@ -49,13 +51,16 @@ class TestGCTrackerImporter(TestCase):
def _make_ticket(self, issue, issue_id=1):
self.assertIsNone(self.project.app_instance('test-issue'))
with mock.patch.object(base.h, 'urlopen') as urlopen,\
- mock.patch.object(google.tracker, 'GoogleCodeProjectExtractor') as GPE,\
- mock.patch.object(google.tracker.M, 'AuditLog') as AL,\
- mock.patch('forgetracker.tasks.update_bin_counts') as ubc:
- urlopen.side_effect = lambda req, **kw: mock.Mock(read=req.get_full_url, info=lambda:{'content-type': 'text/plain'})
+ mock.patch.object(google.tracker, 'GoogleCodeProjectExtractor') as GPE,\
+ mock.patch.object(google.tracker.M, 'AuditLog') as AL,\
+ mock.patch('forgetracker.tasks.update_bin_counts') as ubc:
+ urlopen.side_effect = lambda req, **kw: mock.Mock(
+ read=req.get_full_url,
+ info=lambda: {'content-type': 'text/plain'})
GPE.iter_issues.return_value = [(issue_id, issue)]
gti = google.tracker.GoogleCodeTrackerImporter()
- gti.import_tool(self.project, self.user, 'test-issue-project', mount_point='test-issue')
+ gti.import_tool(self.project, self.user,
+ 'test-issue-project', mount_point='test-issue')
c.app = self.project.app_instance('test-issue')
query = TM.Ticket.query.find({'app_config_id': c.app.config._id})
self.assertEqual(query.count(), 1)
@@ -65,37 +70,42 @@ class TestGCTrackerImporter(TestCase):
def setUp(self, *a, **kw):
super(TestGCTrackerImporter, self).setUp(*a, **kw)
setup_basic_test()
- self.empty_issue = self._make_extractor(open(pkg_resources.resource_filename('forgeimporters', 'tests/data/google/empty-issue.html')).read())
- self.test_issue = self._make_extractor(open(pkg_resources.resource_filename('forgeimporters', 'tests/data/google/test-issue.html')).read())
+ self.empty_issue = self._make_extractor(
+ open(pkg_resources.resource_filename('forgeimporters', 'tests/data/google/empty-issue.html')).read())
+ self.test_issue = self._make_extractor(
+ open(pkg_resources.resource_filename('forgeimporters', 'tests/data/google/test-issue.html')).read())
c.project = self.project = M.Project.query.get(shortname='test')
c.user = self.user = M.User.query.get(username='test-admin')
def test_empty_issue(self):
ticket = self._make_ticket(self.empty_issue)
self.assertEqual(ticket.summary, 'Empty Issue')
- self.assertEqual(ticket.description, '*Originally created by:* john...@gmail.com\n\nEmpty')
+ self.assertEqual(ticket.description,
+ '*Originally created by:* john...@gmail.com\n\nEmpty')
self.assertEqual(ticket.status, '')
self.assertEqual(ticket.milestone, '')
self.assertEqual(ticket.custom_fields, {})
assert c.app.config.options.get('EnableVoting')
- open_bin = TM.Bin.query.get(summary='Open Tickets', app_config_id=c.app.config._id)
+ open_bin = TM.Bin.query.get(
+ summary='Open Tickets', app_config_id=c.app.config._id)
self.assertItemsEqual(open_bin.terms.split(' && '), [
- '!status:Fixed',
- '!status:Verified',
- '!status:Invalid',
- '!status:Duplicate',
- '!status:WontFix',
- '!status:Done',
- ])
- closed_bin = TM.Bin.query.get(summary='Closed Tickets', app_config_id=c.app.config._id)
+ '!status:Fixed',
+ '!status:Verified',
+ '!status:Invalid',
+ '!status:Duplicate',
+ '!status:WontFix',
+ '!status:Done',
+ ])
+ closed_bin = TM.Bin.query.get(
+ summary='Closed Tickets', app_config_id=c.app.config._id)
self.assertItemsEqual(closed_bin.terms.split(' or '), [
- 'status:Fixed',
- 'status:Verified',
- 'status:Invalid',
- 'status:Duplicate',
- 'status:WontFix',
- 'status:Done',
- ])
+ 'status:Fixed',
+ 'status:Verified',
+ 'status:Invalid',
+ 'status:Duplicate',
+ 'status:WontFix',
+ 'status:Done',
+ ])
@without_module('html2text')
def test_issue_basic_fields(self):
@@ -105,40 +115,40 @@ class TestGCTrackerImporter(TestCase):
self.assertIsNone(ticket.assigned_to_id)
self.assertEqual(ticket.summary, 'Test "Issue"')
assert_equal(ticket.description,
- '*Originally created by:* [john...@gmail.com](http://code.google.com/u/101557263855536553789/)\n'
- '*Originally owned by:* [john...@gmail.com](http://code.google.com/u/101557263855536553789/)\n'
- '\n'
- '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'
- )
+ '*Originally created by:* [john...@gmail.com](http://code.google.com/u/101557263855536553789/)\n'
+ '*Originally owned by:* [john...@gmail.com](http://code.google.com/u/101557263855536553789/)\n'
+ '\n'
+ '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(ticket.status, 'Started')
self.assertEqual(ticket.created_date, datetime(2013, 8, 8, 15, 33, 52))
self.assertEqual(ticket.mod_date, datetime(2013, 8, 8, 15, 36, 57))
self.assertEqual(ticket.custom_fields, {
- '_priority': 'Medium',
- '_opsys': 'All, OSX, Windows',
- '_component': 'Logic',
- '_type': 'Defect',
- '_milestone': 'Release1.0'
- })
+ '_priority': 'Medium',
+ '_opsys': 'All, OSX, Windows',
+ '_component': 'Logic',
+ '_type': 'Defect',
+ '_milestone': 'Release1.0'
+ })
self.assertEqual(ticket.labels, ['Performance', 'Security'])
self.assertEqual(ticket.votes_up, 1)
self.assertEqual(ticket.votes, 1)
@@ -146,55 +156,57 @@ class TestGCTrackerImporter(TestCase):
def test_import_id(self):
ticket = self._make_ticket(self.test_issue, issue_id=6)
self.assertEqual(ticket.app.config.options.import_id, {
- 'source': 'Google Code',
- 'project_name': 'test-issue-project',
- })
+ 'source': 'Google Code',
+ 'project_name': 'test-issue-project',
+ })
self.assertEqual(ticket.ticket_num, 6)
self.assertEqual(ticket.import_id, {
- 'source': 'Google Code',
- 'project_name': 'test-issue-project',
- 'source_id': 6,
- })
+ 'source': 'Google Code',
+ 'project_name': 'test-issue-project',
+ 'source_id': 6,
+ })
@skipif(module_not_available('html2text'))
def test_html2text_escaping(self):
ticket = self._make_ticket(self.test_issue)
assert_equal(ticket.description,
- '*Originally created by:* [john...@gmail.com](http://code.google.com/u/101557263855536553789/)\n'
- '*Originally owned by:* [john...@gmail.com](http://code.google.com/u/101557263855536553789/)\n'
- '\n'
- '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'
- )
+ '*Originally created by:* [john...@gmail.com](http://code.google.com/u/101557263855536553789/)\n'
+ '*Originally owned by:* [john...@gmail.com](http://code.google.com/u/101557263855536553789/)\n'
+ '\n'
+ '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'
+ )
def _assert_attachments(self, actual, *expected):
self.assertEqual(len(actual), len(expected))
- atts = set((a.filename, a.content_type, a.rfile().read()) for a in actual)
+ atts = set((a.filename, a.content_type, a.rfile().read())
+ for a in actual)
self.assertEqual(atts, set(expected))
def test_attachements(self):
ticket = self._make_ticket(self.test_issue)
self._assert_attachments(ticket.attachments,
- ('at1.txt', 'text/plain', 'http://allura-google-importer.googlecode.com/issues/attachment?aid=70000000&name=at1.txt&token=3REU1M3JUUMt0rJUg7ldcELt6LA%3A1376059941255'),
- )
+ ('at1.txt', 'text/plain',
+ 'http://allura-google-importer.googlecode.com/issues/attachment?aid=70000000&name=at1.txt&token=3REU1M3JUUMt0rJUg7ldcELt6LA%3A1376059941255'),
+ )
@without_module('html2text')
def test_comments(self):
@@ -202,96 +214,102 @@ class TestGCTrackerImporter(TestCase):
ticket = self._make_ticket(self.test_issue)
actual_comments = ticket.discussion_thread.find_posts()
expected_comments = [
- {
- 'timestamp': datetime(2013, 8, 8, 15, 35, 15),
- 'text': (
- '*Originally posted by:* [john...@gmail.com](http://code.google.com/u/101557263855536553789/)\n'
- '\n'
- 'Test \\*comment\\* is a comment\n'
- '\n'
- '**Labels:** -OpSys-Linux OpSys-Windows\n'
- '**Status:** Started'
- ),
- 'attachments': [
- ('at2.txt', 'text/plain', 'http://allura-google-importer.googlecode.com/issues/attachment?aid=60001000&name=at2.txt&token=JOSo4duwaN2FCKZrwYOQ-nx9r7U%3A1376001446667'),
- ],
- },
- {
- 'timestamp': datetime(2013, 8, 8, 15, 35, 34),
- 'text': (
- '*Originally posted by:* [john...@gmail.com](http://code.google.com/u/101557263855536553789/)\n'
- '\n'
- 'Another comment with references: [issue 2](#2), [r1]\n\n'
- ),
- },
- {
- 'timestamp': datetime(2013, 8, 8, 15, 36, 39),
- 'text': (
- '*Originally posted by:* [john...@gmail.com](http://code.google.com/u/101557263855536553789/)\n'
- '\n'
- 'Last comment\n\n'
- ),
- 'attachments': [
- ('at4.txt', 'text/plain', 'http://allura-google-importer.googlecode.com/issues/attachment?aid=60003000&name=at4.txt&token=6Ny2zYHmV6b82dqxyoiH6HUYoC4%3A1376001446667'),
- ('at1.txt', 'text/plain', 'http://allura-google-importer.googlecode.com/issues/attachment?aid=60003001&name=at1.txt&token=NS8aMvWsKzTAPuY2kniJG5aLzPg%3A1376001446667'),
- ],
- },
- {
- 'timestamp': datetime(2013, 8, 8, 15, 36, 57),
- 'text': (
- '*Originally posted by:* [john...@gmail.com](http://code.google.com/u/101557263855536553789/)\n'
- '\n'
- '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)\\)\n'
- '\n'
- '**Labels:** OpSys-OSX'
- ),
- },
- ]
+ {
+ 'timestamp': datetime(2013, 8, 8, 15, 35, 15),
+ 'text': (
+ '*Originally posted by:* [john...@gmail.com](http://code.google.com/u/101557263855536553789/)\n'
+ '\n'
+ 'Test \\*comment\\* is a comment\n'
+ '\n'
+ '**Labels:** -OpSys-Linux OpSys-Windows\n'
+ '**Status:** Started'
+ ),
+ 'attachments': [
+ ('at2.txt', 'text/plain',
+ 'http://allura-google-importer.googlecode.com/issues/attachment?aid=60001000&name=at2.txt&token=JOSo4duwaN2FCKZrwYOQ-nx9r7U%3A1376001446667'),
+ ],
+ },
+ {
+ 'timestamp': datetime(2013, 8, 8, 15, 35, 34),
+ 'text': (
+ '*Originally posted by:* [john...@gmail.com](http://code.google.com/u/101557263855536553789/)\n'
+ '\n'
+ 'Another comment with references: [issue 2](#2), [r1]\n\n'
+ ),
+ },
+ {
+ 'timestamp': datetime(2013, 8, 8, 15, 36, 39),
+ 'text': (
+ '*Originally posted by:* [john...@gmail.com](http://code.google.com/u/101557263855536553789/)\n'
+ '\n'
+ 'Last comment\n\n'
+ ),
+ 'attachments': [
+ ('at4.txt', 'text/plain',
+ 'http://allura-google-importer.googlecode.com/issues/attachment?aid=60003000&name=at4.txt&token=6Ny2zYHmV6b82dqxyoiH6HUYoC4%3A1376001446667'),
+ ('at1.txt', 'text/plain',
+ 'http://allura-google-importer.googlecode.com/issues/attachment?aid=60003001&name=at1.txt&token=NS8aMvWsKzTAPuY2kniJG5aLzPg%3A1376001446667'),
+ ],
+ },
+ {
+ 'timestamp': datetime(2013, 8, 8, 15, 36, 57),
+ 'text': (
+ '*Originally posted by:* [john...@gmail.com](http://code.google.com/u/101557263855536553789/)\n'
+ '\n'
+ '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)\\)\n'
+ '\n'
+ '**Labels:** OpSys-OSX'
+ ),
+ },
+ ]
self.assertEqual(len(actual_comments), len(expected_comments))
for actual, expected in zip(actual_comments, expected_comments):
self.assertEqual(actual.author(), anon)
self.assertEqual(actual.timestamp, expected['timestamp'])
self.assertEqual(actual.text, expected['text'])
if 'attachments' in expected:
- self._assert_attachments(actual.attachments, *expected['attachments'])
+ self._assert_attachments(
+ actual.attachments, *expected['attachments'])
def test_globals(self):
globals = self._make_ticket(self.test_issue, issue_id=6).globals
self.assertEqual(globals.open_status_names, 'New Accepted Started')
- self.assertEqual(globals.closed_status_names, 'Fixed Verified Invalid Duplicate WontFix Done')
+ self.assertEqual(globals.closed_status_names,
+ 'Fixed Verified Invalid Duplicate WontFix Done')
self.assertEqual(globals.last_ticket_num, 6)
self.assertItemsEqual(globals.custom_fields, [
- {
- 'label': 'Milestone',
- 'name': '_milestone',
- 'type': 'milestone',
- 'options': '',
- 'milestones': [
- {'name': 'Release1.0', 'due_date': None, 'complete': False},
- ],
- },
- {
- 'label': 'Type',
- 'name': '_type',
- 'type': 'select',
- 'options': 'Defect',
- },
- {
- 'label': 'Priority',
- 'name': '_priority',
- 'type': 'select',
- 'options': 'Medium',
- },
- {
- 'label': 'OpSys',
- 'name': '_opsys',
- 'type': 'string',
- 'options': '',
- },
- {
- 'label': 'Component',
- 'name': '_component',
- 'type': 'string',
- 'options': '',
- },
- ])
+ {
+ 'label': 'Milestone',
+ 'name': '_milestone',
+ 'type': 'milestone',
+ 'options': '',
+ 'milestones': [
+ {'name': 'Release1.0', 'due_date':
+ None, 'complete': False},
+ ],
+ },
+ {
+ 'label': 'Type',
+ 'name': '_type',
+ 'type': 'select',
+ 'options': 'Defect',
+ },
+ {
+ 'label': 'Priority',
+ 'name': '_priority',
+ 'type': 'select',
+ 'options': 'Medium',
+ },
+ {
+ 'label': 'OpSys',
+ 'name': '_opsys',
+ 'type': 'string',
+ 'options': '',
+ },
+ {
+ 'label': 'Component',
+ 'name': '_component',
+ 'type': 'string',
+ 'options': '',
+ },
+ ])