Commit abee0c60 by Paul Kilgo

remove save calls where not necessary

parent a14a3504
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
from django.test import TestCase from django.test import TestCase
from django.test.client import Client from django.test.client import Client
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django_sshkey.forms import UserKeyForm from django_sshkey.forms import UserKeyForm
...@@ -108,32 +109,24 @@ class KeyCreationTestCase(BaseTestCase): ...@@ -108,32 +109,24 @@ class KeyCreationTestCase(BaseTestCase):
def test_private_key_fails(self): def test_private_key_fails(self):
key = Key( key = Key(
#user = self.user1,
#name = 'name',
key = open(self.key1_path).read(), key = open(self.key1_path).read(),
) )
self.assertRaises(ValidationError, key.full_clean) self.assertRaises(ValidationError, key.full_clean)
def test_invalid_key_fails(self): def test_invalid_key_fails(self):
key = Key( key = Key(
#user = self.user1,
#name = 'name',
key = 'ssh-rsa invalid', key = 'ssh-rsa invalid',
) )
self.assertRaises(ValidationError, key.full_clean) self.assertRaises(ValidationError, key.full_clean)
def test_key_with_options_fails(self): def test_key_with_options_fails(self):
key = Key( key = Key(
#user = self.user1,
#name = 'name',
key = 'command="foobar" ' + open(self.key1_path+'.pub').read(), key = 'command="foobar" ' + open(self.key1_path+'.pub').read(),
) )
self.assertRaises(ValidationError, key.full_clean) self.assertRaises(ValidationError, key.full_clean)
def test_multiple_keys_fails(self): def test_multiple_keys_fails(self):
key = Key( key = Key(
#user = self.user1,
#name = 'name',
key = open(self.key1_path+'.pub').read() \ key = open(self.key1_path+'.pub').read() \
+ open(self.key2_path+'.pub').read(), + open(self.key2_path+'.pub').read(),
) )
...@@ -142,41 +135,31 @@ class KeyCreationTestCase(BaseTestCase): ...@@ -142,41 +135,31 @@ class KeyCreationTestCase(BaseTestCase):
def test_fingerprint(self): def test_fingerprint(self):
fingerprint = ssh_fingerprint(self.key1_path+'.pub') fingerprint = ssh_fingerprint(self.key1_path+'.pub')
key = Key( key = Key(
#user = self.user1,
#name = 'name',
key = open(self.key1_path+'.pub').read(), key = open(self.key1_path+'.pub').read(),
) )
key.full_clean() key.full_clean()
key.save()
self.assertEqual(key.fingerprint, fingerprint) self.assertEqual(key.fingerprint, fingerprint)
def test_touch(self): def test_touch(self):
import datetime import datetime
key = Key( key = Key(
#user = self.user1, content_type = ContentType.objects.get_for_model(Key), # to satisfy foreign key
#name = 'name',
key = open(self.key1_path+'.pub').read(), key = open(self.key1_path+'.pub').read(),
) )
key.full_clean() key.full_clean()
key.save()
self.assertIsNone(key.last_used) self.assertIsNone(key.last_used)
key.touch() key.touch()
key.save()
self.assertIsInstance(key.last_used, datetime.datetime) self.assertIsInstance(key.last_used, datetime.datetime)
key.touch() key.touch()
def test_blank_key_fails(self): def test_blank_key_fails(self):
key = Key( key = Key(
#user = self.user1,
#name = 'name1',
key = '', key = '',
) )
self.assertRaises(ValidationError, key.full_clean) self.assertRaises(ValidationError, key.full_clean)
def test_ws_key_fails(self): def test_ws_key_fails(self):
key = Key( key = Key(
#user = self.user1,
#name = 'name1',
key = ' ', key = ' ',
) )
self.assertRaises(ValidationError, key.full_clean) self.assertRaises(ValidationError, key.full_clean)
...@@ -187,14 +170,12 @@ class KeyCreationTestCase(BaseTestCase): ...@@ -187,14 +170,12 @@ class KeyCreationTestCase(BaseTestCase):
key = open(self.key1_path + '.pub').read() key = open(self.key1_path + '.pub').read()
) )
key.full_clean() key.full_clean()
key.save()
self.assertEqual(key.fingerprint, unicode(key)) self.assertEqual(key.fingerprint, unicode(key))
def test_unicode2(self): def test_unicode2(self):
'''Without fingerprint.''' '''Without fingerprint.'''
contents = open(self.key1_path + '.pub').read() contents = open(self.key1_path + '.pub').read()
key = Key(key=contents) key = Key(key=contents)
key.save()
self.assertEqual(contents[:20] + '...', unicode(key)) self.assertEqual(contents[:20] + '...', unicode(key))
class ApplicationKeyTestCase(BaseTestCase): class ApplicationKeyTestCase(BaseTestCase):
...@@ -204,7 +185,7 @@ class ApplicationKeyTestCase(BaseTestCase): ...@@ -204,7 +185,7 @@ class ApplicationKeyTestCase(BaseTestCase):
# key1 has a comment # key1 has a comment
cls.key1_path = os.path.join(cls.key_dir, 'key1') cls.key1_path = os.path.join(cls.key_dir, 'key1')
ssh_keygen(comment='comment', file=cls.key1_path) ssh_keygen(comment='comment', file=cls.key1_path)
cls.key1 = Key(key=open(cls.key1_path + '.pub').read()) cls.key1 = TestApplicationKey.base(key=open(cls.key1_path + '.pub').read())
cls.key1.full_clean() cls.key1.full_clean()
cls.key1.save() cls.key1.save()
cls.app_key1 = TestApplicationKey(basekey=cls.key1) cls.app_key1 = TestApplicationKey(basekey=cls.key1)
...@@ -515,7 +496,7 @@ class KeyLookupTestCase(BaseTestCase): ...@@ -515,7 +496,7 @@ class KeyLookupTestCase(BaseTestCase):
def generate_key(name, user): def generate_key(name, user):
path = os.path.join(cls.key_dir, name) path = os.path.join(cls.key_dir, name)
ssh_keygen(file=path) ssh_keygen(file=path)
key = Key(key=open(path + '.pub').read()) key = UserKey.base(key=open(path + '.pub').read())
key.full_clean() key.full_clean()
key.save() key.save()
userkey = UserKey(basekey=key, name=name, user=user) userkey = UserKey(basekey=key, name=name, user=user)
......
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 sign in to comment