Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DCAT Catalog Check
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Open-Data
DCAT Catalog Check
Commits
d06bfef3
Commit
d06bfef3
authored
3 months ago
by
Thorge Petersen
Browse files
Options
Downloads
Patches
Plain Diff
test: add unit tests for URI replacements and resource clearing
parent
e7b06056
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1
Update Formats, Dependencies, and Dockerfile Configuration
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_format_fidelity_checker.py
+86
-5
86 additions, 5 deletions
tests/test_format_fidelity_checker.py
with
86 additions
and
5 deletions
tests/test_format_fidelity_checker.py
+
86
−
5
View file @
d06bfef3
...
...
@@ -29,10 +29,13 @@ class TestDcatCatalogCheck(unittest.TestCase):
"
XML
"
:
[
"
application/xml
"
],
}
self
.
assertTrue
(
self
.
dcc
.
is_mime_type_compatible
(
"
JSON
"
,
"
application/json
"
))
self
.
assertFalse
(
self
.
dcc
.
is_mime_type_compatible
(
"
JSON
"
,
"
application/xml
"
))
self
.
assertTrue
(
self
.
dcc
.
is_mime_type_compatible
(
"
JSON
"
,
"
application/json
"
))
self
.
assertFalse
(
self
.
dcc
.
is_mime_type_compatible
(
"
JSON
"
,
"
application/xml
"
))
self
.
assertFalse
(
self
.
dcc
.
is_mime_type_compatible
(
"
UnknownFormat
"
,
"
application/json
"
)
self
.
dcc
.
is_mime_type_compatible
(
"
UnknownFormat
"
,
"
application/json
"
)
)
def
test_read_allowed_file_formats
(
self
):
...
...
@@ -44,7 +47,8 @@ class TestDcatCatalogCheck(unittest.TestCase):
):
formats
=
self
.
dcc
.
read_allowed_file_formats
()
self
.
assertEqual
(
formats
,
{
"
JSON
"
:
[
"
application/json
"
],
"
XML
"
:
[
"
application/xml
"
]}
formats
,
{
"
JSON
"
:
[
"
application/json
"
],
"
XML
"
:
[
"
application/xml
"
]}
)
def
test_load_uri_replacements
(
self
):
...
...
@@ -55,7 +59,8 @@ class TestDcatCatalogCheck(unittest.TestCase):
),
):
replacements
=
self
.
dcc
.
load_uri_replacements
()
self
.
assertEqual
(
replacements
,
[{
"
regex
"
:
"
old
"
,
"
replaced_by
"
:
"
new
"
}])
self
.
assertEqual
(
replacements
,
[{
"
regex
"
:
"
old
"
,
"
replaced_by
"
:
"
new
"
}])
# Simulate that the file does not exist
...
...
@@ -375,6 +380,82 @@ class TestDcatCatalogCheck(unittest.TestCase):
'
Line 1 is missing
\'
url
\'
: {
"
status
"
:
"
valid
"
,
"
format
"
:
"
JSON
"
}
'
)
def
test_apply_uri_replacements
(
self
):
"""
Test the apply_uri_replacements method.
"""
# Setup URI replacements
self
.
dcc
.
uri_replacements
=
[
{
"
regex
"
:
r
"
example\.com
"
,
"
replaced_by
"
:
"
test.com
"
},
{
"
regex
"
:
r
"
http://
"
,
"
replaced_by
"
:
"
https://
"
},
]
# URL matching both replacements
url
=
"
http://example.com/path
"
result
=
self
.
dcc
.
apply_uri_replacements
(
url
)
self
.
assertEqual
(
result
,
"
https://test.com/path
"
)
# URL matching only one replacement
url
=
"
http://other.com/path
"
result
=
self
.
dcc
.
apply_uri_replacements
(
url
)
self
.
assertEqual
(
result
,
"
https://other.com/path
"
)
# URL with no matches
url
=
"
https://unchanged.com/path
"
result
=
self
.
dcc
.
apply_uri_replacements
(
url
)
self
.
assertEqual
(
result
,
"
https://unchanged.com/path
"
)
# Empty URL
url
=
""
result
=
self
.
dcc
.
apply_uri_replacements
(
url
)
self
.
assertEqual
(
result
,
""
)
# No URI replacements defined
self
.
dcc
.
uri_replacements
=
[]
url
=
"
http://example.com/path
"
result
=
self
.
dcc
.
apply_uri_replacements
(
url
)
self
.
assertEqual
(
result
,
"
http://example.com/path
"
)
def
test_clear_result
(
self
):
"""
Test the _clear_result method.
"""
# Define a resource dictionary with keys to clear and some additional keys
resource
=
{
"
accessible
"
:
True
,
"
checksum_ok
"
:
True
,
"
duration
"
:
1.23
,
"
error
"
:
"
Some error
"
,
"
etag
"
:
"
some-etag
"
,
"
http_status
"
:
200
,
"
last_check
"
:
"
2024-12-27T12:34:56Z
"
,
"
mimetype
"
:
"
application/json
"
,
"
mimetype_mismatch
"
:
False
,
"
valid
"
:
True
,
"
url
"
:
"
http://example.com/data
"
,
# This key should remain untouched
"
format
"
:
"
JSON
"
,
# This key should remain untouched
}
# Call the _clear_result method
self
.
dcc
.
_clear_result
(
resource
)
# Check that all keys to clear have been removed
for
key
in
[
"
accessible
"
,
"
checksum_ok
"
,
"
duration
"
,
"
error
"
,
"
etag
"
,
"
http_status
"
,
"
last_check
"
,
"
mimetype
"
,
"
mimetype_mismatch
"
,
"
valid
"
,
]:
self
.
assertNotIn
(
key
,
resource
)
# Check that unrelated keys remain
self
.
assertIn
(
"
url
"
,
resource
)
self
.
assertIn
(
"
format
"
,
resource
)
self
.
assertEqual
(
resource
[
"
url
"
],
"
http://example.com/data
"
)
self
.
assertEqual
(
resource
[
"
format
"
],
"
JSON
"
)
if
__name__
==
"
__main__
"
:
unittest
.
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