Skip to content

Commit

Permalink
Merge pull request #26 from OpenDataServices/1208-pass-root_list_path
Browse files Browse the repository at this point in the history
Pass through root_list_path
  • Loading branch information
Jared Parnell authored Sep 4, 2019
2 parents 61ed8d0 + 37ca561 commit 142683c
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [0.9.0] - 2019-08-29

### Changed

- Allow the passing of `root_list_path` to the conversion tool

## [0.8.0] - 2019-08-28

### Changed
Expand Down
11 changes: 7 additions & 4 deletions libcove/lib/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,18 @@ def convert_spreadsheet(upload_dir, upload_url, file_name, file_type, lib_cove_c
return context


def convert_json(upload_dir, upload_url, file_name, lib_cove_config, schema_url=None, replace=False, request=None,
flatten=False, cache=True, xml=False):
def convert_json(upload_dir, upload_url, file_name, lib_cove_config, root_list_path=None,
schema_url=None, replace=False, request=None, flatten=False, cache=True, xml=False):
context = {}
converted_path = os.path.join(upload_dir, 'flattened')

if root_list_path is None:
root_list_path = lib_cove_config.config['root_list_path']

flatten_kwargs = dict(
output_name=converted_path,
main_sheet_name=lib_cove_config.config['root_list_path'],
root_list_path=lib_cove_config.config['root_list_path'],
main_sheet_name=root_list_path,
root_list_path=root_list_path,
root_id=lib_cove_config.config['root_id'],
schema=schema_url,
disable_local_refs=lib_cove_config.config['flatten_tool']['disable_local_refs'],
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='libcove',
version='0.8.0',
version='0.9.0',
author='Open Data Services',
author_email='[email protected]',
url='https://github.com/OpenDataServices/lib-cove',
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/fixtures/converters/convert_1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<iati-activities version="2.02">
<!--Generated By AidStream-->
<iati-activity default-currency="GBP">
<iati-identifier>GB-TEST-13-example_ODSC_2019</iati-identifier>
<reporting-org ref="GB-TEST-13">
<narrative>Department for Education</narrative>
</reporting-org>
</iati-activity>
</iati-activities>
36 changes: 36 additions & 0 deletions tests/lib/test_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,42 @@ def test_convert_json_1():
assert row2[1] == 'Hat'


def test_convert_xml_1():

cove_temp_folder = tempfile.mkdtemp(prefix='lib-cove-ocds-tests-', dir=tempfile.gettempdir())
xml_filename = os.path.join(os.path.dirname(
os.path.realpath(__file__)), 'fixtures', 'converters', 'convert_1.xml'
)

lib_cove_config = LibCoveConfig()
output = convert_json(cove_temp_folder, "", xml_filename, lib_cove_config, flatten=True,
xml=True, root_list_path='iati-activity')

assert output['converted_url'] == '/flattened'
assert len(output['conversion_warning_messages']) == 0
assert output['conversion'] == 'flatten'

conversion_warning_messages_name = os.path.join(cove_temp_folder, "conversion_warning_messages.json")
assert os.path.isfile(conversion_warning_messages_name)
with open(conversion_warning_messages_name) as fp:
conversion_warning_messages_data = json.load(fp)
assert conversion_warning_messages_data == []

assert os.path.isfile(os.path.join(cove_temp_folder, "flattened.xlsx"))
assert os.path.isfile(os.path.join(cove_temp_folder, "flattened", "iati-activity.csv"))

with open(os.path.join(cove_temp_folder, "flattened", "iati-activity.csv"), 'r') as csvfile:
csvreader = csv.reader(csvfile)

header = next(csvreader)
assert header[0] == '@default-currency'
assert header[1] == 'iati-identifier'

row1 = next(csvreader)
assert row1[0] == 'GBP'
assert row1[1] == 'GB-TEST-13-example_ODSC_2019'


def test_convert_json_root_is_list_1():

cove_temp_folder = tempfile.mkdtemp(prefix='lib-cove-ocds-tests-', dir=tempfile.gettempdir())
Expand Down

0 comments on commit 142683c

Please sign in to comment.