Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
cloud
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
405dd1f1
authored
Jul 10, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: improve FakeRequestFactory
parent
0e906aea
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
8 deletions
+17
-8
circle/dashboard/tests/test_mockedviews.py
+17
-8
No files found.
circle/dashboard/tests/test_mockedviews.py
View file @
405dd1f1
...
...
@@ -16,13 +16,15 @@
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
import
unittest
import
warnings
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.core.signing
import
TimestampSigner
,
JSONSerializer
,
b64_encode
from
django.http
import
HttpRequest
,
Http404
from
django.http
import
HttpRequest
,
Http404
,
QueryDict
from
django.utils
import
baseconv
from
..models
import
Profile
...
...
@@ -238,26 +240,33 @@ class VmOperationViewTestCase(unittest.TestCase):
self
.
assertEquals
(
rend
.
status_code
,
200
)
def
FakeRequestFactory
(
*
args
,
**
kwargs
):
def
FakeRequestFactory
(
user
=
None
,
**
kwargs
):
''' FakeRequestFactory, FakeMessages and FakeRequestContext are good for
mocking out django views; they are MUCH faster than the Django test client.
'''
if
user
is
None
:
user
=
UserFactory
()
user
.
is_authenticated
=
lambda
:
kwargs
.
get
(
'authenticated'
,
True
)
user
.
is_superuser
=
kwargs
.
get
(
'superuser'
,
False
)
if
kwargs
.
get
(
'has_perms_mock'
,
False
):
user
.
is_authenticated
=
lambda
:
kwargs
.
pop
(
'authenticated'
,
True
)
user
.
is_superuser
=
kwargs
.
pop
(
'superuser'
,
False
)
if
kwargs
.
pop
(
'has_perms_mock'
,
False
):
user
.
has_perms
=
MagicMock
(
return_value
=
True
)
user
.
save
()
request
=
HttpRequest
()
request
.
user
=
user
request
.
session
=
kwargs
.
get
(
'session'
,
{})
request
.
session
=
kwargs
.
pop
(
'session'
,
{})
if
kwargs
.
get
(
'POST'
)
is
not
None
:
request
.
method
=
'POST'
request
.
POST
=
kwargs
.
get
(
'POST'
)
request
.
POST
=
QueryDict
(
''
,
mutable
=
True
)
request
.
POST
.
update
(
kwargs
.
pop
(
'POST'
))
else
:
request
.
method
=
'GET'
request
.
GET
=
kwargs
.
get
(
'GET'
,
{})
request
.
GET
=
QueryDict
(
''
,
mutable
=
True
)
request
.
GET
.
update
(
kwargs
.
pop
(
'GET'
,
{}))
if
len
(
kwargs
):
warnings
.
warn
(
"FakeRequestFactory kwargs unused: "
+
unicode
(
kwargs
))
return
request
...
...
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