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
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
414e19cd
authored
Oct 03, 2014
by
Paul Kilgo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
write tests for BaseKey
parent
0092e506
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
1 deletions
+53
-1
django_sshkey/tests.py
+53
-1
No files found.
django_sshkey/tests.py
View file @
414e19cd
...
@@ -31,7 +31,7 @@ from django.test.client import Client
...
@@ -31,7 +31,7 @@ from django.test.client import Client
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
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.models
import
UserKey
from
django_sshkey.models
import
UserKey
,
BaseKey
from
django_sshkey
import
settings
from
django_sshkey
import
settings
import
os
import
os
import
shutil
import
shutil
...
@@ -67,6 +67,9 @@ def ssh_fingerprint(pubkey_path):
...
@@ -67,6 +67,9 @@ def ssh_fingerprint(pubkey_path):
fingerprint
=
stdout
.
split
(
None
,
2
)[
1
]
fingerprint
=
stdout
.
split
(
None
,
2
)[
1
]
return
fingerprint
return
fingerprint
class
TestKey
(
BaseKey
):
pass
class
BaseTestCase
(
TestCase
):
class
BaseTestCase
(
TestCase
):
@classmethod
@classmethod
def
setUpClass
(
cls
):
def
setUpClass
(
cls
):
...
@@ -501,3 +504,52 @@ class UserKeyLookupTestCase(BaseTestCase):
...
@@ -501,3 +504,52 @@ class UserKeyLookupTestCase(BaseTestCase):
self
.
assertIn
(
'Content-Type'
,
response
)
self
.
assertIn
(
'Content-Type'
,
response
)
self
.
assertEqual
(
response
[
'Content-Type'
],
'text/plain'
)
self
.
assertEqual
(
response
[
'Content-Type'
],
'text/plain'
)
self
.
assertEqual
(
response
.
content
,
''
)
self
.
assertEqual
(
response
.
content
,
''
)
class
BaseKeyTestCase
(
BaseTestCase
):
@classmethod
def
setUpClass
(
cls
):
super
(
BaseKeyTestCase
,
cls
)
.
setUpClass
()
# key1 has a comment
cls
.
key1_path
=
os
.
path
.
join
(
cls
.
key_dir
,
'key1'
)
ssh_keygen
(
comment
=
'comment'
,
file
=
cls
.
key1_path
)
# key2 does not have a comment
cls
.
key2_path
=
os
.
path
.
join
(
cls
.
key_dir
,
'key2'
)
ssh_keygen
(
comment
=
''
,
file
=
cls
.
key2_path
)
def
test_same_key
(
self
):
key1
=
TestKey
(
name
=
'name'
,
key
=
open
(
self
.
key1_path
+
'.pub'
)
.
read
(),
)
key1
.
full_clean
()
key1
.
save
()
key2
=
TestKey
(
name
=
'name'
,
key
=
open
(
self
.
key2_path
+
'.pub'
)
.
read
(),
)
key2
.
full_clean
()
key2
.
save
()
def
test_no_key
(
self
):
key
=
TestKey
(
name
=
'name'
)
self
.
assertRaises
(
ValidationError
,
key
.
full_clean
)
def
test_key_noname_comment
(
self
):
key
=
TestKey
(
key
=
open
(
self
.
key1_path
+
'.pub'
)
.
read
())
key
.
full_clean
()
key
.
save
()
self
.
assertEqual
(
'comment'
,
key
.
name
)
def
test_key_noname_nocomment
(
self
):
key
=
TestKey
(
key
=
open
(
self
.
key2_path
+
'.pub'
)
.
read
())
self
.
assertRaises
(
ValidationError
,
key
.
full_clean
)
def
test_touch
(
self
):
import
datetime
key
=
TestKey
(
key
=
open
(
self
.
key1_path
+
'.pub'
)
.
read
())
key
.
full_clean
()
key
.
save
()
self
.
assertEqual
(
None
,
key
.
last_used
)
key
.
touch
()
key
.
save
()
self
.
assertIsInstance
(
key
.
last_used
,
datetime
.
datetime
)
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