Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
synnefo
Commits
f5e24ad4
Commit
f5e24ad4
authored
Apr 01, 2011
by
Georgios Gousios
Browse files
Move authentication tests and code to logic
parent
e1c185f8
Changes
3
Hide whitespace changes
Inline
Side-by-side
auth/tests.py
View file @
f5e24ad4
#
# 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
):
fixtures
=
[
'api_test_data'
,
'auth_test_data'
]
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'
,
{},
**
{
'X-Auth-User'
:
'notme'
,
'X-Auth-Key'
:
'0xdeadbabe'
})
self
.
assertEquals
(
response
.
status_code
,
401
)
#Check with existing user
response
=
self
.
client
.
get
(
self
.
apibase
+
'/'
,
{},
**
{
'X-Auth-User'
:
'testuser'
,
'X-Auth-Key'
:
'testuserpasswd'
})
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
auth
/fixtures/auth_test_data.json
→
logic
/fixtures/auth_test_data.json
View file @
f5e24ad4
File moved
logic/tests.py
View file @
f5e24ad4
...
...
@@ -99,3 +99,35 @@ class DebitAccountTestCase(TestCase):
s_user
=
SynnefoUser
.
objects
.
get
(
pk
=
30000
)
self
.
assertEqual
(
0
,
s_user
.
credit
,
'SynnefoUser (pk=30000) should have zero credits (%d)'
%
(
s_user
.
credit
,
))
class
AuthTestCase
(
TestCase
):
fixtures
=
[
'api_test_data'
,
'auth_test_data'
]
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'
,
{},
**
{
'X-Auth-User'
:
'notme'
,
'X-Auth-Key'
:
'0xdeadbabe'
})
self
.
assertEquals
(
response
.
status_code
,
401
)
#Check with existing user
response
=
self
.
client
.
get
(
self
.
apibase
+
'/'
,
{},
**
{
'X-Auth-User'
:
'testuser'
,
'X-Auth-Key'
:
'testuserpasswd'
})
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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment