Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
django-sshkey
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
abee0c60
authored
Oct 09, 2014
by
Paul Kilgo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove save calls where not necessary
parent
a14a3504
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
23 deletions
+4
-23
django_sshkey/tests.py
+4
-23
No files found.
django_sshkey/tests.py
View file @
abee0c60
...
...
@@ -29,6 +29,7 @@
from
django.test
import
TestCase
from
django.test.client
import
Client
from
django.contrib.auth.models
import
User
from
django.contrib.contenttypes.models
import
ContentType
from
django.core.exceptions
import
ValidationError
from
django.core.urlresolvers
import
reverse
from
django_sshkey.forms
import
UserKeyForm
...
...
@@ -108,32 +109,24 @@ class KeyCreationTestCase(BaseTestCase):
def
test_private_key_fails
(
self
):
key
=
Key
(
#user = self.user1,
#name = 'name',
key
=
open
(
self
.
key1_path
)
.
read
(),
)
self
.
assertRaises
(
ValidationError
,
key
.
full_clean
)
def
test_invalid_key_fails
(
self
):
key
=
Key
(
#user = self.user1,
#name = 'name',
key
=
'ssh-rsa invalid'
,
)
self
.
assertRaises
(
ValidationError
,
key
.
full_clean
)
def
test_key_with_options_fails
(
self
):
key
=
Key
(
#user = self.user1,
#name = 'name',
key
=
'command="foobar" '
+
open
(
self
.
key1_path
+
'.pub'
)
.
read
(),
)
self
.
assertRaises
(
ValidationError
,
key
.
full_clean
)
def
test_multiple_keys_fails
(
self
):
key
=
Key
(
#user = self.user1,
#name = 'name',
key
=
open
(
self
.
key1_path
+
'.pub'
)
.
read
()
\
+
open
(
self
.
key2_path
+
'.pub'
)
.
read
(),
)
...
...
@@ -142,41 +135,31 @@ class KeyCreationTestCase(BaseTestCase):
def
test_fingerprint
(
self
):
fingerprint
=
ssh_fingerprint
(
self
.
key1_path
+
'.pub'
)
key
=
Key
(
#user = self.user1,
#name = 'name',
key
=
open
(
self
.
key1_path
+
'.pub'
)
.
read
(),
)
key
.
full_clean
()
key
.
save
()
self
.
assertEqual
(
key
.
fingerprint
,
fingerprint
)
def
test_touch
(
self
):
import
datetime
key
=
Key
(
#user = self.user1,
#name = 'name',
content_type
=
ContentType
.
objects
.
get_for_model
(
Key
),
# to satisfy foreign key
key
=
open
(
self
.
key1_path
+
'.pub'
)
.
read
(),
)
key
.
full_clean
()
key
.
save
()
self
.
assertIsNone
(
key
.
last_used
)
key
.
touch
()
key
.
save
()
self
.
assertIsInstance
(
key
.
last_used
,
datetime
.
datetime
)
key
.
touch
()
def
test_blank_key_fails
(
self
):
key
=
Key
(
#user = self.user1,
#name = 'name1',
key
=
''
,
)
self
.
assertRaises
(
ValidationError
,
key
.
full_clean
)
def
test_ws_key_fails
(
self
):
key
=
Key
(
#user = self.user1,
#name = 'name1',
key
=
' '
,
)
self
.
assertRaises
(
ValidationError
,
key
.
full_clean
)
...
...
@@ -187,14 +170,12 @@ class KeyCreationTestCase(BaseTestCase):
key
=
open
(
self
.
key1_path
+
'.pub'
)
.
read
()
)
key
.
full_clean
()
key
.
save
()
self
.
assertEqual
(
key
.
fingerprint
,
unicode
(
key
))
def
test_unicode2
(
self
):
'''Without fingerprint.'''
contents
=
open
(
self
.
key1_path
+
'.pub'
)
.
read
()
key
=
Key
(
key
=
contents
)
key
.
save
()
self
.
assertEqual
(
contents
[:
20
]
+
'...'
,
unicode
(
key
))
class
ApplicationKeyTestCase
(
BaseTestCase
):
...
...
@@ -204,7 +185,7 @@ class ApplicationKeyTestCase(BaseTestCase):
# key1 has a comment
cls
.
key1_path
=
os
.
path
.
join
(
cls
.
key_dir
,
'key1'
)
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
.
save
()
cls
.
app_key1
=
TestApplicationKey
(
basekey
=
cls
.
key1
)
...
...
@@ -515,7 +496,7 @@ class KeyLookupTestCase(BaseTestCase):
def
generate_key
(
name
,
user
):
path
=
os
.
path
.
join
(
cls
.
key_dir
,
name
)
ssh_keygen
(
file
=
path
)
key
=
Key
(
key
=
open
(
path
+
'.pub'
)
.
read
())
key
=
UserKey
.
base
(
key
=
open
(
path
+
'.pub'
)
.
read
())
key
.
full_clean
()
key
.
save
()
userkey
=
UserKey
(
basekey
=
key
,
name
=
name
,
user
=
user
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment