]> jfr.im git - z_archive/twitter.git/commitdiff
Fix search tests to use api.twitter.com with authorisation
authorhugovk <redacted>
Tue, 15 Apr 2014 10:07:55 +0000 (13:07 +0300)
committerhugovk <redacted>
Tue, 15 Apr 2014 10:07:55 +0000 (13:07 +0300)
.travis.yml
tests/test_sanity.py
twitter/api.py

index 15a58d35b1697ab08ba81d232c1bb4bd8db4c957..f81983b6dfca606e2a1e0113e8199310e7f097f0 100644 (file)
@@ -10,6 +10,13 @@ python:
 
 script: nosetests
 
+after_success:
+  - pip install pep8 pyflakes
+  - pep8 twitter/*.py
+  - pyflakes twitter/*.py
+  - pep8 tests/*.py
+  - pyflakes tests/*.py
+
 matrix:
   allow_failures:
     - python: "2.6"
index fb315e2b81fe1fa8e50b40b4c59ce504824c96ad..c2e94eae511cf54bf46d8347cdc63fa094e117f1 100644 (file)
@@ -64,8 +64,9 @@ def test_API_set_unicode_tweet():
 
 
 def test_search():
-    t_search = Twitter(domain='search.twitter.com')
-    results = t_search.search(q='foo')
+    # In 1.1, search works on api.twitter.com not search.twitter.com
+    # and requires authorisation
+    results = twitter11.search(q='foo')
     assert results
 
 
index c61ffc50c56883a48ac048f13c0b2a2f8cd9fac1..9002768e1072b60a35c06bf9cbfd229e91a4bc02 100644 (file)
@@ -22,9 +22,11 @@ try:
 except ImportError:
     import simplejson as json
 
+
 class _DEFAULT(object):
     pass
 
+
 class TwitterError(Exception):
     """
     Base Exception thrown by the Twitter object when there is a
@@ -32,6 +34,7 @@ class TwitterError(Exception):
     """
     pass
 
+
 class TwitterHTTPError(TwitterError):
     """
     Exception thrown by the Twitter object when there is an
@@ -53,10 +56,11 @@ class TwitterHTTPError(TwitterError):
         fmt = ("." + self.format) if self.format else ""
         return (
             "Twitter sent status %i for URL: %s%s using parameters: "
-            "(%s)\ndetails: %s" %(
+            "(%s)\ndetails: %s" % (
                 self.e.code, self.uri, fmt, self.uriparts,
                 self.response_data))
 
+
 class TwitterResponse(object):
     """
     Response from a twitter request. Behaves like a list or a string
@@ -104,19 +108,18 @@ def wrap_response(response, headers):
         def __init__(self, response, headers):
             response_typ.__init__(self, response)
             TwitterResponse.__init__(self, headers)
+
         def __new__(cls, response, headers):
             return response_typ.__new__(cls, response)
 
-
     return WrappedTwitterResponse(response, headers)
 
 
-
 class TwitterCall(object):
 
     def __init__(
-        self, auth, format, domain, callable_cls, uri="",
-        uriparts=None, secure=True):
+            self, auth, format, domain, callable_cls, uri="",
+            uriparts=None, secure=True):
         self.auth = auth
         self.format = format
         self.domain = domain
@@ -132,8 +135,8 @@ class TwitterCall(object):
             def extend_call(arg):
                 return self.callable_cls(
                     auth=self.auth, format=self.format, domain=self.domain,
-                    callable_cls=self.callable_cls, uriparts=self.uriparts \
-                        + (arg,),
+                    callable_cls=self.callable_cls, uriparts=self.uriparts
+                    + (arg,),
                     secure=self.secure)
             if k == "_":
                 return extend_call
@@ -161,7 +164,7 @@ class TwitterCall(object):
         # the list of uriparts, assume the id goes at the end.
         id = kwargs.pop('id', None)
         if id:
-            uri += "/%s" %(id)
+            uri += "/%s" % (id)
 
         # If an _id kwarg is present, this is treated as id as a CGI
         # param.
@@ -178,8 +181,8 @@ class TwitterCall(object):
         dot = ""
         if self.format:
             dot = "."
-        uriBase = "http%s://%s/%s%s%s" %(
-                    secure_str, self.domain, uri, dot, self.format)
+        uriBase = "http%s://%s/%s%s%s" % (
+            secure_str, self.domain, uri, dot, self.format)
 
         headers = {'Accept-Encoding': 'gzip'}
         if self.auth:
@@ -225,6 +228,7 @@ class TwitterCall(object):
             else:
                 raise TwitterHTTPError(e, uri, self.format, arg_data)
 
+
 class Twitter(TwitterCall):
     """
     The minimalist yet fully featured Twitter API class.
@@ -310,9 +314,9 @@ class Twitter(TwitterCall):
 
     """
     def __init__(
-        self, format="json",
-        domain="api.twitter.com", secure=True, auth=None,
-        api_version=_DEFAULT):
+            self, format="json",
+            domain="api.twitter.com", secure=True, auth=None,
+            api_version=_DEFAULT):
         """
         Create a new twitter API connector.
 
@@ -325,20 +329,19 @@ class Twitter(TwitterCall):
 
 
         `domain` lets you change the domain you are connecting. By
-        default it's `api.twitter.com` but `search.twitter.com` may be
-        useful too.
+        default it's `api.twitter.com`.
 
         If `secure` is False you will connect with HTTP instead of
         HTTPS.
 
         `api_version` is used to set the base uri. By default it's
-        '1'. If you are using "search.twitter.com" set this to None.
+        '1.1'.
         """
         if not auth:
             auth = NoAuth()
 
         if (format not in ("json", "xml", "")):
-            raise ValueError("Unknown data format '%s'" %(format))
+            raise ValueError("Unknown data format '%s'" % (format))
 
         if api_version is _DEFAULT:
             if domain == 'api.twitter.com':