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

b/snf-cyclades-app/synnefo/userdata/tests.py
32 32
# or implied, of GRNET S.A.
33 33
#
34 34

  
35
from django import http
35 36
from django.test import TransactionTestCase
36 37
from django.conf import settings
37 38
from django.test.client import Client
......
54 55
    fixtures = ['users']
55 56

  
56 57
    def setUp(self):
58
        settings.USERDATA_MAX_SSH_KEYS_PER_USER = 10
59

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

  
62 67
        # mock the astakos authentication function
63 68
        from snf_django.lib import astakos
......
135 140
                                            'content':"""key 2 content"""}),
136 141
                                content_type='application/json')
137 142
        self.assertEqual(PublicKeyPair.objects.count(), 1)
138
        pk = PublicKeyPair.objects.get(pk=1)
143
        pk = PublicKeyPair.objects.get()
139 144
        self.assertEqual(pk.name, "key pair 2")
140 145
        self.assertEqual(pk.content, "key 2 content")
141 146

  
......
166 171
        new_key.full_clean()
167 172
        new_key.save()
168 173

  
174
    def test_generate_limit(self):
175
        settings.USERDATA_MAX_SSH_KEYS_PER_USER = 1
176
        resp = self.client.post(self.keys_url,
177
                                json.dumps({'name':'key1',
178
                                            'content':"""key 1 content"""}),
179
                                content_type='application/json')
180
        genpath = self.keys_url + "/generate"
181
        r = self.client.post(genpath)
182
        assert isinstance(r, http.HttpResponseServerError)
183

  
169 184
    def test_invalid_data(self):
170 185
        resp = self.client.post(self.keys_url,
171 186
                                json.dumps({'content':"""key 2 content"""}),

Also available in: Unified diff