Example #1
0
    def get_pushlogs(self):
        """
        Returns pushlog json objects (python dicts) sorted by date.
        """
        # the first changeset is not taken into account in the result.
        # let's add it directly with this request
        chset_url = '%s/json-pushes?changeset=%s' % (self.get_repo_url(),
                                                     self.start_rev)
        response = get_http_session().get(chset_url)
        response.raise_for_status()
        chsets = response.json()

        # now fetch all remaining changesets
        response = get_http_session().get(self.pushlog_url())
        response.raise_for_status()
        chsets.update(response.json())
        # sort pushlogs by date
        return sorted(chsets.itervalues(), key=lambda push: push['date'])
Example #2
0
    def test_get_http_session(self):
        utils.set_http_cache_session(self.make_cache())
        a_session = utils.get_http_session()

        # verify session exists
        self.assertTrue(isinstance(a_session, requests.Session))

        # turns out CacheControl is just a function not a class
        # so it makes verifying that we're actually using it
        # a little messy
        for k, v in a_session.adapters.items():
            self.assertTrue(
                isinstance(v.cache, limitedfilecache.LimitedFileCache))
Example #3
0
    def test_get_http_session(self):
        utils.set_http_cache_session(self.make_cache())
        a_session = utils.get_http_session()

        # verify session exists
        self.assertTrue(isinstance(a_session, requests.Session))

        # turns out CacheControl is just a function not a class
        # so it makes verifying that we're actually using it
        # a little messy
        for k, v in a_session.adapters.items():
            self.assertTrue(isinstance(v.cache,
                            limitedfilecache.LimitedFileCache))
Example #4
0
 def test_set_http_session_with_get_defaults(self):
     original_get = Mock()
     session = Mock(get=original_get)
     utils.set_http_cache_session(session, get_defaults={"timeout": 10.0})
     # default is applied
     utils.get_http_session().get('url')
     original_get.assert_called_with('url', timeout=10.0)
     # this is just a default, it can be overriden
     utils.get_http_session().get('url', timeout=5.0)
     original_get.assert_called_with('url', timeout=5.0)
     # you can still pass a None session
     with patch('requests.Session') as Session:
         Session.return_value = session
         utils.set_http_cache_session(None, get_defaults={'timeout': 1.0})
         # a new session has been returned
         self.assertEquals(session, utils.get_http_session())
         # with defaults patch too
         utils.get_http_session().get('url')
         original_get.assert_called_with('url', timeout=1.0)
Example #5
0
 def test_set_http_session_with_get_defaults(self):
     original_get = Mock()
     session = Mock(get=original_get)
     utils.set_http_cache_session(session, get_defaults={"timeout": 10.0})
     # default is applied
     utils.get_http_session().get('url')
     original_get.assert_called_with('url', timeout=10.0)
     # this is just a default, it can be overriden
     utils.get_http_session().get('url', timeout=5.0)
     original_get.assert_called_with('url', timeout=5.0)
     # you can still pass a None session
     with patch('requests.Session') as Session:
         Session.return_value = session
         utils.set_http_cache_session(None, get_defaults={'timeout': 1.0})
         # a new session has been returned
         self.assertEquals(session, utils.get_http_session())
         # with defaults patch too
         utils.get_http_session().get('url')
         original_get.assert_called_with('url', timeout=1.0)
Example #6
0
    def find_build_info_txt(self, url):
        """
        Retrieve information from a build information txt file.

        Returns a dict with keys repository and changeset if information
        is found.
        """
        data = {}
        response = get_http_session().get(url)
        for line in response.text.splitlines():
            if '/rev/' in line:
                repository, changeset = line.split('/rev/')
                data['repository'] = repository
                data['changeset'] = changeset
                break
        if not data:
            # the txt file could be in an old format:
            # DATE CHANGESET
            # we can try to extract that to get the changeset at least.
            matched = re.match('^\d+ (\w+)$', response.text.strip())
            if matched:
                data['changeset'] = matched.group(1)
        return data
Example #7
0
 def test_none_returns_requests(self):
     utils.set_http_cache_session(self.make_cache())
     utils.set_http_cache_session(None)
     self.assertEquals(utils.get_http_session(), requests)
Example #8
0
 def test_basic(self):
     self.assertEquals(utils.get_http_session(), requests)
Example #9
0
 def test_none_returns_requests(self):
     utils.set_http_cache_session(self.make_cache())
     utils.set_http_cache_session(None)
     self.assertEquals(utils.get_http_session(), requests)
Example #10
0
 def test_basic(self):
     self.assertEquals(utils.get_http_session(), requests)
Example #11
0
 def __init__(self, destdir, **kwargs):
     QObject.__init__(self)
     BuildDownloadManager.__init__(self, None, destdir,
                                   session=get_http_session(),
                                   **kwargs)