diff --git a/basemodels/manifest/manifest.py b/basemodels/manifest/manifest.py index 45fc25f..a012f5c 100644 --- a/basemodels/manifest/manifest.py +++ b/basemodels/manifest/manifest.py @@ -20,15 +20,6 @@ from basemodels.constants import JOB_TYPES_FOR_CONTENT_TYPE_VALIDATION -# Validator function for taskdata and taskdata_uri fields -def validator_taskdata_uri(cls, value, values, **kwargs): - taskdata = values.get("taskdata") - taskdata_uri = values.get("taskdata_uri") - if taskdata is not None and len(taskdata) > 0 and taskdata_uri is not None: - raise ValidationError("Specify only one of taskdata {} or taskdata_uri {}".format(taskdata, taskdata_uri)) - return value - - # A validator function for UUID fields def validate_uuid(cls, value): return value or uuid.uuid4() @@ -330,6 +321,14 @@ class Manifest(Model): def validate(cls, values: Dict[str, Any]) -> Dict[str, Any]: start_date = values["start_date"] expiration_date = values["expiration_date"] + # validate at least taskdata or taskdata_uri is present + taskdata = values.get("taskdata") + taskdata_uri = values.get("taskdata_uri") + if taskdata is not None and len(taskdata) > 0 and taskdata_uri is not None: + raise ValueError("Specify only one of taskdata {} or taskdata_uri {}".format(taskdata, taskdata_uri)) + if taskdata is None and taskdata_uri is None: + raise ValueError("No taskdata or taskdata_uri found in manifest") + if not start_date and not expiration_date: # Timestamps are not passed return values @@ -398,8 +397,6 @@ def validate_requester_question_example(cls, value, values, **kwargs): raise ValueError("Lists are not allowed in this challenge type") return value - validate_taskdata_uri = validator("taskdata_uri", allow_reuse=True, always=True)(validator_taskdata_uri) - validate_taskdata = validator("taskdata", allow_reuse=True, always=True)(validator_taskdata_uri) validate_request_type = validator("request_type", allow_reuse=True, always=True)(RequestTypeValidator().validate) validate_job_api_key = validator("job_api_key", always=True, allow_reuse=True)(validate_uuid) validate_job_id = validator("job_id", always=True, allow_reuse=True)(validate_uuid) diff --git a/pyproject.toml b/pyproject.toml index 070ff1b..99b6b00 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "hmt-basemodels" -version = "0.2.6" +version = "0.2.7" description = "" authors = ["Intuition Machines, Inc "] packages = [ diff --git a/setup.py b/setup.py index 9ef0e5c..c2f87d9 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setuptools.setup( name="hmt-basemodels", - version="0.2.6", + version="0.2.7", author="HUMAN Protocol", description="Common data models shared by various components of the Human Protocol stack", url="https://github.com/hCaptcha/hmt-basemodels", diff --git a/tests/test_manifest_validation.py b/tests/test_manifest_validation.py index 8ead9e7..bb111af 100644 --- a/tests/test_manifest_validation.py +++ b/tests/test_manifest_validation.py @@ -196,6 +196,13 @@ def test_can_fail_toconstruct2(self): mani.taskdata_uri = "test" self.assertRaises(ValidationError, validate_func(mani)) + def test_manifest_must_contain_taskdata(self): + """Tests that manifest raises error when there is no taskdata""" + manifest = get_data() + manifest["taskdata_uri"] = None + with self.assertRaises(ValidationError): + basemodels.manifest.Manifest(**manifest) + def test_can_make_request_config_job(self): """Test that jobs with valid request_config parameter work""" manifest = a_manifest( diff --git a/tests/test_restricted_answer_set.py b/tests/test_restricted_answer_set.py index 7162b53..97c75d6 100644 --- a/tests/test_restricted_answer_set.py +++ b/tests/test_restricted_answer_set.py @@ -13,6 +13,7 @@ "recording_oracle_addr": "0x6a0E68eA5F706339dd6bd354F53EfcB5B9e53E49", "reputation_oracle_addr": "0x6a0E68eA5F706339dd6bd354F53EfcB5B9e53E49", "reputation_agent_addr": "0x6a0E68eA5F706339dd6bd354F53EfcB5B9e53E49", + "taskdata_uri": "http://google.com/fake", } NESTED_MANIFEST_VALUES = {