root / api / tests_auth.py @ 7584d408
History | View | Annotate | Download (1.5 kB)
1 |
#
|
---|---|
2 |
# Unit Tests for api
|
3 |
#
|
4 |
# Provides automated tests for api module
|
5 |
#
|
6 |
# Copyright 2011 Greek Research and Technology Network
|
7 |
#
|
8 |
|
9 |
from django.test import TestCase |
10 |
from django.test.client import Client |
11 |
|
12 |
class AuthTestCase(TestCase): |
13 |
fixtures = ['auth_test_data']
|
14 |
apibase = '/api/v1.0'
|
15 |
|
16 |
def setUp(self): |
17 |
self.client = Client()
|
18 |
|
19 |
def test_auth_headers(self): |
20 |
""" test whether the authentication mechanism sets the correct headers
|
21 |
"""
|
22 |
#Check with non-existing user
|
23 |
response = self.client.get( self.apibase + '/servers', {}, |
24 |
**{'X-Auth-User':'notme', |
25 |
'X-Auth-Key':'0xdeadbabe'}) |
26 |
self.assertEquals(response.status_code, 401) |
27 |
|
28 |
#Check with existing user
|
29 |
response = self.client.get( self.apibase + '/', {}, |
30 |
**{'X-Auth-User':'testuser', |
31 |
'X-Auth-Key':'testuserpasswd'}) |
32 |
self.assertEquals(response.status_code, 204) |
33 |
self.assertNotEqual(response['X-Auth-Token'], None) |
34 |
self.assertEquals(response['X-Server-Management-Url'], '') |
35 |
self.assertEquals(response['X-Storage-Url'], '') |
36 |
self.assertEquals(response['X-CDN-Management-Url'], '') |
37 |
|
38 |
#Check access now that we do have an auth token
|
39 |
token = response['X-Auth-Token']
|
40 |
response = self.client.get (self.apibase + '/servers/detail', {}, |
41 |
**{'X-Auth-Token': token})
|
42 |
self.assertEquals(response.status_code, 200) |