require key authentication for purge_by_key

This commit is contained in:
Thom Mahoney 2014-09-15 10:49:11 -07:00
parent b0dd18d4e4
commit 1bc048d1c7
3 changed files with 17 additions and 0 deletions

3
README
View file

@ -11,4 +11,7 @@ Doc files
Docstrings
Config file
TESTING:
`python -m test.api_test`

View file

@ -57,5 +57,8 @@ class API(object):
return resp.status == 200
def purge_key(self, service, key):
if type(self.conn.authenticator) is not KeyAuthenticator:
raise AuthenticationError("This request requires an API key")
resp, data = self.conn.request('POST','/service/%s/purge/%s' % (service, key))
return resp.status == 200

View file

@ -11,6 +11,17 @@ class APITest(unittest.TestCase):
def test_purge(self):
self.assertTrue(self.api.purge_url('test.com', '/'))
def test_purge_by_key(self):
self.api.deauthenticate()
self.api.authenticate_by_key('TESTAPIKEY')
self.assertTrue(self.api.purge_key('test.com', 'foo'))
def test_cookie_purge_by_key(self):
self.api.deauthenticate()
self.api.authenticate_by_password('foo@example.com', 'password')
with self.assertRaises(fastly.AuthenticationError):
self.api.purge_key('test.com', 'foo')
def test_auth_error(self):
self.api.deauthenticate()
with self.assertRaises(fastly.AuthenticationError):