Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

834 additional iati checks #856

Merged
merged 54 commits into from
Oct 11, 2017
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
54a4589
[#834] cove_iati: add missing backtick in feature
edugomez Sep 25, 2017
23d98d0
[#834] cove_iati: add initial Open Ag ruleset
edugomez Sep 25, 2017
f64c445
[#834] iati_openag: add steps to check for right attributes in openag…
edugomez Sep 26, 2017
1f33927
[#834] iati_openag: rename openag_tag_agrovoc_attributes.feature as o…
edugomez Sep 26, 2017
6f3e525
[#834] iati_openag: refactor openag steps to add 'And' step to features
edugomez Sep 26, 2017
c038504
[#834] iati_openag: add openag_location.features
edugomez Sep 26, 2017
b4e245b
[#834] iati_openag: add org-ids feature
edugomez Sep 27, 2017
cddf2bc
[#834] Add @get_org_ids_prefixes
edugomez Sep 27, 2017
bf8f0fc
[#834] iati_openag: edit opena_orgids.feature
edugomez Sep 28, 2017
2882cda
[#834] iati_openag: add step for org_ids ref id check
edugomez Sep 28, 2017
a273960
Merge branch 'master' into 834-additional-iati-checks
edugomez Sep 28, 2017
549c6a2
[#834] Raise requests exception if first request org-ids file fails
edugomez Sep 28, 2017
aa0ef82
[#834] iati rulesets: reuse given steps
edugomez Sep 28, 2017
ce5943a
[#834] iati ruleset: refactor actual dates features and steps
edugomez Sep 28, 2017
f0ba01e
[#834]: iati_ruleset: refactor start-date end-date features
edugomez Sep 29, 2017
101c321
[#834]: iati_ruleset: refactor sector features
edugomez Sep 29, 2017
9dcd539
[#834]: iati_ruleset: refactor element valid format feature
edugomez Sep 29, 2017
28f486e
[#834] iati_openag: delete ruleset_openag dir from output dir
edugomez Sep 29, 2017
07414ea
[#834] iati_ruleset: edit error messages
edugomez Sep 29, 2017
03d6a79
[#834] iati_ruleset: add rulesets utils
edugomez Sep 29, 2017
56c0766
[#834] iati_ruleset: use register_ruleset_errors decorator
edugomez Sep 29, 2017
40fa7ee
[#834] iati_ruleset: rename steps
edugomez Sep 29, 2017
edadf3c
[#834] iati_ruleset: edit scenario outlines
edugomez Oct 2, 2017
de2c2b1
[#834] iati_ruleset: check for namespaces defined in data
edugomez Oct 2, 2017
2092b07
[#834] cove_iati: fix tests
edugomez Oct 2, 2017
bccff32
[#834] cove_iati: add --openag option to iati-cli
edugomez Oct 2, 2017
d28124e
[#834] iati_ruleset: make @register_ruleset_errors a decorator factory
edugomez Oct 2, 2017
98f985b
[#834] iati_openag: add test for openag cli output
edugomez Oct 2, 2017
d0e7c07
cove_ocds: fix broken test
edugomez Oct 2, 2017
0f81218
[#834] iati_openag: fix bug location-id step
edugomez Oct 3, 2017
8df0e4f
[#834] iati_openag: more comprehensive tests for openag rulesets
edugomez Oct 3, 2017
72e68e4
[#834] iati_ruleset: add test_register_ruleset_errors_decorator
edugomez Oct 3, 2017
3b3e394
[#834] iati_ruleset: fix broken test
edugomez Oct 3, 2017
8ed8e82
Merge branch 'master' into 834-additional-iati-checks
edugomez Oct 3, 2017
547d187
[#834] cove_iati: tests minor layout changes
edugomez Oct 3, 2017
0e1481a
[#834] iati_ruleset: tidy up iati rulesets
edugomez Oct 4, 2017
8f7ecf5
[#834] iati_ruleset: add forward slash to paths in rule definition
edugomez Oct 4, 2017
faacc3d
[#834]: iati_ruleset: do not check for valid iso dates in rulesets
edugomez Oct 4, 2017
08e057b
[#834] iati_ruleset: fix test for cli output
edugomez Oct 4, 2017
cfe1512
[#834] iati_openag: better rule definitions
edugomez Oct 4, 2017
f948e26
[#834]: cove_iati: fix bug for xml not returning validation errors 'v…
edugomez Oct 5, 2017
a627eef
[#834] cove_iati: add functional test
edugomez Oct 5, 2017
fbb540a
[#834] iati_orgids: add orgids check option to cli
edugomez Oct 5, 2017
ebf7892
Merge branch 'master' into 834-additional-iati-checks
edugomez Oct 6, 2017
b05006c
[#834] iati_ruleset: add tests for rulesets utils
edugomez Oct 6, 2017
3c8e061
Merge branch 'master' into 834-additional-iati-checks
edugomez Oct 6, 2017
0e4e129
[#834] Add orgids_url kwarg to @get_orgids_prefixes
edugomez Oct 6, 2017
d06fe21
[#834] iati_ruleset: pass iterable with namespaces to @register_rules…
edugomez Oct 9, 2017
4af9641
[#834] iati_openag: rename openag ruleset step
edugomez Oct 9, 2017
c054cdc
[#834] iati_orgids: use startwith instead of regex
edugomez Oct 9, 2017
815fc80
[#834] iati_cli: add more info to README.rst
edugomez Oct 9, 2017
d5250d2
[#834] Fix broken ruleset check
Bjwebb Oct 10, 2017
9653270
[#834] Only sector should be an exclusive or
Bjwebb Oct 10, 2017
dfdd697
Merge branch 'master' into 834-additional-iati-checks
edugomez Oct 11, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,13 @@ Options:

``--delete -d`` Delete the output directory if it already exists.

``--orgids -i`` Run org-ids rule check for IATI identifier prefixes.

``--openag -a`` Run ruleset checks for IATI OpenAg data.


If the file is in spreadsheet format, the output directory will contain a *unflattened.xml* file converted from Excel or CSV to XML format

**OpenaAg** rulesets check that the data contains the XML elements ``<opeang:tag>`` and ``<location>``, and that they include the right attributes expected for OpenAg data. Please read `OpenAg ruleset feature files <cove_iati/rulesets/iati_openag_ruleset/>`_ (written in `Gerkhin <https://github.com/cucumber/cucumber/wiki/Gherkin/>`_ style) for more information.

**Org-ids** rulesets check that all organisation identifiers are prefixed with a registered `org-ids <http://org-id.guide>`_ prefix. Please read `Org-ids ruleset feature file <cove_iati/rulesets/iati_orgids_ruleset/>`_ for more information
35 changes: 35 additions & 0 deletions cove/lib/common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import collections
import csv
import datetime
import functools
import json
import os
Expand Down Expand Up @@ -631,3 +632,37 @@ def get_spreadsheet_meta_data(upload_dir, file_name, schema, file_type='xlsx', n
with open(output_name) as metatab_data:
metatab_json = json.load(metatab_data)
return metatab_json


def get_orgids_prefixes(orgids_url=None):
local_org_ids_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'org-ids.json')
today = datetime.date.today()
get_remote_file = False
first_request = False

if not orgids_url:
orgids_url = 'http://org-id.guide/download.json'

if os.path.exists(local_org_ids_file):
with open(local_org_ids_file) as fp:
org_ids = json.load(fp)
date_str = org_ids.get('downloaded', '2000-1-1')
date_downloaded = datetime.datetime.strptime(date_str, '%Y-%m-%d').date()
if date_downloaded != today:
get_remote_file = True
else:
get_remote_file = True
first_request = True

if get_remote_file:
try:
org_ids = requests.get(orgids_url).json()
org_ids['downloaded'] = "%s" % today
with open(local_org_ids_file, 'w') as fp:
json.dump(org_ids, fp, indent=2)
except requests.exceptions.RequestException:
if first_request:
raise # First time ever request fails
pass # Update fails

return [org_list['code'] for org_list in org_ids['lists']]
186 changes: 159 additions & 27 deletions cove_iati/fixtures/basic_iati_ruleset_errors.xml
Original file line number Diff line number Diff line change
@@ -1,63 +1,195 @@
<iati-activities version="2.01">
<iati-activities version="2.02">
<iati-activity>
<iati-identifier>AA-AAA-123123-AA123</iati-identifier>
<reporting-org ref="AA-AAA-123" type="40"><narrative>Reporting Organisation A</narrative></reporting-org>
<iati-identifier>TZ-BRLA-1-AAA-123123-AA123</iati-identifier>
<reporting-org ref="TZ-BRLA-1" type="40">
<narrative>Reporting Organisation 1</narrative>
</reporting-org>
<title><narrative>A title</narrative></title>
<description><narrative>A description</narrative></description>
<participating-org role="1" ref="AA-AAA-123"/>
<participating-org role="1" ref="TZ-BRLA-2"/>
<activity-status code="3"/>
<recipient-country code="AF" percentage="30"/>
<recipient-country code="XK" percentage="60"/>
<sector code='1'/>
<activity-date type="2" iso-date="22000101"/>
<recipient-country code="TZ" percentage="100"/>
<sector vocabulary="1" code="1"/>
<budget>
<period-start iso-date="2016-01-01"/>
<period-end iso-date="2017-01-01"/>
</budget>
<transaction>
<transaction-type code="2"/>
<transaction-date iso-date="22000101"/>
<value value-date="2017-01-01">20</value>
</transaction>
<transaction>
<transaction-type code="3"/>
<transaction-date iso-date="2200-03-03"/>
<value value-date="2012-03-03">20</value>
<transaction-date iso-date="2200-01-01"/>
<value value-date="2017-01-01">20</value>
</transaction>
<transaction>
<transaction-type code="2"/>
<transaction-date iso-date="2013-04-04"/>
<value value-date="2013-04-04">30</value>
<transaction-date iso-date="2017-01-01"/>
<value value-date="2017-01-01">20</value>
</transaction>
<transaction>
<transaction-type code="3"/>
<transaction-date iso-date="2013-05-05"/>
<value value-date="2014-05-05" >40</value>
<transaction-date iso-date="2017-01-01"/>
<value value-date="2017-01-01" >40</value>
</transaction>
</iati-activity>
<iati-activity>
<iati-identifier>BB-BBB-456456-BB456</iati-identifier>
<reporting-org ref="BB-BBB-56789" type="40"><narrative>Reporting Organisation B</narrative></reporting-org>
<iati-identifier>TZ-BRLA-3-BBB-123123-BB123</iati-identifier>
<reporting-org ref="TZ-BRLA-3" type="40">
<narrative>Reporting Organisation 3</narrative>
</reporting-org>
<title><narrative>A title</narrative></title>
<description><narrative>A description</narrative></description>
<participating-org role="1" ref="BB-BBB-456"/>
<participating-org role="1" ref="TZ-BRLA-4"/>
<activity-status code="3"/>
<activity-date type="2" iso-date="2200-01-01"/>
<recipient-country code="TZ" percentage="100"/>
<budget>
<period-start iso-date="20150101"/>
<period-end iso-date="20140101"/>
</budget>
<transaction>
<transaction-type code="2"/>
<transaction-date iso-date="2017-01-01"/>
<value value-date="24000101">10</value>
<sector vocabulary="1" code="1"/>
</transaction>
<transaction>
<transaction-type code="2"/>
<transaction-date iso-date="2017-01-01"/>
<value value-date="2200-01-01">20</value>
<sector vocabulary="1" code="1" />
</transaction>
<transaction>
<transaction-type code="2"/>
<transaction-date iso-date="2017-01-01"/>
<value value-date="2017-01-01">30</value>
<sector vocabulary="1" code="1"/>
</transaction>
<transaction>
<transaction-type code="3"/>
<transaction-date iso-date="2017-01-01"/>
<value value-date="2017-01-01">40</value>
<sector vocabulary="1" code="1"/>
</transaction>
</iati-activity>
<iati-activity>
<iati-identifier>?TZ-BRLA-5-CCC-123123-CC123</iati-identifier>
<reporting-org ref="?TZ-BRLA-5" type="40">
<narrative>Reporting Organisation 5</narrative>
</reporting-org>
<title><narrative>A title</narrative></title>
<description>
<narrative>A description</narrative>
</description>
<participating-org />
<activity-status code="3"/>
<activity-date type="2" iso-date="2013-01-01"/>
<activity-date type="2" iso-date="22000101"/>
<activity-date type="4" iso-date="24000101"/>
<recipient-country code="AF" percentage="30"/>
<recipient-country code="XK" percentage="60"/>
<sector code='1'/>
<sector vocabulary="1" code="1"/>
<budget>
<period-start iso-date="2010-01-01"/>
<period-end iso-date="2009-01-01"/>
</budget>
<transaction>
<transaction-type code="2"/>
<transaction-date iso-date="2012-01-01"/>
<value value-date="2013-01-01">10</value>
<transaction-date iso-date="2017-01-01"/>
<value value-date="2017-01-01">10</value>
<sector vocabulary="1" code="1"/>
</transaction>
<transaction>
<transaction-type code="3"/>
<transaction-date iso-date="2017-01-01"/>
<value value-date="2017-01-01">20</value>
<sector vocabulary="1" code="1"/>
</transaction>
<transaction>
<transaction-type code="2"/>
<transaction-date iso-date="2012-03-03"/>
<value value-date="2012-03-03">20</value>
<transaction-date iso-date="2017-01-01"/>
<value value-date="2017-01-01">30</value>
</transaction>
<transaction>
<transaction-type code="3"/>
<transaction-date iso-date="2017-01-01"/>
<value value-date="2017-01-01">40</value>
</transaction>
</iati-activity>
<iati-activity>
<iati-identifier>TZ-BRLA-5-DDD-123123-DD123</iati-identifier>
<reporting-org ref="TZ-BRLA-7" type="40">
<narrative>Reporting Organisation 5</narrative>
</reporting-org>
<title><narrative>A title</narrative></title>
<description>
<narrative>A description</narrative>
</description>
<participating-org role="1" ref="?TZ-BRLA-8"/>
<activity-status code="3"/>
<activity-date type="4" iso-date="2400-01-01"/>
<recipient-country code="AF" percentage="30"/>
<sector vocabulary="1" code="1"/>
<transaction>
<transaction-type code="2"/>
<transaction-date iso-date="2017-01-01"/>
<value value-date="2012-01-01">10</value>
<provider-org ref="TZ-BRLA-801"/>
</transaction>
<transaction>
<transaction-type code="3"/>
<transaction-date iso-date="2017-01-01"/>
<value value-date="2017-01-01">20</value>
<receiver-org ref="TZ-BRLA-802"/>
</transaction>
<transaction>
<transaction-type code="2"/>
<transaction-date iso-date="2017-01-01"/>
<value value-date="2017-01-01">30</value>
</transaction>
<transaction>
<transaction-type code="3"/>
<transaction-date iso-date="2017-01-01"/>
<value value-date="2017-01-01">40</value>
</transaction>
</iati-activity>
<iati-activity>
<iati-identifier>TZ-BRLA-9-EEE-123123-EE123</iati-identifier>
<reporting-org ref="TZ-BRLA-9" type="40">
<narrative>Reporting Organisation 9</narrative>
</reporting-org>
<title><narrative>A title</narrative></title>
<description>
<narrative>A description</narrative>
</description>
<participating-org role="1" ref="TZ-BRLA-10"/>
<activity-status code="3"/>
<activity-date iso-date="2017-01-01"/>
<recipient-country code="AF" percentage="30"/>
<sector vocabulary="1" code="1"/>
<transaction>
<transaction-type code="2"/>
<transaction-date iso-date="2017-01-01"/>
<value value-date="2012-01-01">10</value>
<provider-org ref="?TZ-BRLA-101"/>
</transaction>
<transaction>
<transaction-type code="3"/>
<transaction-date iso-date="2017-01-01"/>
<value value-date="2017-01-01">20</value>
<receiver-org ref="?TZ-BRLA-102"/>
</transaction>
<transaction>
<transaction-type code="2"/>
<transaction-date iso-date="2013-04-04"/>
<value value-date="2013-04-04">30</value>
<transaction-date iso-date="2017-01-01"/>
<value value-date="2017-01-01">30</value>
</transaction>
<transaction>
<transaction-type code="3"/>
<transaction-date iso-date="2013-05-05"/>
<value value-date="2013-05-05">40</value>
<transaction-date iso-date="2017-01-01"/>
<value value-date="2017-01-01">40</value>
</transaction>
</iati-activity>
</iati-activities>
Loading