allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hei...@apache.org
Subject [22/50] allura git commit: [#8054] delete Google Code importers and tests
Date Wed, 27 Jan 2016 20:22:36 GMT
http://git-wip-us.apache.org/repos/asf/allura/blob/b956fe30/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
deleted file mode 100644
index 72a7d6c..0000000
--- a/ForgeImporters/forgeimporters/tests/google/test_extractor.py
+++ /dev/null
@@ -1,607 +0,0 @@
-#       Licensed to the Apache Software Foundation (ASF) under one
-#       or more contributor license agreements.  See the NOTICE file
-#       distributed with this work for additional information
-#       regarding copyright ownership.  The ASF licenses this file
-#       to you under the Apache License, Version 2.0 (the
-#       "License"); you may not use this file except in compliance
-#       with the License.  You may obtain a copy of the License at
-#
-#         http://www.apache.org/licenses/LICENSE-2.0
-#
-#       Unless required by applicable law or agreed to in writing,
-#       software distributed under the License is distributed on an
-#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-#       KIND, either express or implied.  See the License for the
-#       specific language governing permissions and limitations
-#       under the License.
-
-from unittest import TestCase
-import pkg_resources
-from urllib2 import HTTPError
-
-import mock
-from datadiff.tools import assert_equal
-from IPython.testing.decorators import skipif, module_not_available
-from BeautifulSoup import BeautifulSoup
-
-from allura.tests.decorators import without_module
-from forgeimporters import google
-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(base, 'BeautifulSoup')
-        self.urlopen = self._p_urlopen.start()
-        self.soup = self._p_soup.start()
-        self.project = mock.Mock(name='project')
-        self.project.get_tool_data.return_value = 'my-project'
-
-    def tearDown(self):
-        for patcher in ('_p_urlopen', '_p_soup'):
-            try:
-                getattr(self, patcher).stop()
-            except RuntimeError as e:
-                if 'unstarted patcher' in str(e):
-                    pass  # test case might stop them early
-                else:
-                    raise
-
-    def test_init(self):
-        extractor = google.GoogleCodeProjectExtractor(
-            'my-project', 'project_info')
-
-        self.urlopen.assert_called_once_with(
-            'http://code.google.com/p/my-project/')
-        self.soup.assert_called_once_with(self.urlopen.return_value, convertEntities=self.soup.HTML_ENTITIES)
-        self.assertEqual(extractor.page, self.soup.return_value)
-
-    def test_get_page(self):
-        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/'])
-        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/'])
-        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/'])
-        parser = mock.Mock(return_value='parsed')
-        page = extractor.get_page('url', parser=parser)
-        self.assertEqual(page, 'parsed')
-        self.assertEqual(page, extractor._page_cache['url'])
-
-    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/')
-
-    def test_get_page_url_hosted(self):
-        extractor = google.GoogleCodeProjectExtractor('a/eclipselabs.org/p/restclient-tool')
-        self.assertEqual(extractor.get_page_url('project_info'),
-                         'http://code.google.com/a/eclipselabs.org/p/restclient-tool/')
-
-    def test_get_short_description(self):
-        extractor = google.GoogleCodeProjectExtractor(
-            'my-project', 'project_info')
-        extractor.page.find.return_value.text = 'My Super Project'
-
-        extractor.get_short_description(self.project)
-
-        extractor.page.find.assert_called_once_with(itemprop='description')
-        self.assertEqual(self.project.short_description, 'My Super Project')
-
-    @mock.patch.object(google, 'File')
-    @mock.patch.object(google, 'M')
-    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.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')
-        M.ProjectFile.save_image.assert_called_once_with(
-            'my-logo.png', 'data', 'image/png', square=True,
-            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.page.find.return_value.findNext.return_value.find.return_value.text = '
 New BSD License  '
-        trove = M.TroveCategory.query.get.return_value
-
-        extractor.get_license(self.project)
-
-        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')
-        self.assertEqual(self.project.trove_license, [trove._id])
-        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')
-
-    def _make_extractor(self, html):
-        with mock.patch.object(base.ProjectExtractor, 'urlopen'):
-            extractor = google.GoogleCodeProjectExtractor('allura-google-importer')
-        extractor.page = BeautifulSoup(html)
-        extractor.get_page = lambda pagename: extractor.page
-        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/&nbsp;</span>')
-        self.assertEqual('svn', extractor.get_repo_type())
-
-    def test_get_repo_type_no_crumb_root(self):
-        extractor = self._make_extractor('')
-        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")
-
-    def test_get_repo_type_unknown_repo_type(self):
-        extractor = self._make_extractor(
-            '<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()
-        gpe = self._make_extractor(empty_issue)
-        self.assertIsNone(gpe.get_issue_owner())
-        self.assertEqual(gpe.get_issue_status(), '')
-        self.assertEqual(gpe.get_issue_attachments(), [])
-        self.assertEqual(list(gpe.iter_comments()), [])
-        self.assertEqual(gpe.get_issue_mod_date(), 'Thu Aug  8 14:56:23 2013')
-
-    @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()
-        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_owner().name, 'john...@gmail.com')
-        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'
-                     '&nbsp; 1\\. Test List\n'
-                     '&nbsp; 2\\. Item\n'
-                     '\n'
-                     '\\*\\*Testing\\*\\*\n'
-                     '\n'
-                     ' \\* Test list 2\n'
-                     ' \\* Item\n'
-                     '\n'
-                     '\\# Test Section\n'
-                     '\n'
-                     '&nbsp;&nbsp;&nbsp; p = source\\.test\\_issue\\.post\\(\\)\n'
-                     '&nbsp;&nbsp;&nbsp; p\\.count = p\\.count \\*5 \\#\\* 6\n'
-                     '&nbsp;&nbsp;&nbsp; if p\\.count &gt; 5:\n'
-                     '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
print "Not &lt; 5 &amp; \\!= 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()
-        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_owner().name, 'john...@gmail.com')
-        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'
-                     '&nbsp; 1. Test List\n'
-                     '&nbsp; 2. Item\n'
-                     '\n'
-                     '\\*\\*Testing\\*\\*\n'
-                     '\n'
-                     ' \\* Test list 2\n'
-                     ' \\* Item\n'
-                     '\n'
-                     '\\# Test Section\n'
-                     '\n'
-                     '&nbsp;&nbsp;&nbsp; p = source.test\\_issue.post\\(\\)\n'
-                     '&nbsp;&nbsp;&nbsp; p.count = p.count \\*5 \\#\\* 6\n'
-                     '&nbsp;&nbsp;&nbsp; if p.count &gt; 5:\n'
-                     '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
print "Not &lt; 5 &amp; \\!= 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):
-        html = u"""
-        <div id="issueheader">
-            <table>
-                <tbody>
-                    <tr>
-                        <td></td>
-                        <td><span>%s</span></td>
-                    </tr>
-                </tbody>
-            </table>
-        </div>
-        """
-        gpe = self._make_extractor(html % u'')
-        self.assertEqual(gpe.get_issue_summary(), u'')
-        gpe = self._make_extractor(html % u'My Summary')
-        self.assertEqual(gpe.get_issue_summary(), u'My Summary')
-
-    def test_get_issue_labels(self):
-        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',
-        ])
-
-    @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()
-        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].type, 'text/plain')
-
-    def test_get_issue_ids(self):
-        extractor = google.GoogleCodeProjectExtractor(None)
-        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.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'))]
-        self.assertEqual(issue_ids, [1, 2, 3, 4])
-        get_issue_ids.assert_has_calls([
-            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,
-            # 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'):
-                issue_ids.append(issue_id)
-        except HTTPError as e:
-            self.assertEqual(e.code, 500)
-        else:
-            assert False, 'Missing expected raised exception'
-        self.assertEqual(issue_ids, [1, 3])
-
-    @mock.patch.object(google.requests, 'head')
-    def test_check_readable(self, head):
-        head.return_value.status_code = 200
-        assert google.GoogleCodeProjectExtractor('my-project').check_readable()
-        head.return_value.status_code = 404
-        assert not google.GoogleCodeProjectExtractor('my-project').check_readable()
-
-
-class TestWithSetupForComments(TestCase):
-    # The main test suite did too much patching for how we want these tests to work
-    # These tests use iter_comments and 2 HTML pages of comments.
-
-    def _create_extractor(self):
-        test_issue = open(pkg_resources.resource_filename(
-            'forgeimporters', 'tests/data/google/test-issue-first-page.html')).read()
-        test_issue_older = open(pkg_resources.resource_filename(
-            'forgeimporters', 'tests/data/google/test-issue-prev-page.html')).read()
-
-        class LocalTestExtractor(google.GoogleCodeProjectExtractor):
-            def urlopen(self, url, **kw):
-                return self.urlopen_results.pop(0)
-
-            def setup_urlopen_results(self, results):
-                self.urlopen_results = results
-
-        gpe = LocalTestExtractor('allura-google-importer')
-        gpe.setup_urlopen_results([test_issue, test_issue_older])
-
-        return gpe
-
-    def test_get_issue_mod_date(self):
-        gpe = self._create_extractor()
-        gpe.get_page('detail?id=6')
-        self.assertEqual(gpe.get_issue_mod_date(), 'Thu Aug  8 15:36:57 2013')
-
-    @without_module('html2text')
-    @mock.patch.object(base, 'StringIO')
-    def test_iter_comments(self, StringIO):
-        gpe = self._create_extractor()
-        gpe.get_page('detail?id=6')
-
-        with mock.patch.object(base.ProjectExtractor, 'urlopen'):  # for attachments, which
end up using a different Extractor urlopen
-            comments = list(gpe.iter_comments())
-
-        self.assertEqual(len(comments), 6)
-        expected = [
-            {
-                'author.name': 'john...@gmail.com',
-                'author.url': 'http://code.google.com/u/101557263855536553789/',
-                'created_date': 'Thu Aug  8 15:34:01 2013',
-                'body': 'Simple comment',
-                'updates': {},
-                'attachments': [],
-            },
-            {
-                'author.name': 'john...@gmail.com',
-                'author.url': 'http://code.google.com/u/101557263855536553789/',
-                'created_date': 'Thu Aug  8 15:34:09 2013',
-                'body': 'Boring comment',
-                'updates': {},
-                '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'])
-
-    @skipif(module_not_available('html2text'))
-    @mock.patch.object(base, 'StringIO')
-    def test_iter_comments_html2text(self, StringIO):
-        gpe = self._create_extractor()
-        gpe.get_page('detail?id=6')
-
-        with mock.patch.object(base.ProjectExtractor, 'urlopen'):  # for attachments, which
end up using a different Extractor urlopen
-            comments = list(gpe.iter_comments())
-
-        self.assertEqual(len(comments), 6)
-        expected = [
-            {
-                'author.name': 'john...@gmail.com',
-                'author.url': 'http://code.google.com/u/101557263855536553789/',
-                'created_date': 'Thu Aug  8 15:34:01 2013',
-                'body': 'Simple comment',
-                'updates': {},
-                'attachments': [],
-            },
-            {
-                'author.name': 'john...@gmail.com',
-                'author.url': 'http://code.google.com/u/101557263855536553789/',
-                'created_date': 'Thu Aug  8 15:34:09 2013',
-                'body': 'Boring comment',
-                'updates': {},
-                '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'])
-
-
-class TestUserLink(TestCase):
-
-    def test_plain(self):
-        tag = mock.Mock()
-        tag.text.strip.return_value = 'name'
-        tag.get.return_value = None
-        link = google.UserLink(tag)
-        self.assertEqual(str(link), 'name')
-
-    def test_linked(self):
-        tag = mock.Mock()
-        tag.text.strip.return_value = 'name'
-        tag.get.return_value = '/p/project'
-        link = google.UserLink(tag)
-        self.assertEqual(str(link), '[name](http://code.google.com/p/project)')
-
-
-class TestComment(TestCase):
-    html = """
-    <div class="cursor_off vt issuecomment" id="hc2">
-     <div style="float:right; margin-right:.3em; text-align:right">
-     <span class="date" title="Tue Jun 25 03:20:09 2013">
-     Jun 25, 2013
-     </span>
-     </div>
-     <span class="author">
-     <span class="role_label">Project Member</span>
-     <a name="c2" href="/p/pychess/issues/detail?id=267#c2">#2</a>
-     <a class="userlink" href="/u/gbtami/">gbtami</a></span>
-    <pre><i>(No comment was entered for this change.)</i>
-    </pre>
-     <div class="updates">
-     <div class="round4"></div>
-     <div class="round2"></div>
-     <div class="round1"></div>
-     <div class="box-inner">
-     <b>Summary:</b>
-     Make PyChess keyboard accessible
-     <span class="oldvalue">
-     (was: Make PyChess keyboard accecible)
-     </span>
-     <br>
-     <b>Status:</b>
-     Accepted
-     <br>
-     </div>
-     <div class="round1"></div>
-     <div class="round2"></div>
-     <div class="round4"></div>
-     </div>
-    </div>
-    """
-
-    def test_init(self):
-        from BeautifulSoup import BeautifulSoup
-        html = BeautifulSoup(self.html)
-        comment = google.Comment(html.find('div', 'issuecomment'), 'pychess')
-        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()
-
-    def test_unicode(self):
-        tag = self.soup(u'\ua000 foo <a href="http://example.com/">bar</a>')
-        res = google._as_markdown(tag, 'pn')
-        self.assertEqual(res, u'\ua000 foo [bar](http://example.com/)')

http://git-wip-us.apache.org/repos/asf/allura/blob/b956fe30/ForgeImporters/forgeimporters/tests/google/test_tasks.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/google/test_tasks.py b/ForgeImporters/forgeimporters/tests/google/test_tasks.py
deleted file mode 100644
index 01bab68..0000000
--- a/ForgeImporters/forgeimporters/tests/google/test_tasks.py
+++ /dev/null
@@ -1,33 +0,0 @@
-#       Licensed to the Apache Software Foundation (ASF) under one
-#       or more contributor license agreements.  See the NOTICE file
-#       distributed with this work for additional information
-#       regarding copyright ownership.  The ASF licenses this file
-#       to you under the Apache License, Version 2.0 (the
-#       "License"); you may not use this file except in compliance
-#       with the License.  You may obtain a copy of the License at
-#
-#         http://www.apache.org/licenses/LICENSE-2.0
-#
-#       Unless required by applicable law or agreed to in writing,
-#       software distributed under the License is distributed on an
-#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-#       KIND, either express or implied.  See the License for the
-#       specific language governing permissions and limitations
-#       under the License.
-
-import mock
-
-from ...google import tasks
-
-
-@mock.patch.object(tasks, 'GoogleCodeProjectExtractor')
-@mock.patch.object(tasks, 'ThreadLocalORMSession')
-@mock.patch.object(tasks, 'c')
-def test_import_project_info(c, session, gpe):
-    c.project = mock.Mock(name='project')
-    tasks.import_project_info('my-project')
-    gpe.assert_called_once_with('my-project', 'project_info')
-    gpe.return_value.get_short_description.assert_called_once_with(c.project)
-    gpe.return_value.get_icon.assert_called_once_with(c.project)
-    gpe.return_value.get_license.assert_called_once_with(c.project)
-    session.flush_all.assert_called_once_with()

http://git-wip-us.apache.org/repos/asf/allura/blob/b956fe30/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
deleted file mode 100644
index e8f12bb..0000000
--- a/ForgeImporters/forgeimporters/tests/google/test_tracker.py
+++ /dev/null
@@ -1,336 +0,0 @@
-#       Licensed to the Apache Software Foundation (ASF) under one
-#       or more contributor license agreements.  See the NOTICE file
-#       distributed with this work for additional information
-#       regarding copyright ownership.  The ASF licenses this file
-#       to you under the Apache License, Version 2.0 (the
-#       "License"); you may not use this file except in compliance
-#       with the License.  You may obtain a copy of the License at
-#
-#         http://www.apache.org/licenses/LICENSE-2.0
-#
-#       Unless required by applicable law or agreed to in writing,
-#       software distributed under the License is distributed on an
-#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-#       KIND, either express or implied.  See the License for the
-#       specific language governing permissions and limitations
-#       under the License.
-
-from datetime import datetime
-from unittest import TestCase
-
-import mock
-from mock import patch
-from ming.odm import ThreadLocalORMSession
-
-from allura.tests import TestController
-from allura.tests.decorators import with_tracker
-
-from allura import model as M
-from forgeimporters.google import tracker
-
-
-class TestTrackerImporter(TestCase):
-
-    @mock.patch.object(tracker, 'g')
-    @mock.patch.object(tracker, 'c')
-    @mock.patch.object(tracker, 'ThreadLocalORMSession')
-    @mock.patch.object(tracker, 'session')
-    @mock.patch.object(tracker, 'M')
-    @mock.patch.object(tracker, 'TM')
-    @mock.patch.object(tracker, 'GoogleCodeProjectExtractor')
-    def test_import_tool(self, gpe, TM, M, session, tlos, c, g):
-        importer = tracker.GoogleCodeTrackerImporter()
-        importer.process_fields = mock.Mock()
-        importer.process_labels = mock.Mock()
-        importer.process_comments = mock.Mock()
-        importer.postprocess_custom_fields = 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': '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())]
-        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')
-
-        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]),
-        ])
-        self.assertEqual(importer.process_labels.call_args_list, [
-            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]),
-        ])
-        self.assertEqual(tlos.flush_all.call_args_list, [
-            mock.call(),
-            mock.call(),
-        ])
-        self.assertEqual(session.return_value.flush.call_args_list, [
-            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]),
-        ])
-        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')
-        g.post_event.assert_called_once_with('project_updated')
-        app.globals.invalidate_bin_counts.assert_called_once_with()
-
-    @mock.patch.object(tracker, 'ThreadLocalORMSession')
-    @mock.patch.object(tracker, 'M')
-    @mock.patch.object(tracker, 'h')
-    def test_import_tool_failure(self, h, M, ThreadLocalORMSession):
-        h.push_config.side_effect = ValueError
-        project = mock.Mock()
-        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')
-
-        h.make_app_admin_only.assert_called_once_with(
-            project.install_app.return_value)
-
-    def test_custom_fields(self):
-        importer = tracker.GoogleCodeTrackerImporter()
-        importer.custom_fields = {}
-        importer.custom_field('Foo')
-        importer.custom_field('Milestone')
-        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(),
-            },
-        })
-        importer.custom_fields = {'Foo': {}}
-        importer.custom_field('Foo')
-        self.assertEqual(importer.custom_fields, {'Foo': {}})
-
-    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',
-        )
-        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.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'),
-            ])
-
-    def test_process_labels(self):
-        ticket = mock.Mock(custom_fields={}, labels=[])
-        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.process_labels(ticket, issue)
-        self.assertEqual(ticket.labels, ['Baz'])
-        self.assertEqual(ticket.custom_fields, {'_foo': 'Bar, Qux'})
-
-    def test_process_comments(self):
-        def _author(n):
-            a = mock.Mock()
-            a.name = 'author%s' % n
-            a.link = 'author%s_link' % n
-            return a
-        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')]
-        comments[1].updates.items.return_value = []
-        posts = ticket.discussion_thread.add_post.side_effect = [
-            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')
-        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')
-
-    @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']),
-            },
-        }
-        custom_fields = importer.postprocess_custom_fields()
-        self.assertItemsEqual(custom_fields, [
-            {
-                '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',
-            },
-        ])
-
-
-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(
-                        tracker.GoogleCodeTrackerImporter())
-
-    @with_tracker
-    def test_index(self):
-        r = self.app.get('/p/test/admin/bugs/_importer/')
-        self.assertIsNotNone(r.html.find(attrs=dict(name="gc_project_name")))
-        self.assertIsNotNone(r.html.find(attrs=dict(name="mount_label")))
-        self.assertIsNotNone(r.html.find(attrs=dict(name="mount_point")))
-
-    @with_tracker
-    @patch('forgeimporters.base.import_tool')
-    def test_create(self, import_tool):
-        params = dict(gc_project_name='test',
-                      mount_label='mylabel',
-                      mount_point='mymount',
-                      )
-        r = self.app.post('/p/test/admin/bugs/_importer/create', params,
-                          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'])
-
-    @with_tracker
-    @patch('forgeimporters.base.import_tool')
-    def test_create_limit(self, import_tool):
-        project = M.Project.query.get(shortname='test')
-        project.set_tool_data('GoogleCodeTrackerImporter', pending=1)
-        ThreadLocalORMSession.flush_all()
-        params = dict(gc_project_name='test',
-                      mount_label='mylabel',
-                      mount_point='mymount',
-                      )
-        r = self.app.post('/p/test/admin/bugs/_importer/create', params,
-                          status=302).follow()
-        self.assertIn('Please wait and try again', r)
-        self.assertEqual(import_tool.post.call_count, 0)


Mime
View raw message