Ejemplo n.º 1
0
 def test_headers(self):
     i = GitHubIterator(self.i.count,
                        self.i.url,
                        self.i.cls,
                        self.g,
                        etag='"foobarbogus"')
     expect(i.headers.get('If-None-Match')) == '"foobarbogus"'
Ejemplo n.º 2
0
 def test_nexts(self):
     self.response('user', _iter=True)
     self.get(self.api_url)
     self.conf = {'params': None, 'headers': {}}
     self.j = GitHubIterator(self.num, self.api_url, github3.users.User,
                             self.g)
     expect(self.j.next().login) == next(self.i).login
     self.mock_assertions()
Ejemplo n.º 3
0
def iter_branches(self, number=-1, etag=None, protected=False):
    url = self._build_url('branches', base_url=self._api)
    headers = {'Accept': 'application/vnd.github.loki-preview+json'}
    return GitHubIterator(int(number),
                          url,
                          github3.repos.branch.Branch,
                          self,
                          etag=etag,
                          headers=headers,
                          params={'protected': int(protected)})
Ejemplo n.º 4
0
    def test_count_reaches_0(self):
        self.response('user', _iter=True)
        self.get(self.api_url)
        self.conf = {'params': {'per_page': 1}, 'headers': {}}
        self.i = GitHubIterator(1, self.api_url, github3.users.User, self.g)

        assert isinstance(next(self.i), github3.users.User)
        self.assertRaises(StopIteration, next, self.i)

        self.mock_assertions()
Ejemplo n.º 5
0
 def test_stores_etag_properly(self):
     session, url, count, cls = (
         self.session,
         self.url,
         self.count,
         self.cls,
     )
     i = GitHubIterator(count, url, cls, session, etag='"foobarbogus"')
     assert i.headers != {}
     assert i.headers.get("If-None-Match") == '"foobarbogus"'
Ejemplo n.º 6
0
    def test_count_reaches_0(self):
        self.response('user', _iter=True)
        self.get(self.api_url)
        self.conf = {'params': None, 'headers': {}}
        self.i = GitHubIterator(1, self.api_url, github3.users.User, self.g)

        expect(next(self.i)).isinstance(github3.users.User)
        with expect.raises(StopIteration):
            next(self.i)

        self.mock_assertions()
Ejemplo n.º 7
0
    def _iter(self, count, url, cls, params=None, etag=None):
        """Generic iterator for this project.

        :param int count: How many items to return.
        :param int url: First URL to start with
        :param class cls: cls to return an object of
        :param params dict: (optional) Parameters for the request
        :param str etag: (optional), ETag from the last call
        """
        from github3.structs import GitHubIterator
        return GitHubIterator(count, url, cls, self, params, etag)
Ejemplo n.º 8
0
 def test_stores_headers_properly(self):
     headers = {"Accept": "foo"}
     session, url, count, cls = (
         self.session,
         self.url,
         self.count,
         self.cls,
     )
     i = GitHubIterator(count, url, cls, session, headers=headers)
     assert i.headers != {}
     assert i.headers.get("Accept") == "foo"
Ejemplo n.º 9
0
 def setUp(self):
     super(TestGitHubIterator, self).setUp()
     self.api_url = 'https://api.github.com/users'
     self.num = 10
     self.i = GitHubIterator(self.num, self.api_url, github3.users.User,
                             self.g)
Ejemplo n.º 10
0
 def test_stores_headers_properly(self):
     headers = {'Accept': 'foo'}
     session, url, count, cls = self.session, self.url, self.count, self.cls
     i = GitHubIterator(count, url, cls, session, headers=headers)
     assert i.headers != {}
     assert i.headers.get('Accept') == 'foo'