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
Labels
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Romain Courteaud
erp5
Commits
fd308ae7
Commit
fd308ae7
authored
Jul 01, 2019
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
oauth_facebook_login: modernize test with mock
parent
6f400ae6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
16 deletions
+23
-16
bt5/erp5_oauth_facebook_login/TestTemplateItem/portal_components/test.erp5.testFacebookLogin.py
...lateItem/portal_components/test.erp5.testFacebookLogin.py
+23
-16
No files found.
bt5/erp5_oauth_facebook_login/TestTemplateItem/portal_components/test.erp5.testFacebookLogin.py
View file @
fd308ae7
...
...
@@ -26,8 +26,8 @@
##############################################################################
import
uuid
import
mock
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
from
erp5.component.extension
import
FacebookLoginUtility
from
Products.ERP5Type.tests.utils
import
createZODBPythonScript
CLIENT_ID
=
"a1b2c3"
...
...
@@ -50,28 +50,15 @@ def getUserEntry(access_token):
'reference'
:
getUserId
(
None
),
'email'
:
"dummy@example.org"
}
FacebookLoginUtility_getAccessTokenFromCode
=
FacebookLoginUtility
.
getAccessTokenFromCode
FacebookLoginUtility_getUserEntry
=
FacebookLoginUtility
.
getUserEntry
class
TestFacebookLogin
(
ERP5TypeTestCase
):
def
getTitle
(
self
):
return
"Test Facebook Login"
def
beforeTearDown
(
self
):
FacebookLoginUtility
.
getAccessTokenFromCode
=
FacebookLoginUtility_getAccessTokenFromCode
FacebookLoginUtility
.
getUserEntry
=
FacebookLoginUtility_getUserEntry
def
afterSetUp
(
self
):
"""
This is ran before anything, used to set the environment
"""
self
.
login
()
self
.
portal
.
TemplateTool_checkFacebookExtractionPluginExistenceConsistency
(
fixit
=
True
)
# Patch extension to avoid external connection
FacebookLoginUtility
.
getUserId
=
getUserId
FacebookLoginUtility
.
getAccessTokenFromCode
=
getAccessTokenFromCode
FacebookLoginUtility
.
getUserEntry
=
getUserEntry
self
.
dummy_connector_id
=
"test_facebook_connector"
portal_catalog
=
self
.
portal
.
portal_catalog
...
...
@@ -116,8 +103,18 @@ class TestFacebookLogin(ERP5TypeTestCase):
response
=
request
.
RESPONSE
# (the secure flag is only set if we accessed through https)
request
.
setServerURL
(
'https'
,
'example.com'
)
with
mock
.
patch
(
'erp5.component.extension.FacebookLoginUtility.getAccessTokenFromCode'
,
side_effect
=
getAccessTokenFromCode
,
)
as
getAccessTokenFromCode_mock
,
\
mock
.
patch
(
'erp5.component.extension.FacebookLoginUtility.getUserEntry'
,
side_effect
=
getUserEntry
)
as
getUserEntry_mock
:
getAccessTokenFromCode_mock
.
func_code
=
getAccessTokenFromCode
.
func_code
getUserEntry_mock
.
func_code
=
getUserEntry
.
func_code
self
.
portal
.
ERP5Site_callbackFacebookLogin
(
code
=
CODE
)
self
.
portal
.
ERP5Site_callbackFacebookLogin
(
code
=
CODE
)
ac_cookie
,
=
[
v
for
(
k
,
v
)
in
response
.
listHeaders
()
if
k
.
lower
()
==
'set-cookie'
and
'__ac_facebook_hash='
in
v
]
self
.
assertIn
(
'; Secure'
,
ac_cookie
)
self
.
assertIn
(
'; HTTPOnly'
,
ac_cookie
)
...
...
@@ -171,7 +168,17 @@ context.portal_alarms.accept_submitted_credentials.activeSense()
return credential_request
"""
)
self
.
logout
()
response
=
self
.
portal
.
ERP5Site_callbackFacebookLogin
(
code
=
CODE
)
with
mock
.
patch
(
'erp5.component.extension.FacebookLoginUtility.getAccessTokenFromCode'
,
side_effect
=
getAccessTokenFromCode
,
)
as
getAccessTokenFromCode_mock
,
\
mock
.
patch
(
'erp5.component.extension.FacebookLoginUtility.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_callbackFacebookLogin
(
code
=
CODE
)
facebook_hash
=
self
.
portal
.
REQUEST
.
RESPONSE
.
cookies
.
get
(
"__ac_facebook_hash"
)[
"value"
]
self
.
assertEqual
(
"8cec04e21e927f1023f4f4980ec11a77"
,
facebook_hash
)
# The # is because we workaround facebook adding #_=_ in return URL
...
...
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