Skip to content

Commit 4012203

Browse files
committed
Add test of schema validation
1 parent 27d1b17 commit 4012203

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/hca_metadata_api/test.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
from humancellatlas.data.metadata.helpers.json import (
6969
as_json,
7070
)
71+
from humancellatlas.data.metadata.helpers.schema_validation import (
72+
SchemaValidator,
73+
)
7174
from humancellatlas.data.metadata.helpers.staging_area import (
7275
CannedStagingAreaFactory,
7376
)
@@ -791,6 +794,28 @@ def test_invalid_schema_domain(self):
791794
)
792795
self.assertEqual(expected, cm.exception.args[0].args)
793796

797+
def test_schema_validation(self):
798+
validator = SchemaValidator()
799+
good_data = {
800+
'describedBy': 'https://schema.humancellatlas.org/type/file/9.6.0/sequence_file',
801+
'schema_type': 'file',
802+
'file_core': {'file_name': 'foo.fastq.gz', 'format': 'fastq.gz'},
803+
'read_index': 'read1',
804+
}
805+
validator.validate_json(good_data, 'good.json')
806+
807+
bad_data = {
808+
'describedBy': 'https://schema.humancellatlas.org/type/file/9.6.0/sequence_file',
809+
'schema_type': 'file',
810+
'file_core': {'file_name': 'foo.fastq.gz', 'format': 'fastq.gz'},
811+
'read_index': 'bad-value',
812+
}
813+
with self.assertRaises(AssertionError) as cm:
814+
validator.validate_json(bad_data, 'bad.json')
815+
expected = ("'bad-value' is not one of ['read1', 'read2', 'read3', "
816+
"'read4', 'index1', 'index2', 'single-end, non-indexed']")
817+
self.assertEqual(expected, cm.exception.args[0].args[1])
818+
794819

795820
def load_tests(_loader, tests, _ignore):
796821
modules = (

0 commit comments

Comments
 (0)