Commits

Ian Cordasco  committed b113199

Fix a bug with start_page in search_*

Add regression test for #52. Fix tests/utils.generate_response so the
regression test actually works. ;)

  • Participants
  • Parent commits 575414a

Comments (0)

Files changed (4)

File github3/github.py

         :param int start_page: (optional), page to get (results come 100/page)
         :returns: list of :class:`LegacyIssue <github3.legacy.LegacyIssue>`\ s
         """
-        params = {} if int(start_page) > 0 else {'start_page': int(start_page)}
+        params = {'start_page': int(start_page)} if int(start_page) > 0 else {}
         url = self._build_url('legacy', 'issues', 'search', owner, repo,
                               state, keyword)
         json = self._json(self._get(url, params=params), 200)
         :param int start_page: (optional), page to get (results come 100/page)
         :returns: list of :class:`LegacyUser <github3.legacy.LegacyUser>`\ s
         """
-        params = {} if int(start_page) > 0 else {'start_page': int(start_page)}
+        params = {'start_page': int(start_page)} if int(start_page) > 0 else {}
         url = self._build_url('legacy', 'user', 'search', str(keyword))
         json = self._json(self._get(url, params=params), 200)
         users = json.get('users', [])

File tests/json/utf8_user

+{"html_url":"https://github.com/alejandrogomez","location":"Berlin, Germany","type":"User","avatar_url":"https://secure.gravatar.com/avatar/e085ed95734e09f3a66a749c4eca9ca8?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","company":"Pocket Village","hireable":false,"starred_url":"https://api.github.com/users/alejandrogomez/starred{/owner}{/repo}","gists_url":"https://api.github.com/users/alejandrogomez/gists{/gist_id}","following":86,"bio":"","url":"https://api.github.com/users/alejandrogomez","login":"alejandrogomez","blog":"alejandrogomez.github.com","repos_url":"https://api.github.com/users/alejandrogomez/repos","organizations_url":"https://api.github.com/users/alejandrogomez/orgs","created_at":"2010-09-20T22:28:47Z","followers_url":"https://api.github.com/users/alejandrogomez/followers","gravatar_id":"e085ed95734e09f3a66a749c4eca9ca8","followers":38,"events_url":"https://api.github.com/users/alejandrogomez/events{/privacy}","following_url":"https://api.github.com/users/alejandrogomez/following","public_repos":50,"name":"Alejandro Gómez","received_events_url":"https://api.github.com/users/alejandrogomez/received_events","subscriptions_url":"https://api.github.com/users/alejandrogomez/subscriptions","public_gists":4,"id":409039,"email":"alejandro@dialelo.org"}

File tests/test_github.py

         expect(self.g.key(10)).isinstance(github3.users.Key)
         self.mock_assertions()
 
+    def test_iter_all_repos(self):
+        self.request.return_value = generate_response('repo', _iter=True)
+        self.args = ('get', 'https://api.github.com/repositories')
+        self.conf.update(params=None)
+
+        repo = next(self.g.iter_all_repos())
+        expect(repo).isinstance(github3.repos.Repository)
+        self.mock_assertions()
+
+    def test_iter_all_users(self):
+        self.request.return_value = generate_response('user', _iter=True)
+        self.args = ('get', 'https://api.github.com/users')
+        self.conf.update(params=None)
+
+        repo = next(self.g.iter_all_users())
+        expect(repo).isinstance(github3.users.User)
+        self.mock_assertions()
+
     def test_iter_authorizations(self):
         self.request.return_value = generate_response('authorization',
                 _iter=True)  # nopep8
                      '{3}/{4}/{5}'.format(
                      'issues', 'search', 'sigmavirus24', 'github3.py',
                      'closed', 'requests'))
+        self.conf.update({'params': {}})
         issues = self.g.search_issues('sigmavirus24', 'github3.py', 'closed',
-                'requests')  # nopep8
+                                      'requests')
 
         expect(issues[0]).isinstance(github3.legacy.LegacyIssue)
         self.mock_assertions()
 
+        self.conf.update({'params': {'start_page': 2}})
+        issues = self.g.search_issues('sigmavirus24', 'github3.py', 'closed',
+                                      'requests', 2)
+        self.mock_assertions()
+
     def test_search_repos(self):
         self.request.return_value = generate_response('legacy_repo')
         self.args = ('get',
                      'https://api.github.com/{0}/{1}/{2}/{3}'.format(
                      'legacy', 'user', 'search', 'sigmavirus24')
                      )
+        self.conf.update({'params': {}})
         users = self.g.search_users('sigmavirus24')
         expect(users[0]).isinstance(github3.legacy.LegacyUser)
         self.mock_assertions()
 
+        self.conf.update({'params': {'start_page': 2}})
+        self.g.search_users('sigmavirus24', 2)
+        self.mock_assertions()
+
     def test_search_email(self):
         self.request.return_value = generate_response('legacy_email')
         self.args = ('get',
         expect(self.g.user()).isinstance(github3.users.User)
         self.mock_assertions()
 
+    def test_utf8_user(self):
+        self.request.return_value = generate_response('utf8_user')
+        self.args = ('get', 'https://api.github.com/users/alejandrogomez')
+
+        u = self.g.user('alejandrogomez')
+
+        try:
+            repr(u)
+        except UnicodeEncodeError:
+            self.fail('Regression caught. See PR #52. Names must be utf-8'
+                      ' encoded')
+
     # no test_zen

File tests/utils.py

     r.encoding = enc
 
     if path_name:
-        content = path(path_name).read().strip()
         if _iter:
+            content = path(path_name).read().strip()
             content = '[{0}]'.format(content)
-        r.raw = BytesIO(content.encode())
+            r.raw = BytesIO(content.encode('utf-8'))
+        else:
+            r.raw = path(path_name)
     else:
         r.raw = BytesIO()
 
 class CustomExpecter(expecter.expect):
     def is_not_None(self):
         assert self._actual is not None, (
-                'Expected anything but None but got it.'
-                )
+                'Expected anything but None but got it.'  # nopep8
+                )  # nopep8
 
     def is_None(self):
         assert self._actual is None, (
-                'Expected None but got %s' % repr(self._actual)
-                )
+                'Expected None but got %s' % repr(self._actual)  # nopep8
+                )  # nopep8
 
     def is_True(self):
         assert self._actual is True, (
-                'Expected True but got %s' % repr(self._actual)
-                )
+                'Expected True but got %s' % repr(self._actual)  # nopep8
+                )  # nopep8
 
     def is_False(self):
         assert self._actual is False, (
-                'Expected False but got %s' % repr(self._actual)
-                )
+                'Expected False but got %s' % repr(self._actual)  # nopep8
+                )  # nopep8
 
     def list_of(self, cls):
         for actual in self._actual: