Exemple #1
0
    def test_get_many(self):

        expected = {
            self._url('http://{host}:{port}/a'): (200, 'OK'),
            self._url('http://{host}:{port}/b'): (200, 'OK'),
            self._url('http://{host}:{port}/c'): (200, 'OK'),
        }

        self.assertEqual(phlurl_request.get_many(expected.iterkeys()),
                         expected)
    def test_get_many(self):

        expected = {
            self._url('http://{host}:{port}/a'): (200, 'OK'),
            self._url('http://{host}:{port}/b'): (200, 'OK'),
            self._url('http://{host}:{port}/c'): (200, 'OK'),
        }

        self.assertEqual(
            phlurl_request.get_many(expected.iterkeys()),
            expected)
Exemple #3
0
    def test_get_many(self):

        url_a = self._url('http://{host}:{port}/index')
        url_b = self._url('http://*****:*****@{host}:{port}/index')
        url_c = self._url('http://*****:*****@{host}:{port}/index')

        expected = {
            url_a: (401, 'Authentication required'),
            url_b: (200, 'Basic Zm9vOmJhcg=='),
            url_c: (200, 'Basic YmF6OmJ1eg=='),
        }

        self.assertEqual(phlurl_request.get_many(expected.iterkeys()),
                         expected)
    def test_get_many(self):

        url_a = self._url('http://{host}:{port}/index')
        url_b = self._url('http://*****:*****@{host}:{port}/index')
        url_c = self._url('http://*****:*****@{host}:{port}/index')

        expected = {
            url_a: (401, 'Authentication required'),
            url_b: (200, 'Basic Zm9vOmJhcg=='),
            url_c: (200, 'Basic YmF6OmJ1eg=='),
        }

        self.assertEqual(
            phlurl_request.get_many(expected.iterkeys()),
            expected)
    def refresh(self):
        # XXX: it's safe to refresh multiple times - the 'has changed' flag
        #      is only consumed on 'has_url_recently_changed'
        url_contents = phlurl_request.get_many(self._results.keys())
        for url, contents in url_contents.iteritems():
            old_result = self._results[url]

            # Note that hash objects can't be compared directly so we much
            # first convert them to a representation that can be compared, in
            # this case we've chosen the hexdigest.
            #
            # Note that if you do try to compare hash objects then it seems to
            # do the 'is' comparison rather than 'is equal to'
            #
            # pylint: disable=E1101
            new_hash = hashlib.sha1(contents).hexdigest()
            # pylint: enable=E1101
            old_hash = old_result.hash_hexdigest
            has_changed = old_result.has_changed or (new_hash != old_hash)

            self._results[url] = _HashHexdigestHasChanged(
                new_hash, has_changed)