Skip to content

Commit

Permalink
Merge pull request #171 from kbase/DATAUP-746_empty_types_returns_error
Browse files Browse the repository at this point in the history
DATAUP-746: empty `types` dictionary throws an error
  • Loading branch information
MrCreosote authored Apr 25, 2022
2 parents 12e6f04 + aacbfbf commit d1eb1d0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### Version 1.3.5
- Alter the behavior of the bulk specification file writers to return an error if the
input `types` parameter is empty.

### Version 1.3.4
- Fixed a bug in the csv/tsv bulk specification parser that would case a failure if the
first header of a file had trailing separators. This occurs if a csv/tsv file is opened and
Expand Down
6 changes: 3 additions & 3 deletions staging_service/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
routes = web.RouteTableDef()
VERSION = "1.3.4"
VERSION = "1.3.5"

_DATATYPE_MAPPINGS = None

Expand All @@ -59,7 +59,7 @@ async def importer_filetypes(request: web.Request) -> web.json_response:
Returns the file types for the configured datatypes. The returned JSON contains two keys:
* datatype_to_filetype, which maps import datatypes (like gff_genome) to their accepted
filetypes (like [FASTA, GFF])
* filetype_to_extensions, which maps file types (e.g. FASTA) to their extensions (e.g.
* filetype_to_extensions, which maps file types (e.g. FASTA) to their extensions (e.g.
*.fa, *.fasta, *.fa.gz, etc.)
This information is currently static over the life of the server.
Expand Down Expand Up @@ -197,7 +197,7 @@ async def write_bulk_specification(request: web.Request) -> web.json_response:
def _createJSONErrorResponse(error_text: str, error_class=web.HTTPBadRequest):
err = json.dumps({"error": error_text})
return error_class(text=err, content_type=_APP_JSON)


@routes.get("/add-acl-concierge")
async def add_acl_concierge(request: web.Request):
Expand Down
6 changes: 3 additions & 3 deletions staging_service/import_specifications/file_writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
entry in the list corresponds to a row in the resulting import specification,
and the order of the list defines the order of the rows.
Leave the `data` list empty to write an empty template.
:returns: A mapping of the data types to the files to which they were written.
:returns: A mapping of the data types to the files to which they were written.
"""
# note that we can't use an f string here to interpolate the variables below, e.g.
# order_and_display, etc.
Expand Down Expand Up @@ -82,7 +82,7 @@ def _check_import_specification(types: dict[str, dict[str, list[Any]]]):
Leave the {_DATA} list empty to write an empty template.
"""
if not types:
return
raise ImportSpecWriteException("At least one data type must be specified")
for datatype in types:
# replace this with jsonschema? don't worry about it for now
_check_string(datatype, "A data type")
Expand Down Expand Up @@ -235,4 +235,4 @@ class ImportSpecWriteException(Exception):
"""
An exception thrown when writing an import specification fails.
"""
pass
pass
6 changes: 2 additions & 4 deletions tests/import_specifications/test_file_writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ def temp_dir() -> Generator[Path, None, None]:
}
}

def test_noop():
assert write_csv(Path("."), {}) == {}
assert write_tsv(Path("."), {}) == {}

def test_write_csv(temp_dir: Path):
res = write_csv(temp_dir, _TEST_DATA)
Expand Down Expand Up @@ -194,6 +191,7 @@ def test_file_writers_fail():
E = ImportSpecWriteException
file_writers_fail(None, {}, ValueError("The folder cannot be null"))
file_writers_fail(p, None, E("The types value must be a mapping"))
file_writers_fail(p, {}, E("At least one data type must be specified"))
file_writers_fail(
p, {None: 1}, E("A data type cannot be a non-string or a whitespace only string"))
file_writers_fail(
Expand Down Expand Up @@ -281,4 +279,4 @@ def file_writers_fail(path: Path, types: dict, expected: Exception):
assert_exception_correct(got.value, expected)
with raises(Exception) as got:
write_excel(path, types)
assert_exception_correct(got.value, expected)
assert_exception_correct(got.value, expected)

0 comments on commit d1eb1d0

Please sign in to comment.