incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [16/16] git commit: [#6464] Handle non-linked Google users in tracker import
Date Fri, 16 Aug 2013 22:21:52 GMT
[#6464] Handle non-linked Google users in tracker import

Signed-off-by: Cory Johns <cjohns@slashdotmedia.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/8facbc5e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/8facbc5e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/8facbc5e

Branch: refs/heads/cj/6464
Commit: 8facbc5e2ada555bca0a92b0b322fcb05c6fb23d
Parents: 3c9bc57
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Fri Aug 16 20:02:17 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Fri Aug 16 22:21:00 2013 +0000

----------------------------------------------------------------------
 .../forgeimporters/google/__init__.py           | 19 +++++++++----
 ForgeImporters/forgeimporters/google/tracker.py |  4 +--
 .../tests/data/google/empty-issue.html          |  2 +-
 .../tests/google/functional/test_tracker.py     |  2 +-
 .../tests/google/test_extractor.py              | 29 +++++++++++++++-----
 .../forgeimporters/tests/google/test_tracker.py | 11 ++------
 6 files changed, 43 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/8facbc5e/ForgeImporters/forgeimporters/google/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/google/__init__.py b/ForgeImporters/forgeimporters/google/__init__.py
index 7234dc8..22be7c2 100644
--- a/ForgeImporters/forgeimporters/google/__init__.py
+++ b/ForgeImporters/forgeimporters/google/__init__.py
@@ -198,7 +198,7 @@ class GoogleCodeProjectExtractor(ProjectExtractor):
             return self.get_issue_created_date()
 
     def get_issue_creator(self):
-        a = self.page.find(id='hc0').find('a', 'userlink')
+        a = self.page.find(id='hc0').find(True, 'userlink')
         return UserLink(a)
 
     def get_issue_status(self):
@@ -209,7 +209,7 @@ class GoogleCodeProjectExtractor(ProjectExtractor):
             return ''
 
     def get_issue_owner(self):
-        tag = self.page.find(id='issuemeta').find('th', text=re.compile('Owner:')).findNext().a
+        tag = self.page.find(id='issuemeta').find('th', text=re.compile('Owner:')).findNext().find(True,
'userlink')
         if tag:
             return UserLink(tag)
         else:
@@ -233,11 +233,20 @@ class GoogleCodeProjectExtractor(ProjectExtractor):
 class UserLink(object):
     def __init__(self, tag):
         self.name = tag.string.strip()
-        self.link = urljoin(GoogleCodeProjectExtractor.BASE_URL, tag.get('href'))
+        if 'href' in tag.attrMap:
+            self.url = urljoin(GoogleCodeProjectExtractor.BASE_URL, tag.attrMap['href'])
+        else:
+            self.url = None
+
+    def __str__(self):
+        if self.url:
+            return '[{name}]({url})'.format(name = self.name, url = self.url)
+        else:
+            return self.name
 
 class Comment(object):
     def __init__(self, tag):
-        self.author = UserLink(tag.find('span', 'author').find('a', 'userlink'))
+        self.author = UserLink(tag.find('span', 'author').find(True, 'userlink'))
         self.created_date = tag.find('span', 'date').get('title')
         self.body = _as_text(tag.find('pre')).strip()
         self._get_updates(tag)
@@ -262,7 +271,7 @@ class Comment(object):
     @property
     def annotated_text(self):
         text = (
-                u'*Originally posted by:* [{author.name}]({author.link})\n'
+                u'*Originally posted by:* {author}\n'
                 u'\n'
                 u'{body}\n'
                 u'\n'

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/8facbc5e/ForgeImporters/forgeimporters/google/tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/google/tracker.py b/ForgeImporters/forgeimporters/google/tracker.py
index 3257c5a..3d9843c 100644
--- a/ForgeImporters/forgeimporters/google/tracker.py
+++ b/ForgeImporters/forgeimporters/google/tracker.py
@@ -86,11 +86,11 @@ class GoogleCodeTrackerImporter(ToolImporter):
         ticket.mod_date = datetime.strptime(issue.get_issue_mod_date(), '%c')
         owner = issue.get_issue_owner()
         if owner:
-            owner_line = '*Originally owned by:* [{owner.name}]({owner.link})\n'.format(owner=owner)
+            owner_line = '*Originally owned by:* {owner}\n'.format(owner=owner)
         else:
             owner_line = ''
         ticket.description = (
-                u'*Originally created by:* [{creator.name}]({creator.link})\n'
+                u'*Originally created by:* {creator}\n'
                 u'{owner}'
                 u'\n'
                 u'{body}').format(

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/8facbc5e/ForgeImporters/forgeimporters/tests/data/google/empty-issue.html
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/data/google/empty-issue.html b/ForgeImporters/forgeimporters/tests/data/google/empty-issue.html
index a8fb1d5..b2eef20 100644
--- a/ForgeImporters/forgeimporters/tests/data/google/empty-issue.html
+++ b/ForgeImporters/forgeimporters/tests/data/google/empty-issue.html
@@ -240,7 +240,7 @@ contributes to open source, such as <a href="http://www.firefox.com">Firefox</a>
  Reported by
 
 
- <a class="userlink" href="/u/101557263855536553789/">john...@gmail.com</a>,
+ <span class="userlink">john...@gmail.com</span>,
  <span class="date" title="Thu Aug  8 14:56:23 2013">Today (15 minutes ago)</span>
 </div>
 <pre>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/8facbc5e/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 62c4453..80a8747 100644
--- a/ForgeImporters/forgeimporters/tests/google/functional/test_tracker.py
+++ b/ForgeImporters/forgeimporters/tests/google/functional/test_tracker.py
@@ -70,7 +70,7 @@ class TestGCTrackerImporter(TestCase):
     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](http://code.google.com/u/101557263855536553789/)\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, {})

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/8facbc5e/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 7a485d6..4157c98 100644
--- a/ForgeImporters/forgeimporters/tests/google/test_extractor.py
+++ b/ForgeImporters/forgeimporters/tests/google/test_extractor.py
@@ -152,9 +152,9 @@ class TestGoogleCodeProjectExtractor(TestCase):
         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().link, '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().link, '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.assertEqual(gpe.get_issue_summary(), 'Test Issue')
         self.assertEqual(gpe.get_issue_description(),
@@ -217,7 +217,7 @@ class TestGoogleCodeProjectExtractor(TestCase):
         expected = [
                 {
                     'author.name': 'john...@gmail.com',
-                    'author.link': 'http://code.google.com/u/101557263855536553789/',
+                    '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'},
@@ -225,7 +225,7 @@ class TestGoogleCodeProjectExtractor(TestCase):
                 },
                 {
                     'author.name': 'john...@gmail.com',
-                    'author.link': 'http://code.google.com/u/101557263855536553789/',
+                    'author.url': 'http://code.google.com/u/101557263855536553789/',
                     'created_date': 'Thu Aug  8 15:35:34 2013',
                     'body': 'Another comment',
                     'updates': {},
@@ -233,7 +233,7 @@ class TestGoogleCodeProjectExtractor(TestCase):
                 },
                 {
                     'author.name': 'john...@gmail.com',
-                    'author.link': 'http://code.google.com/u/101557263855536553789/',
+                    'author.url': 'http://code.google.com/u/101557263855536553789/',
                     'created_date': 'Thu Aug  8 15:36:39 2013',
                     'body': 'Last comment',
                     'updates': {},
@@ -241,7 +241,7 @@ class TestGoogleCodeProjectExtractor(TestCase):
                 },
                 {
                     'author.name': 'john...@gmail.com',
-                    'author.link': 'http://code.google.com/u/101557263855536553789/',
+                    'author.url': 'http://code.google.com/u/101557263855536553789/',
                     'created_date': 'Thu Aug  8 15:36:57 2013',
                     'body': 'Oh, I forgot one',
                     'updates': {'Labels:': 'OpSys-OSX'},
@@ -250,8 +250,23 @@ class TestGoogleCodeProjectExtractor(TestCase):
             ]
         for actual, expected in zip(comments, expected):
             self.assertEqual(actual.author.name, expected['author.name'])
-            self.assertEqual(actual.author.link, expected['author.link'])
+            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'])
+
+class TestUserLink(TestCase):
+    def test_plain(self):
+        tag = mock.Mock()
+        tag.string.strip.return_value = 'name'
+        tag.attrMap = {}
+        link = google.UserLink(tag)
+        self.assertEqual(str(link), 'name')
+
+    def test_linked(self):
+        tag = mock.Mock()
+        tag.string.strip.return_value = 'name'
+        tag.attrMap = {'href': '/p/project'}
+        link = google.UserLink(tag)
+        self.assertEqual(str(link), '[name](http://code.google.com/p/project)')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/8facbc5e/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 15b8f33..01d9f8e 100644
--- a/ForgeImporters/forgeimporters/tests/google/test_tracker.py
+++ b/ForgeImporters/forgeimporters/tests/google/test_tracker.py
@@ -112,26 +112,21 @@ class TestTrackerImporter(TestCase):
 
     def test_process_fields(self):
         ticket = mock.Mock()
-        def _user(l):
-            u = mock.Mock()
-            u.name = '%sname' % l
-            u.link = '%slink' % l
-            return u
         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:_user('c'),
-                get_issue_owner=lambda:_user('o'),
+                get_issue_creator=lambda:'creator',
+                get_issue_owner=lambda:'owner',
             )
         importer = tracker.GoogleCodeTrackerImporter()
         with mock.patch.object(tracker, 'datetime') as dt:
             dt.strptime.side_effect = lambda s,f: s
             importer.process_fields(ticket, issue)
             self.assertEqual(ticket.summary, 'summary')
-            self.assertEqual(ticket.description, '*Originally created by:* [cname](clink)\n*Originally
owned by:* [oname](olink)\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')


Mime
View raw message