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
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Laurent S
erp5
Commits
82eea1c9
Commit
82eea1c9
authored
Jun 20, 2012
by
Arnaud Fontaine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Browser.open()-like which does not actually visit the page.
parent
35a20958
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
0 deletions
+47
-0
erp5/util/testbrowser/browser.py
erp5/util/testbrowser/browser.py
+47
-0
No files found.
erp5/util/testbrowser/browser.py
View file @
82eea1c9
...
...
@@ -207,6 +207,53 @@ class Browser(ExtendedTestBrowser):
self
.
_logger
.
debug
(
"Opening: "
+
url_or_path
)
super
(
Browser
,
self
).
open
(
url_or_path
,
data
)
def
openNoVisit
(
self
,
url_or_path
,
data
=
None
,
site_relative
=
True
):
"""
Copy/paste from zope.testbrowser.Browser.open() to allow opening an URL
without changing the current page. See L{open}.
@see zope.testbrowser.interfaces.IBrowser
"""
if
site_relative
:
# In case url_or_path is an absolute URL, urljoin() will return
# it, otherwise it is a relative path and will be concatenated to
# ERP5 base URL
url_or_path
=
urljoin
(
self
.
_erp5_base_url
,
url_or_path
)
import
mechanize
if
isinstance
(
data
,
dict
):
data
=
urllib
.
urlencode
(
data
)
response
=
None
url_or_path
=
str
(
url_or_path
)
self
.
_logger
.
debug
(
"Opening: "
+
url_or_path
)
self
.
_start_timer
()
try
:
try
:
try
:
response
=
self
.
mech_browser
.
open_novisit
(
url_or_path
,
data
)
except
Exception
,
e
:
fix_exception_name
(
e
)
raise
except
mechanize
.
HTTPError
,
e
:
if
e
.
code
>=
200
and
e
.
code
<=
299
:
# 200s aren't really errors
pass
elif
self
.
raiseHttpErrors
:
raise
finally
:
self
.
_stop_timer
()
# if the headers don't have a status, I suppose there can't be an error
if
'Status'
in
self
.
headers
:
code
,
msg
=
self
.
headers
[
'Status'
].
split
(
' '
,
1
)
code
=
int
(
code
)
if
self
.
raiseHttpErrors
and
code
>=
400
:
raise
mechanize
.
HTTPError
(
url_or_path
,
code
,
msg
,
self
.
headers
,
fp
=
None
)
return
response
def
randomSleep
(
self
,
minimum
,
maximum
):
"""
Allow to randomly sleep in seconds in the interval [minimum,
...
...
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