|
68 | 68 | from humancellatlas.data.metadata.helpers.json import (
|
69 | 69 | as_json,
|
70 | 70 | )
|
| 71 | +from humancellatlas.data.metadata.helpers.schema_validation import ( |
| 72 | + SchemaValidator, |
| 73 | +) |
71 | 74 | from humancellatlas.data.metadata.helpers.staging_area import (
|
72 | 75 | CannedStagingAreaFactory,
|
73 | 76 | )
|
@@ -791,6 +794,28 @@ def test_invalid_schema_domain(self):
|
791 | 794 | )
|
792 | 795 | self.assertEqual(expected, cm.exception.args[0].args)
|
793 | 796 |
|
| 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 | + |
794 | 819 |
|
795 | 820 | def load_tests(_loader, tests, _ignore):
|
796 | 821 | modules = (
|
|
0 commit comments