Revision 17fc7729 auth/tests.py

b/auth/tests.py
1
#
2
# Unit Tests for auth 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 = ['api_test_data', 'auth_test_data']
14
    apibase = '/api/v1.0'
15

  
16
    def setUp(self):
17
        self.client = Client()
18

  
19

  
20
    def test_auth_headers(self):
21
        """ test whether the authentication mechanism sets the correct headers
22
        """
23
        #Check with non-existing user
24
        response = self.client.get( self.apibase + '/servers', {},
25
                                   **{'X-Auth-User':'notme',
26
                                      'X-Auth-Key':'0xdeadbabe'})
27
        self.assertEquals(response.status_code, 401)
28

  
29
        #Check with existing user
30
        response = self.client.get( self.apibase + '/', {},
31
                                   **{'X-Auth-User':'testuser',
32
                                      'X-Auth-Key':'testuserpasswd'})
33
        self.assertEquals(response.status_code, 204)
34
        self.assertNotEqual(response['X-Auth-Token'], None)
35
        self.assertEquals(response['X-Server-Management-Url'], '')
36
        self.assertEquals(response['X-Storage-Url'], '')
37
        self.assertEquals(response['X-CDN-Management-Url'], '')
38

  
39
        #Check access now that we do have an auth token
40
        token = response['X-Auth-Token']
41
        response = self.client.get (self.apibase + '/servers/detail', {},
42
                                   **{'X-Auth-Token': token})
43
        self.assertEquals(response.status_code, 200)

Also available in: Unified diff