incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [1/2] git commit: [#6895] ticket:518 Use HEAD instead of GET
Date Fri, 24 Jan 2014 15:21:54 GMT
Updated Branches:
  refs/heads/master 8a337c53c -> 43def0d73


[#6895] ticket:518 Use HEAD instead of GET


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

Branch: refs/heads/master
Commit: 43def0d734dfd0b760caa80ce1ae48ad1963d891
Parents: 7e90e15
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Fri Jan 24 12:06:35 2014 +0200
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Fri Jan 24 15:21:11 2014 +0000

----------------------------------------------------------------------
 ForgeImporters/forgeimporters/google/__init__.py       |  5 +++--
 .../forgeimporters/tests/google/test_extractor.py      | 13 ++++---------
 2 files changed, 7 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/43def0d7/ForgeImporters/forgeimporters/google/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/google/__init__.py b/ForgeImporters/forgeimporters/google/__init__.py
index 0a4e1e0..51560f9 100644
--- a/ForgeImporters/forgeimporters/google/__init__.py
+++ b/ForgeImporters/forgeimporters/google/__init__.py
@@ -23,6 +23,7 @@ from collections import defaultdict
 import logging
 import os
 
+import requests
 from BeautifulSoup import BeautifulSoup
 from formencode import validators as fev
 
@@ -161,8 +162,8 @@ class GoogleCodeProjectExtractor(ProjectExtractor):
     DEFAULT_ICON = 'http://www.gstatic.com/codesite/ph/images/defaultlogo.png'
 
     def check_readable(self):
-        page = urllib.urlopen(self.get_page_url('project_info'))
-        return (page.getcode() == 200) and (page.geturl() == self.get_page_url('project_info'))
+        resp = requests.head(self.get_page_url('project_info'))
+        return resp.status_code == 200
 
     def get_short_description(self, project):
         page = self.get_page('project_info')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/43def0d7/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 1de4872..fb82a57 100644
--- a/ForgeImporters/forgeimporters/tests/google/test_extractor.py
+++ b/ForgeImporters/forgeimporters/tests/google/test_extractor.py
@@ -460,18 +460,13 @@ class TestGoogleCodeProjectExtractor(TestCase):
             assert False, 'Missing expected raised exception'
         self.assertEqual(issue_ids, [1, 3])
 
-    @mock.patch.object(google.urllib, 'urlopen')
-    def test_check_readable(self, urlopen):
-        urlopen.return_value.getcode.return_value = 200
-        urlopen.return_value.geturl.return_value = 'http://code.google.com/p/my-project/'
+    @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()
-
-        urlopen.return_value.getcode.return_value = 404
+        head.return_value.status_code = 404
         assert not google.GoogleCodeProjectExtractor('my-project').check_readable()
 
-        urlopen.return_value.getcode.return_value = 200
-        urlopen.return_value.geturl.return_value = 'http://not_valid_url'
-        assert not google.GoogleCodeProjectExtractor('my-project').check_readable()
 
 class TestUserLink(TestCase):
 


Mime
View raw message