Commit bf00c997 authored by Georgios Gousios's avatar Georgios Gousios
Browse files

Tests for auth api headers

parent 83969d4f
# Unit Tests for auth api
# Provides automated tests for api module
# Copyright 2011 Greek Research and Technology Network
from django.test import TestCase
from django.test.client import Client
class AuthTestCase(TestCase):
apibase = '/api/v1.0'
def setUp(self):
self.client = Client()
def test_auth_headers(self):
""" test whether the authentication mechanism sets the correct headers
#Check with non-existing user
response = self.client.get( self.apibase + '/servers', {},
self.assertEquals(response.status_code, 401)
#Check with existing user
response = self.client.get( self.apibase + '/', {},
self.assertEquals(response.status_code, 204)
self.assertNotEqual(response['X-Auth-Token'], None)
self.assertEquals(response['X-Server-Management-Url'], '')
self.assertEquals(response['X-Storage-Url'], '')
self.assertEquals(response['X-CDN-Management-Url'], '')
#Check access now that we do have an auth token
token = response['X-Auth-Token']
response = self.client.get (self.apibase + '/servers/detail', {},
**{'X-Auth-Token': token})
self.assertEquals(response.status_code, 200)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment