Skip to content

Commit 78b7d14

Browse files
committed
add CLI tests using urls
1 parent 2d5a882 commit 78b7d14

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

tests/unit/synapseclient/unit_test_commandline.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,9 @@ class TestGenerateJSONSchemaFunction:
852852
def setup(self, mock_syn):
853853
self.syn = mock_syn
854854
self.csv_path = "tests/unit/synapseclient/extensions/schema_files/data_models/example.model.csv"
855+
self.csv_url = "https://raw.githubusercontent.com/Sage-Bionetworks/synapsePythonClient/refs/heads/develop/tests/unit/synapseclient/extensions/schema_files/data_models/example.model.csv"
856+
self.json_path = "tests/unit/synapseclient/extensions/schema_files/data_models_jsonld/example.model.jsonld"
857+
self.json_url = "https://raw.githubusercontent.com/Sage-Bionetworks/synapsePythonClient/refs/heads/develop/tests/unit/synapseclient/extensions/schema_files/data_models_jsonld/example.model.jsonld"
855858

856859
def test_one_data_type_no_output_path(self):
857860
# GIVEN a CSV schema file
@@ -959,3 +962,53 @@ def test_all_data_types_with_output_dir(self):
959962
assert len(os.listdir(temp_dir)) > 1
960963
finally:
961964
shutil.rmtree(temp_dir)
965+
966+
def test_jsonld_path(self):
967+
# GIVEN a JSONLD schema file
968+
parser = cmdline.build_parser()
969+
args = parser.parse_args(
970+
["generate-json-schema", self.json_path, "--data-types", "Patient"]
971+
)
972+
schema_path = "./Patient.json"
973+
try:
974+
# WHEN I generate a schema with one datatype and no output path
975+
cmdline.generate_json_schema(args, self.syn)
976+
# THEN a schema file should be created at ./Patient.json
977+
assert os.path.isfile(schema_path)
978+
finally:
979+
if os.path.isfile(schema_path):
980+
os.remove(schema_path)
981+
982+
@pytest.mark.enable_socket
983+
def test_csv_url(self):
984+
# GIVEN a CSV schema URL
985+
parser = cmdline.build_parser()
986+
args = parser.parse_args(
987+
["generate-json-schema", self.csv_url, "--data-types", "Patient"]
988+
)
989+
schema_path = "./Patient.json"
990+
try:
991+
# WHEN I generate a schema with one datatype and no output path
992+
cmdline.generate_json_schema(args, self.syn)
993+
# THEN a schema file should be created at ./Patient.json
994+
assert os.path.isfile(schema_path)
995+
finally:
996+
if os.path.isfile(schema_path):
997+
os.remove(schema_path)
998+
999+
@pytest.mark.enable_socket
1000+
def test_jsonld_url(self):
1001+
# GIVEN a CSV schema URL
1002+
parser = cmdline.build_parser()
1003+
args = parser.parse_args(
1004+
["generate-json-schema", self.json_url, "--data-types", "Patient"]
1005+
)
1006+
schema_path = "./Patient.json"
1007+
try:
1008+
# WHEN I generate a schema with one datatype and no output path
1009+
cmdline.generate_json_schema(args, self.syn)
1010+
# THEN a schema file should be created at ./Patient.json
1011+
assert os.path.isfile(schema_path)
1012+
finally:
1013+
if os.path.isfile(schema_path):
1014+
os.remove(schema_path)

0 commit comments

Comments
 (0)