Skip to content

Commit

Permalink
Merge pull request #45 from OpenDataServices/test-iati-orgxml
Browse files Browse the repository at this point in the history
update tests for org_xml to spreadsheet conversion
  • Loading branch information
Bjwebb authored Feb 21, 2020
2 parents bba912f + e81eda3 commit 71fb186
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ __pycache__
/libcove.egg-info
*~
*.swp
.vscode
File renamed without changes.
17 changes: 17 additions & 0 deletions tests/lib/fixtures/converters/convert_org_1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<iati-organisations version="2.03" generated-datetime="2019-07-24T12:10:00">
<iati-organisation last-updated-datetime="2019-07-24T12:10:00" xml:lang="en" default-currency="GBP">
<organisation-identifier>GB-GOV-1</organisation-identifier>
<name>
<narrative>UK Department for International Development</narrative>
</name>
<reporting-org ref="GB-GOV-1" type="10">
<narrative>UK Department for International Development</narrative>
</reporting-org>
<total-budget status="1">
<period-start iso-date="2019-04-01"/>
<period-end iso-date="2020-03-31"/>
<value value-date="2019-07-11">10574558000</value>
</total-budget>
</iati-organisation>
</iati-organisations>
67 changes: 62 additions & 5 deletions tests/lib/test_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,24 @@ def test_convert_json_1():
assert row2[1] == "Hat"


def test_convert_xml_1():
def test_convert_activity_xml_1():

cove_temp_folder = tempfile.mkdtemp(
prefix="lib-cove-ocds-tests-", dir=tempfile.gettempdir()
prefix="lib-cove-iati-tests-", dir=tempfile.gettempdir()
)
xml_filename = os.path.join(

activity_xml_filename = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"fixtures",
"converters",
"convert_1.xml",
"convert_activity_1.xml",
)

lib_cove_config = LibCoveConfig()
output = convert_json(
cove_temp_folder,
"",
xml_filename,
activity_xml_filename,
lib_cove_config,
flatten=True,
xml=True,
Expand Down Expand Up @@ -108,6 +109,62 @@ def test_convert_xml_1():
assert row1[1] == "GB-TEST-13-example_ODSC_2019"


def test_convert_org_xml_1():

cove_temp_folder = tempfile.mkdtemp(
prefix="lib-cove-iati-tests-", dir=tempfile.gettempdir()
)

organisation_xml_filename = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"fixtures",
"converters",
"convert_org_1.xml",
)

lib_cove_config = LibCoveConfig()
output = convert_json(
cove_temp_folder,
"",
organisation_xml_filename,
lib_cove_config,
flatten=True,
xml=True,
root_list_path="iati-organisation",
root_id="organisation-identifier",
)

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-organisation.csv")
)

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

header = next(csvreader)
assert header[0] == "organisation-identifier"
assert header[4] == "name/narrative"

row1 = next(csvreader)
assert row1[0] == "GB-GOV-1"
assert row1[4] == "UK Department for International Development"


def test_convert_json_root_is_list_1():

cove_temp_folder = tempfile.mkdtemp(
Expand Down

0 comments on commit 71fb186

Please sign in to comment.