Skip to content

Commit

Permalink
task create api fails for hdfs
Browse files Browse the repository at this point in the history
  • Loading branch information
dchhabda committed Feb 22, 2024
1 parent 0fe6673 commit 7b93437
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
4 changes: 4 additions & 0 deletions pybossa/api/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ def _update_attribute(self, new, old):
def _preprocess_post_data(self, data):
project_id = data["project_id"]
info = data["info"]
if isinstance(info, dict):
hdfs_task = any([val.startswith("/fileproxy/hdfs/") for val in info.values() if isinstance(val, str)])
if hdfs_task:
raise BadRequest("Invalid task payload. HDFS is not supported")
duplicate = task_repo.find_duplicate(project_id=project_id, info=info)
if duplicate:
message = {
Expand Down
6 changes: 3 additions & 3 deletions pybossa/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1015,15 +1015,15 @@ def setup_http_signer(app):

def setup_swagger(app):
swagger_path = app.config.get('SWAGGER_HEADER_PATH')
if not swagger_path:
if swagger_path is None:
return

try:
with open(swagger_path, 'r') as file:
html_as_string = file.read()
app.config.get('SWAGGER_TEMPLATE')['head_text'] = html_as_string
except (FileNotFoundError, TypeError) as ex:
msg = f"WARNING: Swagger custom header file not found. {ex}"
except (FileNotFoundError, TypeError):
msg = "WARNING: Swagger custom header file not found."
app.logger.warning(msg)
Swagger.DEFAULT_CONFIG.update(app.config.get('SWAGGER_TEMPLATE'))
Swagger(app, template=app.config.get('SWAGGER_TEMPLATE'))
27 changes: 27 additions & 0 deletions test/test_api/test_task_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1237,3 +1237,30 @@ def upload_gold_data(self, mock, mock2):

url = tasks.upload_gold_data(task, 1, {'ans1': 'test'})
assert url == 'testURL', url


@with_context
def test_create_task_with_hdfs_payload(self):
[admin, subadminowner, subadmin, reguser] = UserFactory.create_batch(4)
make_admin(admin)
make_subadmin(subadminowner)
make_subadmin(subadmin)

project = ProjectFactory.create(owner=subadminowner)
admin_headers = dict(Authorization=admin.api_key)
task_info = dict(field_1='one', field_2='/fileproxy/hdfs/my_hdfs_file.txt')

# POST fails with error 400
data = dict(project_id=project.id, info=task_info, n_answers=2)
res = self.app.post('/api/task', data=json.dumps(data), headers=admin_headers)
assert res.status_code == 400
response = json.loads(res.data)
assert response["exception_msg"] == "Invalid task payload. HDFS is not supported"

# POST successful with hdfs not present in task payload
task_info["field_2"] = "xyz"
data = dict(project_id=project.id, info=task_info, n_answers=2)
res = self.app.post('/api/task', data=json.dumps(data), headers=admin_headers)
task = json.loads(res.data)
assert res.status_code == 200
assert task["info"] == {"field_1": "one", "field_2": "xyz"}

0 comments on commit 7b93437

Please sign in to comment.