Common Package

Submodules

Mapper

Util

seed.common.util.apply_map(map_path, data_path, out_file)

Apply a JSON mapping to data, and write the output.

Args:
map_path (str): Path to mapping file data_path (str): Path to data file out_file (file): output stream
Return:
None
seed.common.util.create_map(path_in, path_out)

Create a JSON mapping file, suitable for map.Mapping(), from a CSV input file in our own custom style.

Input columns: CurrentSEED,NewSEED,PM1,PM2,Type (ignore rest)

Parameters:
  • path_in
  • path_out
Returns:

None

seed.common.util.find_duplicates(map_path, data_path, out_file)

Find duplicates created by a given mapping on a given input file.

Args:
map_path (str): Path to mapping file data_path (str): Path to data file out_file (file): output stream
Return:
None

Views

seed.common.views.api_error(reason)

JSON response for API error.

seed.common.views.api_success(**kwargs)

JSON response for API success.

seed.common.views.missing_request_keys(keys, body)

Check for keys in body.

Args:
keys (list): List of keys to check body (dict): body of request
Returns:
None if all present, JSON error response (using api_error()) if one or more is missing.
seed.common.views.typeof_request_values(types, body)

Check for type of request values.

All keys in types are present in body.

Parameters:
  • types (dict) – key to type map, where type is a function used to test the type conversion. It should take one argument, the value, and raise a ValueError if it is invalid.
  • body (dict) – body of request
Returns:

JSON

Example:

None if all OK, JSON error response (using `api_error()`)
if one or more is of the wrong type.