-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FDS-2127] Update URL validation to use requests.options to verify co…
…nnectivity (#1472) * Update URL validation to use requests.options to verify connectivity
- Loading branch information
1 parent
4591439
commit e3905cf
Showing
5 changed files
with
116 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import pandas as pd | ||
|
||
from schematic.models.validate_attribute import ValidateAttribute | ||
from schematic.schemas.data_model_graph import DataModelGraphExplorer | ||
|
||
CHECK_URL_NODE_NAME = "Check URL" | ||
VALIDATION_RULE_URL = "url" | ||
|
||
|
||
class TestValidateAttribute: | ||
"""Integration tests for the ValidateAttribute class.""" | ||
|
||
def test_url_validation_valid_url(self, dmge: DataModelGraphExplorer) -> None: | ||
# GIVEN a valid URL: | ||
url = "https://github.com/Sage-Bionetworks/schematic" | ||
|
||
# AND a pd.core.series.Series that contains this URL | ||
content = pd.Series(data=[url], name=CHECK_URL_NODE_NAME) | ||
|
||
# AND a validation attribute | ||
validator = ValidateAttribute(dmge=dmge) | ||
|
||
# WHEN the URL is validated | ||
result = validator.url_validation( | ||
val_rule=VALIDATION_RULE_URL, manifest_col=content | ||
) | ||
|
||
# THEN the result should pass validation | ||
assert result == ([], []) | ||
|
||
def test_url_validation_valid_doi(self, dmge: DataModelGraphExplorer) -> None: | ||
# GIVEN a valid URL: | ||
url = "https://doi.org/10.1158/0008-5472.can-23-0128" | ||
|
||
# AND a pd.core.series.Series that contains this URL | ||
content = pd.Series(data=[url], name=CHECK_URL_NODE_NAME) | ||
|
||
# AND a validation attribute | ||
validator = ValidateAttribute(dmge=dmge) | ||
|
||
# WHEN the URL is validated | ||
result = validator.url_validation( | ||
val_rule=VALIDATION_RULE_URL, manifest_col=content | ||
) | ||
|
||
# THEN the result should pass validation | ||
assert result == ([], []) | ||
|
||
def test_url_validation_invalid_url(self, dmge: DataModelGraphExplorer) -> None: | ||
# GIVEN an invalid URL: | ||
url = "http://googlef.com/" | ||
|
||
# AND a pd.core.series.Series that contains this URL | ||
content = pd.Series(data=[url], name=CHECK_URL_NODE_NAME) | ||
|
||
# AND a validation attribute | ||
validator = ValidateAttribute(dmge=dmge) | ||
|
||
# WHEN the URL is validated | ||
result = validator.url_validation( | ||
val_rule=VALIDATION_RULE_URL, manifest_col=content | ||
) | ||
|
||
# THEN the result should not pass validation | ||
assert result == ( | ||
[ | ||
[ | ||
"2", | ||
"Check URL", | ||
"For the attribute 'Check URL', on row 2, the URL provided (http://googlef.com/) does not conform to the standards of a URL. Please make sure you are entering a real, working URL as required by the Schema.", | ||
"http://googlef.com/", | ||
] | ||
], | ||
[], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters