Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Polygon Query on Raster
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
Package Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FACT
FACT Utils
Polygon Query on Raster
Commits
bdbc2848
Commit
bdbc2848
authored
5 months ago
by
Riccardo Boero
Browse files
Options
Downloads
Patches
Plain Diff
Fixing mocked data dir in testing
parent
a0ffa3ac
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#2006
failed
5 months ago
Stage: test
Stage: build
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_setup.py
+9
-6
9 additions, 6 deletions
tests/test_setup.py
with
9 additions
and
6 deletions
tests/test_setup.py
+
9
−
6
View file @
bdbc2848
import
tempfile
import
tempfile
import
request
s
import
o
s
import
threading
import
threading
import
time
import
time
from
polygonqueryonraster.app
import
GeoTIFFService
from
polygonqueryonraster.app
import
GeoTIFFService
...
@@ -7,24 +7,27 @@ from polygonqueryonraster.app import GeoTIFFService
...
@@ -7,24 +7,27 @@ from polygonqueryonraster.app import GeoTIFFService
def
test_flask_app
():
def
test_flask_app
():
# Create a temporary directory for testing
# Create a temporary directory for testing
with
tempfile
.
TemporaryDirectory
()
as
tempdir
:
with
tempfile
.
TemporaryDirectory
()
as
tempdir
:
#
C
reate a dummy subdirectory in the temporary directory to
avoid StopIteration
#
Optionally, c
reate a dummy subdirectory in the temporary directory to
simulate subdirectories
os
.
makedirs
(
os
.
path
.
join
(
tempdir
,
'
dummy_subdir
'
))
os
.
makedirs
(
os
.
path
.
join
(
tempdir
,
'
dummy_subdir
'
))
#
Start the Flask app
#
Initialize the service with the temporary directory
service
=
GeoTIFFService
(
tempdir
,
port
=
5001
)
service
=
GeoTIFFService
(
tempdir
,
port
=
5001
)
# Start the Flask app in a separate thread
thread
=
threading
.
Thread
(
target
=
service
.
run
)
thread
=
threading
.
Thread
(
target
=
service
.
run
)
thread
.
start
()
thread
.
start
()
# Give
i
t time to start
# Give t
he server some
time to start
time
.
sleep
(
2
)
time
.
sleep
(
2
)
try
:
try
:
# Send a request to the Flask API
# Test that the Flask app responds correctly
import
requests
response
=
requests
.
get
(
'
http://127.0.0.1:5001/api
'
)
response
=
requests
.
get
(
'
http://127.0.0.1:5001/api
'
)
assert
response
.
status_code
==
200
assert
response
.
status_code
==
200
assert
response
.
json
()[
"
message
"
]
==
"
Hello, this is a simple REST API!
"
assert
response
.
json
()[
"
message
"
]
==
"
Hello, this is a simple REST API!
"
finally
:
finally
:
# Stop the Flask
server
# Stop the Flask
app
thread
.
join
(
timeout
=
1
)
thread
.
join
(
timeout
=
1
)
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
...
...
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