2012-02-07 03:55:05 -08:00
import unittest
2014-05-10 19:59:31 +02:00
2012-02-07 03:55:05 -08:00
import fastly
2014-05-10 19:59:31 +02:00
2012-02-07 03:55:05 -08:00
class APITest ( unittest . TestCase ) :
2014-05-10 19:59:31 +02:00
2012-02-07 03:55:05 -08:00
def setUp ( self ) :
2014-05-10 19:59:31 +02:00
self . api = fastly . API ( )
2012-02-07 03:55:05 -08:00
def test_purge ( self ) :
self . assertTrue ( self . api . purge_url ( ' test.com ' , ' / ' ) )
2014-09-15 10:49:11 -07:00
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 ' )
2012-02-07 03:55:05 -08:00
def test_auth_error ( self ) :
self . api . deauthenticate ( )
with self . assertRaises ( fastly . AuthenticationError ) :
self . api . conn . request ( ' GET ' , ' /current_customer ' )
def test_auth_key_success ( self ) :
self . api . deauthenticate ( )
self . api . authenticate_by_key ( ' TESTAPIKEY ' )
self . api . conn . request ( ' GET ' , ' /current_customer ' )
def test_auth_session_success ( self ) :
self . api . deauthenticate ( )
2014-05-10 19:59:31 +02:00
self . api . authenticate_by_password ( ' foo@example.com ' , ' password ' )
2012-02-07 03:55:05 -08:00
self . api . conn . request ( ' GET ' , ' /current_customer ' )
if __name__ == ' __main__ ' :
unittest . main ( )