Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
dccXMLJSONConv
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
DigitalDynamicMeasurement
dccXMLJSONConv
Commits
d81e4d74
Commit
d81e4d74
authored
5 months ago
by
Benedikt
Browse files
Options
Downloads
Patches
Plain Diff
captured warnings in pytest
parent
1be616c5
No related branches found
No related tags found
No related merge requests found
Pipeline
#50539
passed
5 months ago
Stage: test
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_RestServer.py
+23
-5
23 additions, 5 deletions
tests/test_RestServer.py
with
23 additions
and
5 deletions
tests/test_RestServer.py
+
23
−
5
View file @
d81e4d74
import
os
import
os
import
json
import
json
import
pytest
import
pytest
import
warnings
from
fastapi.testclient
import
TestClient
from
fastapi.testclient
import
TestClient
from
dccXMLJSONConv.dccServer
import
app
from
dccXMLJSONConv.dccServer
import
app
...
@@ -18,17 +19,26 @@ def test_root():
...
@@ -18,17 +19,26 @@ def test_root():
"
message
"
:
"
Hello!
\n
Better use the URL /json2dcc/?js={...}
\n
or /dcc2json (POST method)
"
}
"
message
"
:
"
Hello!
\n
Better use the URL /json2dcc/?js={...}
\n
or /dcc2json (POST method)
"
}
@pytest.mark.skipif
(
not
os
.
path
.
exists
(
os
.
path
.
join
(
data_dir
,
"
APITestXMLStub.xml
"
)),
reason
=
"
Test XML file not found
"
)
@pytest.mark.skipif
(
not
os
.
path
.
exists
(
os
.
path
.
join
(
data_dir
,
"
APITestXMLStub.xml
"
)),
reason
=
"
Test XML file not found
"
)
def
test_dcc2json_with_valid_xml
():
def
test_dcc2json_with_valid_xml
():
xml_data_path
=
os
.
path
.
join
(
data_dir
,
"
APITestXMLStub.xml
"
)
xml_data_path
=
os
.
path
.
join
(
data_dir
,
"
APITestXMLStub.xml
"
)
with
open
(
xml_data_path
,
"
r
"
)
as
f
:
with
open
(
xml_data_path
,
"
r
"
)
as
f
:
xml_data
=
f
.
read
()
xml_data
=
f
.
read
()
response
=
client
.
post
(
"
/dcc2json/
"
,
json
=
{
"
xml
"
:
xml_data
})
# Capture the expected warning
with
pytest
.
warns
(
UserWarning
,
match
=
"
XML->JSON Validation error:.*
"
):
response
=
client
.
post
(
"
/dcc2json/
"
,
json
=
{
"
xml
"
:
xml_data
})
# Validate response
response_json
=
response
.
json
()
response_json
=
response
.
json
()
expected_json_path
=
os
.
path
.
join
(
data_dir
,
"
APITestJSONStub.json
"
)
with
open
(
expected_json_path
,
"
r
"
)
as
f
:
expected_json
=
json
.
load
(
f
)
assert
response
.
status_code
==
200
assert
response
.
status_code
==
200
assert
response_json
==
json
.
loads
(
open
(
os
.
path
.
join
(
data_dir
,
"
APITestJSONStub.json
"
),
"
r
"
).
read
())
assert
response_json
==
expected_json
def
test_dcc2json_with_empty_xml
():
def
test_dcc2json_with_empty_xml
():
...
@@ -43,9 +53,17 @@ def test_json2dcc_with_valid_json():
...
@@ -43,9 +53,17 @@ def test_json2dcc_with_valid_json():
with
open
(
json_data_path
,
"
r
"
)
as
f
:
with
open
(
json_data_path
,
"
r
"
)
as
f
:
json_data
=
json
.
load
(
f
)
json_data
=
json
.
load
(
f
)
response
=
client
.
post
(
"
/json2dcc/
"
,
json
=
{
"
js
"
:
json_data
})
# Capture the expected warning during the request
with
pytest
.
warns
(
UserWarning
,
match
=
"
JSON->XML Validation error:.*
"
):
response
=
client
.
post
(
"
/json2dcc/
"
,
json
=
{
"
js
"
:
json_data
})
# Validate response
assert
response
.
status_code
==
200
assert
response
.
status_code
==
200
assert
response
.
text
==
open
(
os
.
path
.
join
(
data_dir
,
"
JSONTOXMLRespons.xml
"
),
"
r
"
).
read
()
expected_xml_path
=
os
.
path
.
join
(
data_dir
,
"
JSONTOXMLRespons.xml
"
)
with
open
(
expected_xml_path
,
"
r
"
)
as
f
:
expected_xml
=
f
.
read
()
assert
response
.
text
==
expected_xml
def
test_json2dcc_with_empty_json
():
def
test_json2dcc_with_empty_json
():
...
...
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