Commit a6ffe515 authored by Ilias Tsitsimpis's avatar Ilias Tsitsimpis

cyclades: pep8 fixes

parent da990855
......@@ -36,13 +36,11 @@ from django import http
from django.test import TransactionTestCase
from django.conf import settings
from django.test.client import Client
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 *
from synnefo.userdata.models import PublicKeyPair
def get_user_mock(request, *args, **kwargs):
......@@ -82,17 +80,17 @@ class TestRestViews(TransactionTestCase):
self.assertEqual(resp.content, "[]")
PublicKeyPair.objects.create(user=self.user, name="key pair 1",
content="content1")
content="content1")
resp = self.client.get(self.keys_url)
resp_list = json.loads(resp.content);
resp_list = json.loads(resp.content)
exp_list = [{"content": "content1", "id": 1,
"uri": self.keys_url + "/1", "name": "key pair 1",
"fingerprint": "unknown fingerprint"}]
"uri": self.keys_url + "/1", "name": "key pair 1",
"fingerprint": "unknown fingerprint"}]
self.assertEqual(resp_list, exp_list)
PublicKeyPair.objects.create(user=self.user, name="key pair 2",
content="content2")
content="content2")
resp = self.client.get(self.keys_url)
resp_list = json.loads(resp.content)
......@@ -112,9 +110,9 @@ class TestRestViews(TransactionTestCase):
# create a public key
PublicKeyPair.objects.create(user=self.user, name="key pair 1",
content="content1")
content="content1")
resp = self.client.get(self.keys_url + "/1")
resp_dict = json.loads(resp.content);
resp_dict = json.loads(resp.content)
exp_dict = {"content": "content1", "id": 1,
"uri": self.keys_url + "/1", "name": "key pair 1",
"fingerprint": "unknown fingerprint"}
......@@ -122,7 +120,7 @@ class TestRestViews(TransactionTestCase):
# update
resp = self.client.put(self.keys_url + "/1",
json.dumps({'name':'key pair 1 new name'}),
json.dumps({'name': 'key pair 1 new name'}),
content_type='application/json')
pk = PublicKeyPair.objects.get(pk=1)
......@@ -140,8 +138,8 @@ class TestRestViews(TransactionTestCase):
# test rest create
resp = self.client.post(self.keys_url,
json.dumps({'name':'key pair 2',
'content':"""key 2 content"""}),
json.dumps({'name': 'key pair 2',
'content': """key 2 content"""}),
content_type='application/json')
self.assertEqual(PublicKeyPair.objects.count(), 1)
pk = PublicKeyPair.objects.get()
......@@ -156,11 +154,11 @@ class TestRestViews(TransactionTestCase):
self.assertNotEqual(resp, "")
data = json.loads(resp.content)
self.assertEqual(data.has_key('private'), True)
self.assertEqual(data.has_key('private'), True)
self.assertEqual('private' in data, True)
self.assertEqual('private' in data, True)
# public key is base64 encoded
base64.b64decode(data['public'].replace("ssh-rsa ",""))
base64.b64decode(data['public'].replace("ssh-rsa ", ""))
# remove header/footer
private = "".join(data['private'].split("\n")[1:-1])
......@@ -177,39 +175,40 @@ class TestRestViews(TransactionTestCase):
def test_generate_limit(self):
settings.USERDATA_MAX_SSH_KEYS_PER_USER = 1
resp = self.client.post(self.keys_url,
json.dumps({'name':'key1',
'content':"""key 1 content"""}),
content_type='application/json')
self.client.post(self.keys_url,
json.dumps({'name': 'key1',
'content': """key 1 content"""}),
content_type='application/json')
genpath = self.keys_url + "/generate"
r = self.client.post(genpath)
assert isinstance(r, http.HttpResponseServerError)
def test_invalid_data(self):
resp = self.client.post(self.keys_url,
json.dumps({'content':"""key 2 content"""}),
json.dumps({'content': """key 2 content"""}),
content_type='application/json')
self.assertEqual(resp.status_code, 500)
self.assertEqual(resp.content, """{"non_field_key": "__all__", "errors": """
"""{"name": ["This field cannot be blank."]}}""")
self.assertEqual(resp.content,
"""{"non_field_key": "__all__", "errors": """
"""{"name": ["This field cannot be blank."]}}""")
settings.USERDATA_MAX_SSH_KEYS_PER_USER = 2
# test ssh limit
resp = self.client.post(self.keys_url,
json.dumps({'name':'key1',
'content':"""key 1 content"""}),
json.dumps({'name': 'key1',
'content': """key 1 content"""}),
content_type='application/json')
resp = self.client.post(self.keys_url,
json.dumps({'name':'key1',
'content':"""key 1 content"""}),
json.dumps({'name': 'key1',
'content': """key 1 content"""}),
content_type='application/json')
resp = self.client.post(self.keys_url,
json.dumps({'name':'key1',
'content':"""key 1 content"""}),
json.dumps({'name': 'key1',
'content': """key 1 content"""}),
content_type='application/json')
self.assertEqual(resp.status_code, 500)
self.assertEqual(resp.content, """{"non_field_key": "__all__", "errors": """
"""{"__all__": ["SSH keys limit exceeded."]}}""")
self.assertEqual(resp.content,
"""{"non_field_key": "__all__", "errors": """
"""{"__all__": ["SSH keys limit exceeded."]}}""")
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