Exemplo n.º 1
0
 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
Exemplo n.º 2
0
 def _make_extractor(self, html):
     with mock.patch.object(base.h, 'urlopen') as urlopen:
         urlopen.return_value = ''
         extractor = google.GoogleCodeProjectExtractor(
             'my-project', 'project_info')
     extractor.page = BeautifulSoup(html)
     extractor.url = "http://test/issue/?id=1"
     return extractor
Exemplo n.º 3
0
    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')
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
 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),
         ])
Exemplo n.º 6
0
 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.page = BeautifulSoup(html)
     extractor.url = "http://test/issue/?id=1"
     # iter_comments will make more get_page() calls but we don't want the real thing to run an mess up the .page
     # and .url attributes, make it a no-op which works with these tests (since its just the same page being
     # fetched really)
     extractor.get_page = lambda *a, **kw: ''
     return extractor
Exemplo n.º 7
0
    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'})
Exemplo n.º 8
0
 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'])
Exemplo n.º 9
0
    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')
Exemplo n.º 10
0
 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/')
Exemplo n.º 11
0
 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/')
Exemplo n.º 12
0
 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()