Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
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
93f6d382
authored
Jun 25, 2013
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
school: refactored view tests
parent
4127180b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
32 deletions
+61
-32
school/tests/test_views.py
+61
-32
No files found.
school/tests/test_views.py
View file @
93f6d382
...
@@ -3,7 +3,9 @@ from django.test import TestCase
...
@@ -3,7 +3,9 @@ from django.test import TestCase
from
django.test.client
import
Client
from
django.test.client
import
Client
from
django.contrib.auth.models
import
User
,
Group
as
AuthGroup
from
django.contrib.auth.models
import
User
,
Group
as
AuthGroup
from
django.core.exceptions
import
ValidationError
from
django.core.exceptions
import
ValidationError
from
django.core.urlresolvers
import
reverse
from
..models
import
create_user_profile
,
Person
,
Course
,
Semester
,
Group
from
..models
import
create_user_profile
,
Person
,
Course
,
Semester
,
Group
from
one.models
import
UserCloudDetails
class
ViewTestCase
(
TestCase
):
class
ViewTestCase
(
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
@@ -32,79 +34,106 @@ class ViewTestCase(TestCase):
...
@@ -32,79 +34,106 @@ class ViewTestCase(TestCase):
'email'
:
'test.user@testsite.hu'
,
'email'
:
'test.user@testsite.hu'
,
'affiliation'
:
';'
.
join
([
affiliation1
.
name
])}
'affiliation'
:
';'
.
join
([
affiliation1
.
name
])}
def
login
(
self
,
follow
=
False
):
url
=
reverse
(
'login'
)
resp
=
self
.
client
.
get
(
url
,
follow
=
follow
,
**
self
.
http_headers
)
try
:
username
=
self
.
http_headers
[
'niifPersonOrgID'
]
self
.
user
=
User
.
objects
.
get
(
username
=
username
)
except
KeyError
:
pass
except
User
.
DoesNotExist
:
pass
return
resp
def
test_logout
(
self
):
def
test_logout
(
self
):
resp
=
self
.
client
.
get
(
'/logout/'
,
follow
=
False
)
resp
=
self
.
client
.
get
(
reverse
(
'logout'
)
,
follow
=
False
)
self
.
assertEqual
(
302
,
resp
.
status_code
)
self
.
assertEqual
(
302
,
resp
.
status_code
)
def
test_login
(
self
):
def
test_login
(
self
):
resp
=
self
.
client
.
get
(
'/login/'
,
follow
=
True
,
**
self
.
http_headers
)
resp
=
self
.
login
(
follow
=
True
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
def
test_login_without_id
(
self
):
def
test_login_without_id
(
self
):
del
self
.
http_headers
[
'niifPersonOrgID'
]
del
self
.
http_headers
[
'niifPersonOrgID'
]
resp
=
self
.
client
.
get
(
'/login/'
,
follow
=
True
,
**
self
.
http_headers
)
resp
=
self
.
login
(
follow
=
True
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
(
url
,
_
)
=
resp
.
redirect_chain
[
0
]
(
url
,
_
)
=
resp
.
redirect_chain
[
0
]
self
.
assertIn
(
'/admin'
,
url
)
self
.
assertIn
(
'/admin'
,
url
)
def
test_login_without_email
(
self
):
def
test_login_without_email
(
self
):
del
self
.
http_headers
[
'email'
]
del
self
.
http_headers
[
'email'
]
resp
=
self
.
client
.
get
(
'/login/'
,
follow
=
True
,
**
self
.
http_headers
)
resp
=
self
.
login
(
follow
=
True
)
self
.
assertEqual
(
403
,
resp
.
status_code
)
self
.
assertEqual
(
403
,
resp
.
status_code
)
def
test_login_without_affiliation
(
self
):
def
test_login_without_affiliation
(
self
):
del
self
.
http_headers
[
'affiliation'
]
del
self
.
http_headers
[
'affiliation'
]
resp
=
self
.
client
.
get
(
'/login/'
,
follow
=
True
,
**
self
.
http_headers
)
resp
=
self
.
login
(
follow
=
True
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
def
test_login_without_group_for_affiliation
(
self
):
def
test_login_without_group_for_affiliation
(
self
):
self
.
group1
.
delete
()
self
.
group1
.
delete
()
resp
=
self
.
client
.
get
(
'/login/'
,
follow
=
True
,
**
self
.
http_headers
)
resp
=
self
.
login
(
follow
=
True
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
def
test_language
(
self
):
def
test_language
(
self
):
self
.
client
.
get
(
'/login/'
,
**
self
.
http_headers
)
self
.
login
()
u
=
User
.
objects
.
get
(
username
=
self
.
http_headers
[
'niifPersonOrgID'
])
p
=
Person
.
objects
.
get
(
user
=
self
.
user
)
p
=
Person
.
objects
.
get
(
user
=
u
)
lang
=
u'en'
if
p
.
language
==
u'hu'
else
u'hu'
lang
=
u'en'
if
p
.
language
==
u'hu'
else
u'hu'
url
=
reverse
(
'school.views.language'
,
kwargs
=
{
'lang'
:
lang
})
self
.
http_headers
[
'HTTP_REFERER'
]
=
'/'
self
.
http_headers
[
'HTTP_REFERER'
]
=
'/'
resp
=
self
.
client
.
get
(
'/language/
%
s/'
%
lang
,
follow
=
False
,
resp
=
self
.
client
.
get
(
url
,
follow
=
False
,
**
self
.
http_headers
)
**
self
.
http_headers
)
self
.
assertEqual
(
302
,
resp
.
status_code
)
self
.
assertEqual
(
302
,
resp
.
status_code
)
p
=
Person
.
objects
.
get
(
user
=
u
)
p
=
Person
.
objects
.
get
(
user
=
self
.
user
)
self
.
assertEqual
(
lang
,
p
.
language
)
self
.
assertEqual
(
lang
,
p
.
language
)
def
test_language_with_invalid_parameter
(
self
):
def
test_language_with_invalid_parameter
(
self
):
self
.
client
.
get
(
'/login/'
,
**
self
.
http_headers
)
self
.
login
()
u
=
User
.
objects
.
get
(
username
=
self
.
http_headers
[
'niifPersonOrgID'
])
lang_before
=
Person
.
objects
.
get
(
user
=
self
.
user
)
.
language
lang
=
u'nemvanez'
# invalid language
new_lang
=
u'nemvanez'
# invalid language
url
=
reverse
(
'school.views.language'
,
kwargs
=
{
'lang'
:
new_lang
})
self
.
http_headers
[
'HTTP_REFERER'
]
=
'/'
self
.
http_headers
[
'HTTP_REFERER'
]
=
'/'
resp
=
self
.
client
.
get
(
'/language/
%
s/'
%
lang
,
follow
=
False
,
resp
=
self
.
client
.
get
(
url
,
follow
=
False
,
**
self
.
http_headers
)
**
self
.
http_headers
)
self
.
assertEqual
(
302
,
resp
.
status_code
)
self
.
assertEqual
(
302
,
resp
.
status_code
)
p
=
Person
.
objects
.
get
(
user
=
u
)
p
=
Person
.
objects
.
get
(
user
=
self
.
user
)
self
.
assertEqual
(
lang
,
p
.
language
)
self
.
assertEqual
(
lang_before
,
p
.
language
)
# language didn't change
def
test_language_without_person_for_user
(
self
):
def
test_language_without_person_for_user
(
self
):
self
.
client
.
get
(
'/login/'
,
**
self
.
http_headers
)
self
.
login
(
)
u
=
User
.
objects
.
get
(
username
=
self
.
http_headers
[
'niifPersonOrgID'
]
)
Person
.
objects
.
get
(
user
=
self
.
user
)
.
delete
(
)
Person
.
objects
.
get
(
user
=
u
)
.
delete
()
new_lang
=
u'en'
lang
=
u'en'
url
=
reverse
(
'school.views.language'
,
kwargs
=
{
'lang'
:
new_lang
})
self
.
http_headers
[
'HTTP_REFERER'
]
=
'/'
self
.
http_headers
[
'HTTP_REFERER'
]
=
'/'
resp
=
self
.
client
.
get
(
'/language/
%
s/'
%
lang
,
follow
=
False
,
resp
=
self
.
client
.
get
(
url
,
follow
=
False
,
**
self
.
http_headers
)
**
self
.
http_headers
)
self
.
assertEqual
(
302
,
resp
.
status_code
)
self
.
assertEqual
(
302
,
resp
.
status_code
)
def
test_group_show
(
self
):
def
test_group_show
(
self
):
self
.
client
.
get
(
'/login/'
,
**
self
.
http_headers
)
self
.
login
()
resp
=
self
.
client
.
get
(
'/group/show/
%
s/'
%
self
.
group1
.
id
)
ucd
=
UserCloudDetails
.
objects
.
get
(
user
=
self
.
user
)
ucd
.
share_quota
=
10
ucd
.
save
()
gid
=
self
.
group1
.
id
url
=
reverse
(
'school.views.group_show'
,
kwargs
=
{
'gid'
:
gid
})
resp
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
self
.
assertEqual
(
200
,
resp
.
status_code
)
def
test_group_show_with_nonexistent_groupid
(
self
):
def
test_group_show_with_nonexistent_groupid
(
self
):
self
.
client
.
get
(
'/login/'
,
**
self
.
http_headers
)
self
.
login
(
)
gid
=
1337
# this should be the ID of a non-existent group,
gid
=
1337
# this should be the ID of a non-existent group,
# so if it exists, delete it!
Group
.
objects
.
filter
(
id
=
gid
)
.
delete
()
# so if it exists, delete it!
Group
.
objects
.
filter
(
id
=
gid
)
.
delete
(
)
url
=
reverse
(
'school.views.group_show'
,
kwargs
=
{
'gid'
:
gid
}
)
resp
=
self
.
client
.
get
(
'/group/show/
%
s/'
%
gid
)
resp
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
404
,
resp
.
status_code
)
self
.
assertEqual
(
404
,
resp
.
status_code
)
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