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
bbe3af8b
Commit
bbe3af8b
authored
5 months ago
by
Riccardo Boero
Browse files
Options
Downloads
Patches
Plain Diff
Modification of testing to use mocked input directories
parent
f96ad342
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#2004
failed
5 months ago
Stage: test
Stage: build
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/test_run_service.py
+15
-24
15 additions, 24 deletions
tests/test_run_service.py
tests/test_setup.py
+27
-2
27 additions, 2 deletions
tests/test_setup.py
with
42 additions
and
26 deletions
tests/test_run_service.py
+
15
−
24
View file @
bbe3af8b
# tests/test_run_service.py
# tests/test_run_service.py
from
polygonqueryonraster.app
import
app
import
os
import
requests
import
threading
def
test_run_service
():
class
GeoTIFFService
:
# Start the Flask development server in a separate thread
# Existing methods...
thread
=
threading
.
Thread
(
target
=
app
.
run
,
kwargs
=
{
'
debug
'
:
False
,
'
port
'
:
5001
})
thread
.
start
()
# Wait for the server to start
def
setup_routes
(
self
):
import
time
# Ensure the directory exists and contains subdirectories
time
.
sleep
(
1
)
if
os
.
path
.
exists
(
self
.
directory
):
subdirs
=
next
(
os
.
walk
(
self
.
directory
),
(
None
,
[]))[
1
]
if
not
subdirs
:
print
(
f
"
No subdirectories found in
{
self
.
directory
}
"
)
else
:
for
subdir
in
subdirs
:
subdir_path
=
os
.
path
.
join
(
self
.
directory
,
subdir
)
self
.
create_route
(
f
'
/
{
subdir
}
'
,
subdir_path
)
else
:
raise
ValueError
(
f
"
Directory
{
self
.
directory
}
does not exist.
"
)
try
:
# Make a sample GET request
response_get
=
requests
.
get
(
'
http://127.0.0.1:5001/api
'
)
assert
response_get
.
status_code
==
200
assert
response_get
.
json
()[
"
message
"
]
==
"
Hello, this is a simple REST API!
"
# Make a sample POST request
response_post
=
requests
.
post
(
'
http://127.0.0.1:5001/api
'
,
json
=
{
"
message
"
:
"
Updated message!
"
})
assert
response_post
.
status_code
==
200
assert
response_post
.
json
()[
"
message
"
]
==
"
Updated message!
"
finally
:
# Shut down the Flask development server
thread
.
join
(
timeout
=
1
)
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
test_run_service
()
test_run_service
()
This diff is collapsed.
Click to expand it.
tests/test_setup.py
+
27
−
2
View file @
bbe3af8b
from
polygonqueryonraster.app
import
app
import
tempfile
import
requests
import
threading
import
time
from
polygonqueryonraster.app
import
GeoTIFFService
def
test_flask_app
():
# Create a temporary directory for testing
with
tempfile
.
TemporaryDirectory
()
as
tempdir
:
# Start the Flask app
service
=
GeoTIFFService
(
tempdir
,
port
=
5001
)
thread
=
threading
.
Thread
(
target
=
service
.
run
)
thread
.
start
()
# Give it time to start
time
.
sleep
(
2
)
try
:
# Send a request to the Flask API
response
=
requests
.
get
(
'
http://127.0.0.1:5001/api
'
)
assert
response
.
status_code
==
200
assert
response
.
json
()[
"
message
"
]
==
"
Hello, this is a simple REST API!
"
finally
:
# Stop the Flask server
thread
.
join
(
timeout
=
1
)
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
app
.
run
(
debug
=
True
,
port
=
5001
)
# You can specify the port of your choice
test_flask_app
()
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