Skip to content

Commit

Permalink
Merge pull request #47 from EATRIS/46-other-issue-add-resourceid-vali…
Browse files Browse the repository at this point in the history
…dation

added resourceID validation
  • Loading branch information
niehues authored Dec 6, 2023
2 parents 3d5be14 + f4ce2d2 commit da8369a
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/motbxtools/motbxschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import validators
import yaml
from contextlib import contextmanager
from pathlib import Path


class MotbxSchema():
Expand Down Expand Up @@ -75,6 +76,7 @@ def validate(self, motbx_schema):
:raises Exception: Validation of URL fails
"""
assert isinstance(motbx_schema, MotbxSchema)
# schema validation
try:
# validate against JSON schema
# this includes checking URL for pattern https://* or *.pdf
Expand All @@ -83,6 +85,13 @@ def validate(self, motbx_schema):
format_checker=jsonschema.FormatChecker())
except jsonschema.exceptions.ValidationError:
raise
# ID validation
p = Path(self._yaml_path)
try:
assert self.resource["resourceID"] == p.stem
except AssertionError:
assert self.resource["resourceID"] == f'{p.parent.name}:{p.stem}'
# URL validation
url = self.resource["resourceUrl"]
try:
# validate URL
Expand Down
23 changes: 23 additions & 0 deletions tests/resources_fail/testfailID.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
resourceCategory: Quality Control and Assessment
resourceDescription: ISO Guide 80:2014 guidance for the in-house preparation of quality
control materials (QCMs). ISO Guide 80 outlines the characteristics and preparation
processes of reference materials for quality control. It applies to stable materials
used locally and those transported without significant property changes. Laboratory
staff preparing in-house quality control materials should follow ISO Guides 34 and
35 for transportation-based supply chains. The preparation of quality control materials
requires assessments for homogeneity, stability, and limited characterization. It
aims to demonstrate statistical control in a measurement system but does not provide
usage guidance. The guide offers general information on preparation and includes
case studies for different sectors. Users should have material knowledge and be
aware of matrix effects and contamination risks.
resourceID: 'testfailIDdiffersFromFilename'
resourceSubcategory: Guidelines and best practices
resourceTags:
- ISO standard
- guidelines
- quality control material
- in-house
- genomics
resourceTitle: 'ISO Guide 80:2014: Guidance for in-house preparation of quality control
materials'
resourceUrl: https://www.iso.org/standard/44313.html
2 changes: 1 addition & 1 deletion tests/resources_fail/testfailSubcategory.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ resourceDescription: ISO Guide 80:2014 guidance for the in-house preparation of
usage guidance. The guide offers general information on preparation and includes
case studies for different sectors. Users should have material knowledge and be
aware of matrix effects and contamination risks.
resourceID: '1'
resourceID: 'testfailSubcategory'
resourceSubcategory: Protocols
resourceTags:
- ISO standard
Expand Down
2 changes: 1 addition & 1 deletion tests/resources_fail/testfailUrl1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ resourceTags:
resourceTitle: 'ISO Guide 80:2014: Guidance for in-house preparation of quality
control materials'
resourceUrl: https://wwwiso.org/standard/44313.html
resourceID: 'testfailurl1'
resourceID: 'testfailUrl1'
2 changes: 1 addition & 1 deletion tests/resources_fail/testfailUrl2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ resourceTags:
resourceTitle: 'ISO Guide 80:2014: Guidance for in-house preparation of quality
control materials'
resourceUrl: https://www.iso.org/standard/4431333.html
resourceID: 'testfailurl2'
resourceID: 'testfailUrl2'
2 changes: 1 addition & 1 deletion tests/resources_fail/testfailUrl3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ resourceTags:
resourceTitle: 'ISO Guide 80:2014: Guidance for in-house preparation of quality
control materials'
resourceUrl: http://www.iso.org/standard/44313.html
resourceID: 'testfailurl3'
resourceID: 'testfailUrl3'
2 changes: 1 addition & 1 deletion tests/resources_pass/test1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ resourceDescription: ISO Guide 80:2014 guidance for the in-house preparation of
usage guidance. The guide offers general information on preparation and includes
case studies for different sectors. Users should have material knowledge and be
aware of matrix effects and contamination risks.
resourceID: '1'
resourceID: 'test1'
resourceSubcategory: Guidelines and best practices
resourceTags:
- ISO standard
Expand Down
23 changes: 23 additions & 0 deletions tests/resources_pass/testID.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
resourceCategory: Quality Control and Assessment
resourceDescription: ISO Guide 80:2014 guidance for the in-house preparation of quality
control materials (QCMs). ISO Guide 80 outlines the characteristics and preparation
processes of reference materials for quality control. It applies to stable materials
used locally and those transported without significant property changes. Laboratory
staff preparing in-house quality control materials should follow ISO Guides 34 and
35 for transportation-based supply chains. The preparation of quality control materials
requires assessments for homogeneity, stability, and limited characterization. It
aims to demonstrate statistical control in a measurement system but does not provide
usage guidance. The guide offers general information on preparation and includes
case studies for different sectors. Users should have material knowledge and be
aware of matrix effects and contamination risks.
resourceID: 'resources_pass:testID'
resourceSubcategory: Guidelines and best practices
resourceTags:
- ISO standard
- guidelines
- quality control material
- in-house
- genomics
resourceTitle: 'ISO Guide 80:2014: Guidance for in-house preparation of quality control
materials'
resourceUrl: https://www.iso.org/standard/44313.html
6 changes: 6 additions & 0 deletions tests/test_motbxtools/test_motbxschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ def test_validate_failUrl3(self):
os.path.join(self.resources_fail, "testfailUrl3.yaml"))
resource.validate(self.schema)

def test_validate_failID(self):
with self.assertRaises(AssertionError):
resource = motbxschema.MotbxResource(
os.path.join(self.resources_fail, "testfailID.yaml"))
resource.validate(self.schema)


if __name__ == '__main__':
unittest.main()

0 comments on commit da8369a

Please sign in to comment.