Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
107
Merge Requests
107
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
slapos
Commits
0c9f87f5
Commit
0c9f87f5
authored
May 24, 2021
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
software/theia: Improve tests
parent
a4f7af38
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
63 deletions
+68
-63
software/theia/test/test.py
software/theia/test/test.py
+68
-63
No files found.
software/theia/test/test.py
View file @
0c9f87f5
...
@@ -67,12 +67,21 @@ class TestTheia(TheiaTestCase):
...
@@ -67,12 +67,21 @@ class TestTheia(TheiaTestCase):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
connection_parameters
=
self
.
computer_partition
.
getConnectionParameterDict
()
self
.
connection_parameters
=
self
.
computer_partition
.
getConnectionParameterDict
()
def
get
(
self
,
url
,
expect_code
=
requests
.
codes
.
ok
):
resp
=
requests
.
get
(
url
,
verify
=
False
)
self
.
assertEqual
(
expect_code
,
resp
.
status_code
,
'%s returned %d instead of %d'
%
(
url
,
resp
.
status_code
,
expect_code
),
)
return
resp
def
test_backend_http_get
(
self
):
def
test_backend_http_get
(
self
):
resp
=
requests
.
get
(
self
.
connection_parameters
[
'backend-url'
],
verify
=
False
)
backend_url
=
self
.
connection_parameters
[
'backend-url'
]
self
.
assertEqual
(
requests
.
codes
.
unauthorized
,
resp
.
status_code
)
self
.
get
(
backend_url
,
requests
.
codes
.
unauthorized
)
# with login/password, this is allowed
# with login/password, this is allowed
parsed_url
=
urlparse
(
self
.
connection_parameters
[
'backend-url'
]
)
parsed_url
=
urlparse
(
backend_url
)
authenticated_url
=
parsed_url
.
_replace
(
authenticated_url
=
parsed_url
.
_replace
(
netloc
=
'{}:{}@[{}]:{}'
.
format
(
netloc
=
'{}:{}@[{}]:{}'
.
format
(
self
.
connection_parameters
[
'username'
],
self
.
connection_parameters
[
'username'
],
...
@@ -80,12 +89,11 @@ class TestTheia(TheiaTestCase):
...
@@ -80,12 +89,11 @@ class TestTheia(TheiaTestCase):
parsed_url
.
hostname
,
parsed_url
.
hostname
,
parsed_url
.
port
,
parsed_url
.
port
,
)).
geturl
()
)).
geturl
()
resp
=
requests
.
get
(
authenticated_url
,
verify
=
False
)
self
.
get
(
authenticated_url
)
self
.
assertEqual
(
requests
.
codes
.
ok
,
resp
.
status_code
)
def
test_http_get
(
self
):
def
test_http_get
(
self
):
resp
=
requests
.
get
(
self
.
connection_parameters
[
'url'
],
verify
=
False
)
url
=
self
.
connection_parameters
[
'url'
]
self
.
assertEqual
(
requests
.
codes
.
unauthorized
,
resp
.
status_code
)
self
.
get
(
url
,
requests
.
codes
.
unauthorized
)
# with login/password, this is allowed
# with login/password, this is allowed
parsed_url
=
urlparse
(
self
.
connection_parameters
[
'url'
])
parsed_url
=
urlparse
(
self
.
connection_parameters
[
'url'
])
...
@@ -96,33 +104,28 @@ class TestTheia(TheiaTestCase):
...
@@ -96,33 +104,28 @@ class TestTheia(TheiaTestCase):
parsed_url
.
hostname
,
parsed_url
.
hostname
,
parsed_url
.
port
,
parsed_url
.
port
,
)).
geturl
()
)).
geturl
()
resp
=
requests
.
get
(
authenticated_url
,
verify
=
False
)
self
.
get
(
authenticated_url
)
self
.
assertEqual
(
requests
.
codes
.
ok
,
resp
.
status_code
)
# there's a public folder to serve file
# there's a public folder to serve file
with
open
(
'{}/srv/frontend-static/public/test_file'
.
format
(
with
open
(
'{}/srv/frontend-static/public/test_file'
.
format
(
self
.
computer_partition_root_path
),
'w'
)
as
f
:
self
.
computer_partition_root_path
),
'w'
)
as
f
:
f
.
write
(
"hello"
)
f
.
write
(
"hello"
)
resp
=
requests
.
get
(
urljoin
(
authenticated_url
,
'/public/'
),
verify
=
False
)
resp
=
self
.
get
(
urljoin
(
authenticated_url
,
'/public/'
)
)
self
.
assertIn
(
'test_file'
,
resp
.
text
)
self
.
assertIn
(
'test_file'
,
resp
.
text
)
resp
=
requests
.
get
(
resp
=
self
.
get
(
urljoin
(
authenticated_url
,
'/public/test_file'
))
urljoin
(
authenticated_url
,
'/public/test_file'
),
verify
=
False
)
self
.
assertEqual
(
'hello'
,
resp
.
text
)
self
.
assertEqual
(
'hello'
,
resp
.
text
)
# there's a (not empty) favicon
# there's a (not empty) favicon
resp
=
requests
.
get
(
resp
=
self
.
get
(
urljoin
(
authenticated_url
,
'/favicon.ico'
))
urljoin
(
authenticated_url
,
'/favicon.ico'
),
verify
=
False
)
self
.
assertEqual
(
requests
.
codes
.
ok
,
resp
.
status_code
)
self
.
assertTrue
(
resp
.
raw
)
self
.
assertTrue
(
resp
.
raw
)
# there is a CSS referencing fonts
# there is a CSS referencing fonts
css_text
=
requests
.
get
(
urljoin
(
authenticated_url
,
'/css/slapos.css'
),
verify
=
False
).
text
css_text
=
self
.
get
(
urljoin
(
authenticated_url
,
'/css/slapos.css'
)
).
text
css_urls
=
re
.
findall
(
r'url\
([
\'"]+([^
\
)]+)[
\
'"
]
+
\
)
', css_text)
css_urls
=
re
.
findall
(
r'url\
([
\'"]+([^
\
)]+)[
\
'"
]
+
\
)
', css_text)
self.assertTrue(css_urls)
self.assertTrue(css_urls)
# and fonts are served
# and fonts are served
for url in css_urls:
for url in css_urls:
resp = requests.get(urljoin(authenticated_url, url), verify=False)
resp = self.get(urljoin(authenticated_url, url))
self.assertEqual(requests.codes.ok, resp.status_code)
self.assertTrue(resp.raw)
self.assertTrue(resp.raw)
def test_theia_slapos(self):
def test_theia_slapos(self):
...
@@ -281,7 +284,7 @@ class TestTheiaEnv(TheiaTestCase):
...
@@ -281,7 +284,7 @@ class TestTheiaEnv(TheiaTestCase):
}
}
def
test_theia_env
(
self
):
def
test_theia_env
(
self
):
"""Make sure environment variables are the same wether we use shell or supervisor services.
"""Make sure environment variables are the same w
h
ether we use shell or supervisor services.
"""
"""
# The path of the env.json file expected to be generated by building the dummy software release
# The path of the env.json file expected to be generated by building the dummy software release
env_json_path
=
os
.
path
.
join
(
self
.
computer_partition_root_path
,
'srv'
,
'runner'
,
'software'
,
'env.json'
)
env_json_path
=
os
.
path
.
join
(
self
.
computer_partition_root_path
,
'srv'
,
'runner'
,
'software'
,
'env.json'
)
...
@@ -303,6 +306,7 @@ class TestTheiaEnv(TheiaTestCase):
...
@@ -303,6 +306,7 @@ class TestTheiaEnv(TheiaTestCase):
# Start a theia shell that inherits the environment of the theia process
# Start a theia shell that inherits the environment of the theia process
# This simulates the environment of a shell launched from the browser application
# This simulates the environment of a shell launched from the browser application
theia_shell_process
=
pexpect
.
spawnu
(
'{}/bin/theia-shell'
.
format
(
self
.
computer_partition_root_path
),
env
=
theia_env
)
theia_shell_process
=
pexpect
.
spawnu
(
'{}/bin/theia-shell'
.
format
(
self
.
computer_partition_root_path
),
env
=
theia_env
)
try
:
theia_shell_process
.
expect_exact
(
'Standalone SlapOS for computer `slaprunner` activated'
)
theia_shell_process
.
expect_exact
(
'Standalone SlapOS for computer `slaprunner` activated'
)
# Launch slapos node software from theia shell
# Launch slapos node software from theia shell
...
@@ -318,7 +322,7 @@ class TestTheiaEnv(TheiaTestCase):
...
@@ -318,7 +322,7 @@ class TestTheiaEnv(TheiaTestCase):
os
.
remove
(
env_json_path
)
os
.
remove
(
env_json_path
)
# Launch slapos node software service from the embedded supervisord.
# Launch slapos node software service from the embedded supervisord.
# Note that we have two services, slapos-not-software and slapos-not
-software-all
# Note that we have two services, slapos-node-software and slapos-node
-software-all
# The later uses --all which is what we want to use here, because the software
# The later uses --all which is what we want to use here, because the software
# is already installed and we want to install it again, this time from supervisor
# is already installed and we want to install it again, this time from supervisor
embedded_run_path
=
os
.
path
.
join
(
self
.
computer_partition_root_path
,
'srv'
,
'runner'
,
'var'
,
'run'
)
embedded_run_path
=
os
.
path
.
join
(
self
.
computer_partition_root_path
,
'srv'
,
'runner'
,
'var'
,
'run'
)
...
@@ -344,6 +348,7 @@ class TestTheiaEnv(TheiaTestCase):
...
@@ -344,6 +348,7 @@ class TestTheiaEnv(TheiaTestCase):
self
.
assertEqual
(
theia_shell_env
[
'SLAPOS_CLIENT_CONFIGURATION'
],
supervisord_env
[
'SLAPOS_CLIENT_CONFIGURATION'
])
self
.
assertEqual
(
theia_shell_env
[
'SLAPOS_CLIENT_CONFIGURATION'
],
supervisord_env
[
'SLAPOS_CLIENT_CONFIGURATION'
])
self
.
assertEqual
(
theia_shell_env
[
'HOME'
],
supervisord_env
[
'HOME'
])
self
.
assertEqual
(
theia_shell_env
[
'HOME'
],
supervisord_env
[
'HOME'
])
finally
:
# Cleanup the theia shell process
# Cleanup the theia shell process
theia_shell_process
.
terminate
()
theia_shell_process
.
terminate
()
theia_shell_process
.
wait
()
theia_shell_process
.
wait
()
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