Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
8e08e6c2
authored
Mar 28, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: test vm-activity detail view
parent
032c38d9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
0 deletions
+68
-0
circle/dashboard/tests/test_mockedviews.py
+67
-0
requirements/test.txt
+1
-0
No files found.
circle/dashboard/tests/test_mockedviews.py
0 → 100644
View file @
8e08e6c2
import
unittest
from
factory
import
Factory
,
Sequence
from
mock
import
patch
,
MagicMock
from
django.contrib.auth.models
import
User
# from django.core.exceptions import PermissionDenied
from
django.http
import
HttpRequest
,
Http404
from
dashboard.views
import
InstanceActivityDetail
,
InstanceActivity
class
ViewUserTestCase
(
unittest
.
TestCase
):
def
test_404
(
self
):
view
=
InstanceActivityDetail
.
as_view
()
request
=
FakeRequestFactory
(
superuser
=
True
)
with
self
.
assertRaises
(
Http404
):
view
(
request
,
pk
=
1234
)
def
test_not_superuser
(
self
):
request
=
FakeRequestFactory
(
superuser
=
False
)
with
patch
.
object
(
InstanceActivityDetail
,
'get_object'
)
as
go
:
go
.
return_value
=
MagicMock
(
spec
=
InstanceActivity
)
go
.
return_value
.
_meta
.
object_name
=
"InstanceActivity"
view
=
InstanceActivityDetail
.
as_view
()
self
.
assertEquals
(
view
(
request
,
pk
=
1234
)
.
status_code
,
302
)
def
test_found
(
self
):
request
=
FakeRequestFactory
(
superuser
=
True
)
with
patch
.
object
(
InstanceActivityDetail
,
'get_object'
)
as
go
:
act
=
MagicMock
(
spec
=
InstanceActivity
)
act
.
_meta
.
object_name
=
"InstanceActivity"
go
.
return_value
=
act
view
=
InstanceActivityDetail
.
as_view
()
self
.
assertEquals
(
view
(
request
,
pk
=
1234
)
.
render
()
.
status_code
,
200
)
def
FakeRequestFactory
(
*
args
,
**
kwargs
):
''' FakeRequestFactory, FakeMessages and FakeRequestContext are good for
mocking out django views; they are MUCH faster than the Django test client.
'''
user
=
UserFactory
()
user
.
is_authenticated
=
lambda
:
kwargs
.
get
(
'authenticated'
,
True
)
user
.
is_superuser
=
kwargs
.
get
(
'superuser'
,
False
)
request
=
HttpRequest
()
request
.
user
=
user
request
.
session
=
kwargs
.
get
(
'session'
,
{})
if
kwargs
.
get
(
'POST'
):
request
.
method
=
'POST'
request
.
POST
=
kwargs
.
get
(
'POST'
)
else
:
request
.
method
=
'GET'
request
.
POST
=
kwargs
.
get
(
'GET'
,
{})
return
request
class
UserFactory
(
Factory
):
''' using the excellent factory_boy library '''
FACTORY_FOR
=
User
username
=
Sequence
(
lambda
i
:
'test
%
d'
%
i
)
first_name
=
'John'
last_name
=
'Doe'
email
=
Sequence
(
lambda
i
:
'test
%
d@example.com'
%
i
)
requirements/test.txt
View file @
8e08e6c2
...
...
@@ -4,3 +4,4 @@ coverage==3.6
django-discover-runner==0.4
django-nose==1.2
mock==1.0.1
factory-boy==2.3.1
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