Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Hiboo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cyrinux
Hiboo
Commits
08e1f847
Commit
08e1f847
authored
1 year ago
by
kaiyou
Browse files
Options
Downloads
Patches
Plain Diff
Refactor test temporary files management
parent
5a2427a9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/conftest.py
+17
-17
17 additions, 17 deletions
tests/conftest.py
tests/test_e2e_auth.py
+12
-9
12 additions, 9 deletions
tests/test_e2e_auth.py
with
29 additions
and
26 deletions
tests/conftest.py
+
17
−
17
View file @
08e1f847
...
@@ -7,33 +7,34 @@ import time
...
@@ -7,33 +7,34 @@ import time
import
requests
import
requests
@pytest.fixture
@pytest.fixture
(
scope
=
"
module
"
)
def
temp
():
def
temp
():
"""
Write data to a temporary file and return the handle
"""
Write a temporary directory with module scope and offer
This is a fixture instead of a utility function so that
to write files in it, with optional subpath
temporary files have a test-scoped lifetime
"""
"""
handles
=
[]
#directory = tempfile.TemporaryDirectory()
d
ef
fun
(
data
):
d
irectory
=
tempfile
.
mkdtemp
()
handle
=
temp
file
.
N
ame
dTemporaryFile
(
delete
=
Fals
e
)
def
write_and_get_
file
n
ame
(
data
,
path
=
Non
e
)
:
if
type
(
data
)
is
str
:
if
type
(
data
)
is
str
:
data
=
data
.
encode
(
"
utf8
"
)
data
=
data
.
encode
(
"
utf8
"
)
handle
.
write
(
data
)
if
path
is
None
:
handle
.
flush
()
path
=
str
(
random
.
randbytes
(
3
).
hex
())
handles
.
append
(
handle
)
filepath
=
os
.
path
.
join
(
directory
,
path
)
return
handle
.
name
os
.
makedirs
(
os
.
path
.
dirname
(
filepath
),
0o755
,
True
)
yield
fun
with
open
(
filepath
,
"
wb
"
)
as
handle
:
del
handles
# Useless but explicit
handle
.
write
(
data
)
return
filepath
return
write_and_get_filename
@pytest.fixture
(
scope
=
"
module
"
)
@pytest.fixture
(
scope
=
"
module
"
)
def
app
(
username
,
password
):
def
app
(
username
,
password
,
temp
):
"""
Run an isolated application instance and return the URL
"""
"""
Run an isolated application instance and return the URL
"""
data
=
tempfile
.
TemporaryDirectory
()
port
=
5000
+
random
.
randint
(
1
,
999
)
# Port = 5XXX
port
=
5000
+
random
.
randint
(
1
,
999
)
# Port = 5XXX
url
=
f
"
http://localhost:
{
port
}
"
url
=
f
"
http://localhost:
{
port
}
"
db
=
temp
(
b
""
,
"
hiboo.db
"
)
env
=
os
.
environ
env
=
os
.
environ
env
.
update
(
FLASK_APP
=
"
hiboo
"
,
SQLALCHEMY_DATABASE_URI
=
f
"
sqlite:///
{
d
ata
.
name
}
/hiboo.d
b
"
)
env
.
update
(
FLASK_APP
=
"
hiboo
"
,
SQLALCHEMY_DATABASE_URI
=
f
"
sqlite:///
{
db
}
"
)
subprocess
.
run
([
"
flask
"
,
"
db
"
,
"
upgrade
"
],
env
=
env
)
subprocess
.
run
([
"
flask
"
,
"
db
"
,
"
upgrade
"
],
env
=
env
)
subprocess
.
run
([
"
flask
"
,
"
user
"
,
"
create
"
,
username
,
password
],
env
=
env
)
subprocess
.
run
([
"
flask
"
,
"
user
"
,
"
create
"
,
username
,
password
],
env
=
env
)
subprocess
.
run
([
"
flask
"
,
"
user
"
,
"
promote
"
,
username
],
env
=
env
)
subprocess
.
run
([
"
flask
"
,
"
user
"
,
"
promote
"
,
username
],
env
=
env
)
...
@@ -50,7 +51,6 @@ def app(username, password):
...
@@ -50,7 +51,6 @@ def app(username, password):
break
break
proc
.
terminate
()
proc
.
terminate
()
proc
.
wait
()
proc
.
wait
()
del
data
@pytest.fixture
(
scope
=
"
session
"
)
@pytest.fixture
(
scope
=
"
session
"
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_e2e_auth.py
+
12
−
9
View file @
08e1f847
...
@@ -12,12 +12,18 @@ HTTPD_CONFIG = """
...
@@ -12,12 +12,18 @@ HTTPD_CONFIG = """
ServerName localhost
ServerName localhost
ServerRoot /usr/lib/httpd
ServerRoot /usr/lib/httpd
PidFile /tmp/apache.pid
PidFile /tmp/apache.pid
<IfModule !unixd_module>
LoadModule unixd_module modules/mod_unixd.so
</IfModule>
<IfModule !log_config_module>
LoadModule log_config_module modules/mod_log_config.so
</IfModule>
LoadModule mpm_event_module modules/mod_mpm_event.so
LoadModule mpm_event_module modules/mod_mpm_event.so
LoadModule unixd_module modules/mod_unixd.so
LoadModule env_module modules/mod_env.so
LoadModule env_module modules/mod_env.so
LoadModule dir_module modules/mod_dir.so
LoadModule dir_module modules/mod_dir.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_user_module modules/mod_authz_user.so
...
@@ -31,7 +37,7 @@ HTTPD_CONFIG = """
...
@@ -31,7 +37,7 @@ HTTPD_CONFIG = """
DirectoryIndex index.html
DirectoryIndex index.html
"""
"""
SAML_CONFIG
=
"""
"
SAML_CONFIG
=
"""
LoadModule auth_mellon_module modules/mod_auth_mellon.so
LoadModule auth_mellon_module modules/mod_auth_mellon.so
<Location />
<Location />
Require valid-user
Require valid-user
...
@@ -46,7 +52,7 @@ SAML_CONFIG = """"
...
@@ -46,7 +52,7 @@ SAML_CONFIG = """"
"""
"""
OIDC_CONFIG
=
"""
"
OIDC_CONFIG
=
"""
LoadModule auth_openidc_module modules/mod_auth_openidc.so
LoadModule auth_openidc_module modules/mod_auth_openidc.so
OIDCProviderMetadataURL {metadata}
OIDCProviderMetadataURL {metadata}
...
@@ -69,18 +75,15 @@ def httpd(temp):
...
@@ -69,18 +75,15 @@ def httpd(temp):
Multiple servers may run and will all be closed at the end, they all share
Multiple servers may run and will all be closed at the end, they all share
a root directory
"""
a root directory
"""
proc
=
[]
proc
=
[]
rootDirectory
=
tempfile
.
TemporaryDirectory
()
root
=
os
.
path
.
dirname
(
temp
(
"
Hello world!
"
,
"
root/index.html
"
))
with
open
(
os
.
path
.
join
(
rootDirectory
.
name
,
"
index.html
"
),
"
w
"
)
as
handle
:
handle
.
write
(
"
Hello world!
"
)
def
start
(
config
):
def
start
(
config
):
config_file
=
temp
(
HTTPD_CONFIG
.
format
(
root
=
root
Directory
.
name
)
+
config
)
config_file
=
temp
(
HTTPD_CONFIG
.
format
(
root
=
root
)
+
config
)
proc
.
append
(
subprocess
.
Popen
([
"
httpd
"
,
"
-DFOREGROUND
"
,
"
-f
"
,
config_file
]))
proc
.
append
(
subprocess
.
Popen
([
"
httpd
"
,
"
-DFOREGROUND
"
,
"
-f
"
,
config_file
]))
time
.
sleep
(
1
)
# Sleep so apache can start
time
.
sleep
(
1
)
# Sleep so apache can start
yield
start
yield
start
for
pid
in
proc
:
for
pid
in
proc
:
pid
.
terminate
()
pid
.
terminate
()
pid
.
wait
()
pid
.
wait
()
del
rootDirectory
def
do_login
(
page
,
username
,
password
):
def
do_login
(
page
,
username
,
password
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment