Commit da990855 authored by Ilias Tsitsimpis's avatar Ilias Tsitsimpis

cyclades: Fix userdata tests

Mock the 'snf_django.lib.astakos.get_user' function.
The way it was done didn't seem to work.
parent f1dab536
......@@ -40,15 +40,30 @@ from django.core.urlresolvers import clear_url_caches
from django.utils import simplejson as json
from django.conf import settings
from django.core.urlresolvers import reverse
from mock import patch
from synnefo.userdata.models import *
def get_user_mock(request, *args, **kwargs):
if request.META.get('HTTP_X_AUTH_TOKEN', None) == '0000':
request.user_uniq = 'test'
request.user = {'id': 'id',
'username': 'username',
'uuid': 'test'}
class AaiClient(Client):
def request(self, **request):
request['HTTP_X_AUTH_TOKEN'] = '0000'
return super(AaiClient, self).request(**request)
# mock the astakos authentication function
with patch("synnefo.userdata.rest.get_user",
new=get_user_mock):
with patch("synnefo.userdata.views.get_user",
new=get_user_mock):
request['HTTP_X_AUTH_TOKEN'] = '0000'
return super(AaiClient, self).request(**request)
class TestRestViews(TransactionTestCase):
......@@ -57,17 +72,6 @@ class TestRestViews(TransactionTestCase):
def setUp(self):
settings.USERDATA_MAX_SSH_KEYS_PER_USER = 10
def get_user_mock(request, *Args, **kwargs):
if request.META.get('HTTP_X_AUTH_TOKEN', None) == '0000':
request.user_uniq = 'test'
request.user = {'id': 'id',
'username': 'username',
'uuid': 'test'}
# mock the astakos authentication function
from snf_django.lib import astakos
astakos.get_user = get_user_mock
settings.SKIP_SSH_VALIDATION = True
self.client = AaiClient()
self.user = 'test'
......
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