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
Branches containing commit
No related tags found
Tags containing commit
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
import
requests
@pytest.fixture
@pytest.fixture
(
scope
=
"
module
"
)
def
temp
():
"""
Write data to a temporary file and return the handle
This is a fixture instead of a utility function so that
temporary files have a test-scoped lifetime
"""
Write a temporary directory with module scope and offer
to write files in it, with optional subpath
"""
handles
=
[]
d
ef
fun
(
data
):
handle
=
temp
file
.
N
ame
dTemporaryFile
(
delete
=
Fals
e
)
#directory = tempfile.TemporaryDirectory()
d
irectory
=
tempfile
.
mkdtemp
()
def
write_and_get_
file
n
ame
(
data
,
path
=
Non
e
)
:
if
type
(
data
)
is
str
:
data
=
data
.
encode
(
"
utf8
"
)
handle
.
write
(
data
)
handle
.
flush
()
handles
.
append
(
handle
)
return
handle
.
name
yield
fun
del
handles
# Useless but explicit
if
path
is
None
:
path
=
str
(
random
.
randbytes
(
3
).
hex
())
filepath
=
os
.
path
.
join
(
directory
,
path
)
os
.
makedirs
(
os
.
path
.
dirname
(
filepath
),
0o755
,
True
)
with
open
(
filepath
,
"
wb
"
)
as
handle
:
handle
.
write
(
data
)
return
filepath
return
write_and_get_filename
@pytest.fixture
(
scope
=
"
module
"
)
def
app
(
username
,
password
):
def
app
(
username
,
password
,
temp
):
"""
Run an isolated application instance and return the URL
"""
data
=
tempfile
.
TemporaryDirectory
()
port
=
5000
+
random
.
randint
(
1
,
999
)
# Port = 5XXX
url
=
f
"
http://localhost:
{
port
}
"
db
=
temp
(
b
""
,
"
hiboo.db
"
)
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
"
,
"
user
"
,
"
create
"
,
username
,
password
],
env
=
env
)
subprocess
.
run
([
"
flask
"
,
"
user
"
,
"
promote
"
,
username
],
env
=
env
)
...
...
@@ -50,7 +51,6 @@ def app(username, password):
break
proc
.
terminate
()
proc
.
wait
()
del
data
@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 = """
ServerName localhost
ServerRoot /usr/lib/httpd
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 unixd_module modules/mod_unixd.so
LoadModule env_module modules/mod_env.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 authz_core_module modules/mod_authz_core.so
LoadModule authz_user_module modules/mod_authz_user.so
...
...
@@ -31,7 +37,7 @@ HTTPD_CONFIG = """
DirectoryIndex index.html
"""
SAML_CONFIG
=
"""
"
SAML_CONFIG
=
"""
LoadModule auth_mellon_module modules/mod_auth_mellon.so
<Location />
Require valid-user
...
...
@@ -46,7 +52,7 @@ SAML_CONFIG = """"
"""
OIDC_CONFIG
=
"""
"
OIDC_CONFIG
=
"""
LoadModule auth_openidc_module modules/mod_auth_openidc.so
OIDCProviderMetadataURL {metadata}
...
...
@@ -69,18 +75,15 @@ def httpd(temp):
Multiple servers may run and will all be closed at the end, they all share
a root directory
"""
proc
=
[]
rootDirectory
=
tempfile
.
TemporaryDirectory
()
with
open
(
os
.
path
.
join
(
rootDirectory
.
name
,
"
index.html
"
),
"
w
"
)
as
handle
:
handle
.
write
(
"
Hello world!
"
)
root
=
os
.
path
.
dirname
(
temp
(
"
Hello world!
"
,
"
root/index.html
"
))
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
]))
time
.
sleep
(
1
)
# Sleep so apache can start
yield
start
for
pid
in
proc
:
pid
.
terminate
()
pid
.
wait
()
del
rootDirectory
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