Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure manifest contains taskdata #107

Merged
merged 3 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions basemodels/manifest/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions tests/test_manifest_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions tests/test_restricted_answer_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Loading