def test_malformed_pub_key_document(self): # We need the first request to raise a 404, so we replace # post with a custom function here. def post(url, data): response = Mock() if not post.called: response.status_code = 404 post.called = True response.text = 'I AINT NO JSON, FOOL!' return response post.called = False with patch('browserid.certificates.requests') as requests: requests.post = post with self.assertRaises(InvalidIssuerError): fetch_public_key('test.com')
def _fetch(self, hostname, requests, well_known_url=None, side_effect=None, response_text='', status_code=200): response = Mock() response.text = response_text response.status_code = status_code requests.get.side_effect = side_effect requests.get.return_value = response kwargs = {} if well_known_url is not None: kwargs['well_known_url'] = well_known_url return fetch_public_key(hostname, **kwargs)