Revision c72a830d ui/userdata/tests.py

b/ui/userdata/tests.py
10 10
from django.test.client import Client
11 11
from django.core.urlresolvers import clear_url_caches
12 12
from django.utils import simplejson as json
13
from django.conf import settings
13 14

  
14 15
from synnefo.ui.userdata.models import User
15 16
from synnefo.ui.userdata.models import *
......
101 102
        # private key is base64 encoded
102 103
        base64.b64decode(private)
103 104

  
105
    def test_invalid_data(self):
106
        resp = self.client.post("/keys", json.dumps({'content':"""key 2 content"""}),
107
                content_type='application/json')
108

  
109
        self.assertEqual(resp.status_code, 500)
110
        self.assertEqual(resp.content, """{"non_field_key": "__all__", "errors": """
111
                                       """{"name": ["This field cannot be blank."]}}""")
112

  
113
        settings.MAX_SSH_KEYS_PER_USER = 2
114

  
115
        # test ssh limit
116
        resp = self.client.post("/keys", json.dumps({'name':'key1', 'content':"""key 1 content"""}),
117
                content_type='application/json')
118
        resp = self.client.post("/keys", json.dumps({'name':'key1', 'content':"""key 1 content"""}),
119
                content_type='application/json')
120
        resp = self.client.post("/keys", json.dumps({'name':'key1', 'content':"""key 1 content"""}),
121
                content_type='application/json')
122
        self.assertEqual(resp.status_code, 500)
123
        self.assertEqual(resp.content, """{"non_field_key": "__all__", "errors": """
124
                                       """{"__all__": ["SSH keys limit exceeded."]}}""")

Also available in: Unified diff