Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos-mynij-dev
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
Mynij
slapos-mynij-dev
Commits
5b82e789
Commit
5b82e789
authored
Aug 24, 2020
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
seleniumserver: use managed resources in tests
parent
139e2e74
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
66 deletions
+56
-66
software/seleniumserver/test/test.py
software/seleniumserver/test/test.py
+56
-66
No files found.
software/seleniumserver/test/test.py
View file @
5b82e789
...
@@ -34,8 +34,10 @@ import unittest
...
@@ -34,8 +34,10 @@ import unittest
import
urlparse
import
urlparse
import
base64
import
base64
import
hashlib
import
hashlib
import
logging
import
contextlib
import
contextlib
from
BaseHTTPServer
import
BaseHTTPRequestHandler
,
HTTPServer
from
BaseHTTPServer
import
BaseHTTPRequestHandler
from
io
import
BytesIO
from
io
import
BytesIO
import
paramiko
import
paramiko
...
@@ -48,81 +50,69 @@ from selenium.webdriver.support import expected_conditions as EC
...
@@ -48,81 +50,69 @@ from selenium.webdriver.support import expected_conditions as EC
from
selenium.webdriver.support.ui
import
WebDriverWait
from
selenium.webdriver.support.ui
import
WebDriverWait
from
slapos.testing.testcase
import
makeModuleSetUpAndTestCaseClass
from
slapos.testing.testcase
import
makeModuleSetUpAndTestCaseClass
from
slapos.testing.utils
import
findFreeTCPPort
,
ImageComparisonTestCase
from
slapos.testing.utils
import
findFreeTCPPort
,
ImageComparisonTestCase
,
ManagedHTTPServer
setUpModule
,
SeleniumServerTestCase
=
makeModuleSetUpAndTestCaseClass
(
setUpModule
,
SeleniumServerTestCase
=
makeModuleSetUpAndTestCaseClass
(
os
.
path
.
abspath
(
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'..'
,
'software.cfg'
)))
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'..'
,
'software.cfg'
)))
class
WebServer
(
ManagedHTTPServer
):
class
RequestHandler
(
BaseHTTPRequestHandler
):
"""Request handler for our test server.
The implemented server is:
- submit q and you'll get a page with q as title
- upload a file and the file content will be displayed in div.uploadedfile
"""
def
do_GET
(
self
):
self
.
send_response
(
200
)
self
.
end_headers
()
self
.
wfile
.
write
(
'''
<html>
<title>Test page</title>
<body>
<style> p { font-family: Arial; } </style>
<form action="/" method="POST" enctype="multipart/form-data">
<input name="q" type="text"></input>
<input name="f" type="file" ></input>
<input type="submit" value="I'm feeling lucky"></input>
</form>
<p>the quick brown fox jumps over the lazy dog</p>
</body>
</html>'''
)
def
do_POST
(
self
):
form
=
cgi
.
FieldStorage
(
fp
=
self
.
rfile
,
headers
=
self
.
headers
,
environ
=
{
'REQUEST_METHOD'
:
'POST'
,
'CONTENT_TYPE'
:
self
.
headers
[
'Content-Type'
],
})
self
.
send_response
(
200
)
self
.
end_headers
()
file_data
=
'no file'
if
form
.
has_key
(
'f'
):
file_data
=
form
[
'f'
].
file
.
read
()
self
.
wfile
.
write
(
'''
<html>
<title>%s</title>
<div>%s</div>
</html>
'''
%
(
form
[
'q'
].
value
,
file_data
))
log_message
=
logging
.
getLogger
(
__name__
+
'.WebServer'
).
info
class
WebServerMixin
(
object
):
class
WebServerMixin
(
object
):
"""Mixin class which provides a simple web server reachable at self.server_url
"""Mixin class which provides a simple web server reachable at self.server_url
"""
"""
def
setUp
(
self
):
def
setUp
(
self
):
"""Start a minimal web server.
self
.
server_url
=
self
.
getManagedResource
(
'web_server'
,
WebServer
).
url
"""
class
TestHandler
(
BaseHTTPRequestHandler
):
"""Request handler for our test server.
The implemented server is:
- submit q and you'll get a page with q as title
- upload a file and the file content will be displayed in div.uploadedfile
"""
def
log_message
(
self
,
*
args
,
**
kw
):
if
SeleniumServerTestCase
.
_debug
:
BaseHTTPRequestHandler
.
log_message
(
self
,
*
args
,
**
kw
)
def
do_GET
(
self
):
self
.
send_response
(
200
)
self
.
end_headers
()
self
.
wfile
.
write
(
'''
<html>
<title>Test page</title>
<body>
<style> p { font-family: Arial; } </style>
<form action="/" method="POST" enctype="multipart/form-data">
<input name="q" type="text"></input>
<input name="f" type="file" ></input>
<input type="submit" value="I'm feeling lucky"></input>
</form>
<p>the quick brown fox jumps over the lazy dog</p>
</body>
</html>'''
)
def
do_POST
(
self
):
form
=
cgi
.
FieldStorage
(
fp
=
self
.
rfile
,
headers
=
self
.
headers
,
environ
=
{
'REQUEST_METHOD'
:
'POST'
,
'CONTENT_TYPE'
:
self
.
headers
[
'Content-Type'
],
})
self
.
send_response
(
200
)
self
.
end_headers
()
file_data
=
'no file'
if
form
.
has_key
(
'f'
):
file_data
=
form
[
'f'
].
file
.
read
()
self
.
wfile
.
write
(
'''
<html>
<title>%s</title>
<div>%s</div>
</html>
'''
%
(
form
[
'q'
].
value
,
file_data
))
super
(
WebServerMixin
,
self
).
setUp
()
ip
=
os
.
environ
.
get
(
'SLAPOS_TEST_IPV4'
,
'127.0.1.1'
)
port
=
findFreeTCPPort
(
ip
)
server
=
HTTPServer
((
ip
,
port
),
TestHandler
)
self
.
server_process
=
multiprocessing
.
Process
(
target
=
server
.
serve_forever
)
self
.
server_process
.
start
()
self
.
server_url
=
'http://%s:%s/'
%
(
ip
,
port
)
def
tearDown
(
self
):
self
.
server_process
.
terminate
()
self
.
server_process
.
join
()
super
(
WebServerMixin
,
self
).
tearDown
()
class
BrowserCompatibilityMixin
(
WebServerMixin
):
class
BrowserCompatibilityMixin
(
WebServerMixin
):
...
...
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