Revision d495600d snf-cyclades-app/synnefo/userdata/tests.py

b/snf-cyclades-app/synnefo/userdata/tests.py
40 40
from django.utils import simplejson as json
41 41
from django.conf import settings
42 42
from django.core.urlresolvers import reverse
43
from mock import patch
43 44

  
44 45
from synnefo.userdata.models import *
45 46

  
46 47

  
48
def get_user_mock(request, *args, **kwargs):
49
    if request.META.get('HTTP_X_AUTH_TOKEN', None) == '0000':
50
        request.user_uniq = 'test'
51
        request.user = {'id': 'id',
52
                        'username': 'username',
53
                        'uuid': 'test'}
54

  
55

  
47 56
class AaiClient(Client):
48 57

  
49 58
    def request(self, **request):
50
        request['HTTP_X_AUTH_TOKEN'] = '0000'
51
        return super(AaiClient, self).request(**request)
59
        # mock the astakos authentication function
60
        with patch("synnefo.userdata.rest.get_user",
61
                   new=get_user_mock):
62
            with patch("synnefo.userdata.views.get_user",
63
                       new=get_user_mock):
64
                request['HTTP_X_AUTH_TOKEN'] = '0000'
65
                return super(AaiClient, self).request(**request)
66

  
52 67

  
53 68
class TestRestViews(TransactionTestCase):
54 69

  
......
57 72
    def setUp(self):
58 73
        settings.USERDATA_MAX_SSH_KEYS_PER_USER = 10
59 74

  
60
        def get_user_mock(request, *Args, **kwargs):
61
            if request.META.get('HTTP_X_AUTH_TOKEN', None) == '0000':
62
                request.user_uniq = 'test'
63
                request.user = {'id': 'id',
64
                                'username': 'username',
65
                                'uuid': 'test'}
66

  
67
        # mock the astakos authentication function
68
        from snf_django.lib import astakos
69
        astakos.get_user = get_user_mock
70

  
71 75
        settings.SKIP_SSH_VALIDATION = True
72 76
        self.client = AaiClient()
73 77
        self.user = 'test'

Also available in: Unified diff