def test_purge_location_successfully(self, requests): nginx = Nginx() response = mock.Mock() response.status_code = 200 response.text = 'purged' side_effect = mock.Mock() side_effect.status_code = 404 side_effect.text = "Not Found" requests.request.side_effect = [ response, side_effect, response, side_effect ] purged = nginx.purge_location('myhost', '/foo/bar') self.assertTrue(purged) self.assertEqual(requests.request.call_count, 4) expec_responses = [] for scheme in ['http', 'https']: for header in self.cache_headers: expec_responses.append( mock.call( 'get', 'http://myhost:8089/purge/{}/foo/bar'.format(scheme), headers=header, timeout=2)) requests.request.assert_has_calls(expec_responses)
def test_purge_location_not_found(self, requests): nginx = Nginx() response = mock.Mock() response.status_code = 404 response.text = 'Not Found' requests.get.side_effect = [response, response] purged = nginx.purge_location('myhost.com', '/foo/bar') self.assertFalse(purged) self.assertEqual(requests.get.call_count, 2) requests.get.assert_has_calls([mock.call('http://myhost.com:8089/purge/http/foo/bar', timeout=2), mock.call('http://myhost.com:8089/purge/https/foo/bar', timeout=2)])
def test_purge_location_not_found(self, requests): nginx = Nginx() response = mock.Mock() response.status_code = 404 response.text = 'Not Found' requests.get.side_effect = [response, response] purged = nginx.purge_location('myhost.com', '/foo/bar') self.assertFalse(purged) self.assertEqual(requests.get.call_count, 2) requests.get.assert_has_calls([ mock.call('http://myhost.com:8089/purge/http/foo/bar', timeout=2), mock.call('http://myhost.com:8089/purge/https/foo/bar', timeout=2) ])
def test_purge_location_preserve_path_successfully(self, requests): nginx = Nginx() response = mock.Mock() response.status_code = 200 response.text = 'purged' requests.request.side_effect = [response] purged = nginx.purge_location('myhost', 'http://example.com/foo/bar', True) self.assertTrue(purged) self.assertEqual(requests.request.call_count, 2) expected_responses = [] for header in self.cache_headers: expected_responses.append(mock.call('get', 'http://myhost:8089/purge/http://example.com/foo/bar', headers=header, timeout=2)) requests.request.assert_has_calls(expected_responses)
def test_purge_location_preserve_path_successfully(self, requests): nginx = Nginx() response = mock.Mock() response.status_code = 200 response.text = 'purged' requests.get.side_effect = [response] purged = nginx.purge_location('myhost', 'http://example.com/foo/bar', True) self.assertTrue(purged) self.assertEqual(requests.get.call_count, 2) expected_responses = [] for header in self.cache_headers: expected_responses.append(mock.call('http://myhost:8089/purge/http://example.com/foo/bar', headers=header, timeout=2)) requests.get.assert_has_calls(expected_responses)
def test_purge_location_not_found(self, requests): nginx = Nginx() response = mock.Mock() response.status_code = 404 response.text = 'Not Found' requests.request.side_effect = [response, response, response, response] purged = nginx.purge_location('myhost', '/foo/bar') self.assertFalse(purged) self.assertEqual(requests.request.call_count, 4) expec_responses = [] for scheme in ['http', 'https']: for header in self.cache_headers: expec_responses.append(mock.call('get', 'http://myhost:8089/purge/{}/foo/bar'.format(scheme), headers=header, timeout=2)) requests.request.assert_has_calls(expec_responses)
def test_purge_location_successfully(self, requests): nginx = Nginx() response = mock.Mock() response.status_code = 200 response.text = 'purged' side_effect = mock.Mock() side_effect.status_code = 404 side_effect.text = "Not Found" requests.get.side_effect = [response, side_effect] purged = nginx.purge_location('myhost.com', '/foo/bar') self.assertTrue(purged) self.assertEqual(requests.get.call_count, 2) requests.get.assert_has_calls([mock.call('http://myhost.com:8089/purge/http/foo/bar', timeout=2), mock.call('http://myhost.com:8089/purge/https/foo/bar', timeout=2)])
def test_purge_location_not_found(self, requests): nginx = Nginx() response = mock.Mock() response.status_code = 404 response.text = 'Not Found' requests.get.side_effect = [response, response, response, response] purged = nginx.purge_location('myhost', '/foo/bar') self.assertFalse(purged) self.assertEqual(requests.get.call_count, 4) expected_responses = [] for scheme in ['http', 'https']: for header in self.cache_headers: expected_responses.append(mock.call('http://myhost:8089/purge/{}/foo/bar'.format(scheme), headers=header, timeout=2)) requests.get.assert_has_calls(expected_responses)
def test_purge_location_preserve_path_successfully(self, requests): nginx = Nginx() response = mock.Mock() response.status_code = 200 response.text = 'purged' requests.get.side_effect = [response] purged = nginx.purge_location('myhost', 'http://example.com/foo/bar', True) self.assertTrue(purged) self.assertEqual(requests.get.call_count, 1) headers = {'Accept-Encoding': ''} requests.get.assert_has_calls([ mock.call('http://myhost:8089/purge/http://example.com/foo/bar', headers=headers, timeout=2) ])
def test_purge_location_successfully(self, requests): nginx = Nginx() response = mock.Mock() response.status_code = 200 response.text = 'purged' side_effect = mock.Mock() side_effect.status_code = 404 side_effect.text = "Not Found" requests.get.side_effect = [response, side_effect] purged = nginx.purge_location('myhost.com', '/foo/bar') self.assertTrue(purged) self.assertEqual(requests.get.call_count, 2) requests.get.assert_has_calls([ mock.call('http://myhost.com:8089/purge/http/foo/bar', timeout=2), mock.call('http://myhost.com:8089/purge/https/foo/bar', timeout=2) ])