Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Cédric Le Ninivin
erp5
Commits
d45bf6ab
Commit
d45bf6ab
authored
Jul 01, 2019
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
oauth_google_login: modernize test with mock
parent
7f920b14
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
16 deletions
+32
-16
bt5/erp5_oauth_google_login/TestTemplateItem/portal_components/test.erp5.testGoogleLogin.py
...mplateItem/portal_components/test.erp5.testGoogleLogin.py
+32
-16
No files found.
bt5/erp5_oauth_google_login/TestTemplateItem/portal_components/test.erp5.testGoogleLogin.py
View file @
d45bf6ab
...
@@ -26,10 +26,11 @@
...
@@ -26,10 +26,11 @@
##############################################################################
##############################################################################
import
uuid
import
uuid
import
mock
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
erp5.component.extension
import
GoogleLoginUtility
from
Products.ERP5Type.tests.utils
import
createZODBPythonScript
from
Products.ERP5Type.tests.utils
import
createZODBPythonScript
CLIENT_ID
=
"a1b2c3"
CLIENT_ID
=
"a1b2c3"
SECRET_KEY
=
"3c2ba1"
SECRET_KEY
=
"3c2ba1"
ACCESS_TOKEN
=
"T1234"
ACCESS_TOKEN
=
"T1234"
...
@@ -87,28 +88,15 @@ def getUserEntry(access_token):
...
@@ -87,28 +88,15 @@ def getUserEntry(access_token):
"reference"
:
getUserId
(
None
)
"reference"
:
getUserId
(
None
)
}
}
GoogleLoginUtility_getAccessTokenFromCode
=
GoogleLoginUtility
.
getAccessTokenFromCode
GoogleLoginUtility_getUserEntry
=
GoogleLoginUtility
.
getUserEntry
class
TestGoogleLogin
(
ERP5TypeTestCase
):
class
TestGoogleLogin
(
ERP5TypeTestCase
):
def
getTitle
(
self
):
return
"Test Google Login"
def
beforeTearDown
(
self
):
GoogleLoginUtility
.
getAccessTokenFromCode
=
GoogleLoginUtility_getAccessTokenFromCode
GoogleLoginUtility
.
getUserEntry
=
GoogleLoginUtility_getUserEntry
def
afterSetUp
(
self
):
def
afterSetUp
(
self
):
"""
"""
This is ran before anything, used to set the environment
This is ran before anything, used to set the environment
"""
"""
self
.
login
()
self
.
login
()
self
.
portal
.
TemplateTool_checkGoogleExtractionPluginExistenceConsistency
(
fixit
=
True
)
self
.
portal
.
TemplateTool_checkGoogleExtractionPluginExistenceConsistency
(
fixit
=
True
)
# Patch extension to avoid external connection
GoogleLoginUtility
.
getUserId
=
getUserId
GoogleLoginUtility
.
getAccessTokenFromCode
=
getAccessTokenFromCode
GoogleLoginUtility
.
getUserEntry
=
getUserEntry
self
.
dummy_connector_id
=
"test_google_connector"
self
.
dummy_connector_id
=
"test_google_connector"
portal_catalog
=
self
.
portal
.
portal_catalog
portal_catalog
=
self
.
portal
.
portal_catalog
...
@@ -154,7 +142,21 @@ class TestGoogleLogin(ERP5TypeTestCase):
...
@@ -154,7 +142,21 @@ class TestGoogleLogin(ERP5TypeTestCase):
# (the secure flag is only set if we accessed through https)
# (the secure flag is only set if we accessed through https)
request
.
setServerURL
(
'https'
,
'example.com'
)
request
.
setServerURL
(
'https'
,
'example.com'
)
self
.
portal
.
ERP5Site_receiveGoogleCallback
(
code
=
CODE
)
with
mock
.
patch
(
'erp5.component.extension.GoogleLoginUtility.getAccessTokenFromCode'
,
side_effect
=
getAccessTokenFromCode
,
)
as
getAccessTokenFromCode_mock
,
\
mock
.
patch
(
'erp5.component.extension.GoogleLoginUtility.getUserEntry'
,
side_effect
=
getUserEntry
)
as
getUserEntry_mock
:
getAccessTokenFromCode_mock
.
func_code
=
getAccessTokenFromCode
.
func_code
getUserEntry_mock
.
func_code
=
getUserEntry
.
func_code
self
.
portal
.
ERP5Site_receiveGoogleCallback
(
code
=
CODE
)
getAccessTokenFromCode_mock
.
assert_called_once
()
getUserEntry_mock
.
assert_called_once
()
ac_cookie
,
=
[
v
for
(
k
,
v
)
in
response
.
listHeaders
()
if
k
.
lower
()
==
'set-cookie'
and
'__ac_google_hash='
in
v
]
ac_cookie
,
=
[
v
for
(
k
,
v
)
in
response
.
listHeaders
()
if
k
.
lower
()
==
'set-cookie'
and
'__ac_google_hash='
in
v
]
self
.
assertIn
(
'; Secure'
,
ac_cookie
)
self
.
assertIn
(
'; Secure'
,
ac_cookie
)
self
.
assertIn
(
'; HTTPOnly'
,
ac_cookie
)
self
.
assertIn
(
'; HTTPOnly'
,
ac_cookie
)
...
@@ -209,7 +211,21 @@ context.portal_alarms.accept_submitted_credentials.activeSense()
...
@@ -209,7 +211,21 @@ context.portal_alarms.accept_submitted_credentials.activeSense()
return credential_request
return credential_request
"""
)
"""
)
self
.
logout
()
self
.
logout
()
response
=
self
.
portal
.
ERP5Site_receiveGoogleCallback
(
code
=
CODE
)
with
mock
.
patch
(
'erp5.component.extension.GoogleLoginUtility.getAccessTokenFromCode'
,
side_effect
=
getAccessTokenFromCode
,
)
as
getAccessTokenFromCode_mock
,
\
mock
.
patch
(
'erp5.component.extension.GoogleLoginUtility.getUserEntry'
,
side_effect
=
getUserEntry
)
as
getUserEntry_mock
:
getAccessTokenFromCode_mock
.
func_code
=
getAccessTokenFromCode
.
func_code
getUserEntry_mock
.
func_code
=
getUserEntry
.
func_code
response
=
self
.
portal
.
ERP5Site_receiveGoogleCallback
(
code
=
CODE
)
getAccessTokenFromCode_mock
.
assert_called_once
()
getUserEntry_mock
.
assert_called_once
()
google_hash
=
self
.
portal
.
REQUEST
.
RESPONSE
.
cookies
.
get
(
"__ac_google_hash"
)[
"value"
]
google_hash
=
self
.
portal
.
REQUEST
.
RESPONSE
.
cookies
.
get
(
"__ac_google_hash"
)[
"value"
]
self
.
assertEqual
(
"b01533abb684a658dc71c81da4e67546"
,
google_hash
)
self
.
assertEqual
(
"b01533abb684a658dc71c81da4e67546"
,
google_hash
)
self
.
assertEqual
(
self
.
portal
.
absolute_url
(),
response
)
self
.
assertEqual
(
self
.
portal
.
absolute_url
(),
response
)
...
...
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