def test_api_key():
 @hug.authentication.api_key
 def api_key_authentication(api_key):
  if (api_key == 'Bacon'):
   return 'Timothy'
 @hug.get(requires=api_key_authentication)
 def hello_world():
  return 'Hello world!'
 assert (hug.test.get(api, 'hello_world', headers={'X-Api-Key': 'Bacon'}).data == 'Hello world!')
 assert ('401' in hug.test.get(api, 'hello_world').status)
 assert ('401' in hug.test.get(api, 'hello_world', headers={'X-Api-Key': 'Invalid'}).status)

def test_api_key ( ) : @ hug . authentication . api_key def api_key_authentication ( api_key ) : if ( api_key == 'Bacon' ) : return 'Timothy' @ hug . get ( requires = api_key_authentication ) def hello_world ( ) : return 'Hello world!' assert ( hug . test . get ( api , 'hello_world' , headers = { 'X-Api-Key' : 'Bacon' } ) . data == 'Hello world!' ) assert ( '401' in hug . test . get ( api , 'hello_world' ) . status ) assert ( '401' in hug . test . get ( api , 'hello_world' , headers = { 'X-Api-Key' : 'Invalid' } ) . status )
test the included api_key based header to ensure it works as expected to allow x-api-key based authentication .