Skip to content

Commit 74bc1de

Browse files
committed
End to end tests (just of traceability so far)
#21
1 parent 05fc228 commit 74bc1de

10 files changed

+151
-0
lines changed

Diff for: .github/workflows/end_to_end.yml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: End to end tests
2+
on: [push, pull_request]
3+
jobs:
4+
generate_stats:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: Checkout this repo
8+
uses: actions/checkout@v2
9+
with:
10+
persist-credentials: false
11+
- name: Set up Python 3.7
12+
uses: actions/setup-python@v2
13+
with:
14+
python-version: 3.7
15+
- uses: actions/cache@v2
16+
name: Cache dependencies
17+
with:
18+
path: ~/.cache/pip
19+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
20+
restore-keys: |
21+
${{ runner.os }}-pip-
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install -r requirements.txt
26+
- name: Install some extras
27+
run: |
28+
cd helpers
29+
git clone --branch version-2.03 https://github.com/IATI/IATI-Rulesets.git
30+
ln -s IATI-Rulesets/rulesets .
31+
./get_codelist_mapping.sh
32+
./get_codelists.sh
33+
./get_schemas.sh
34+
wget -q "https://raw.githubusercontent.com/codeforIATI/IATI-Dashboard/main/registry_id_relationships.csv"
35+
wget -q https://codeforiati.org/imf-exchangerates/imf_exchangerates_A_ENDA_USD.csv -O currency_conversion/exchange_rates.csv
36+
cd ..
37+
- name: Symlink fixtures for IATI data
38+
run: ln -s tests_end_to_end/fixtures/{data,metadata,metadata.json} .
39+
- name: Create output dir
40+
run: mkdir out
41+
- name: Generate ckan.json
42+
run: |
43+
echo '{}' > helpers/ckan.json
44+
# python helpers/ckan.py
45+
# cp ckan.json out
46+
# mv ckan.json helpers
47+
# mv metadata.json out
48+
# mv licenses.json out
49+
- name: Run loop
50+
run: python calculate_stats.py --output out/current --multi 2 loop
51+
- name: Run aggregate
52+
run: python calculate_stats.py --output out/current aggregate
53+
- name: Run invert
54+
run: python calculate_stats.py --output out/current invert
55+
- name: cat
56+
run: cat out/current/aggregated/traceable_activities_by_publisher_id.json

Diff for: run_end_to_end-tracaebility-test.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rm -r out/current; python calculate_stats.py --output out/current loop && python calculate_stats.py --output out/current aggregate && python calculate_stats.py --output out/current invert && python traceable_percentages.py > traceable_percentages.csv && diff traceable_percentages.csv.expected traceable_percentages.csv && echo 'Success'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<iati-activities version="2.03">
2+
<iati-activity>
3+
<iati-identifier>XE-EXAMPLE-BB-01</iati-identifier>
4+
</iati-activity>
5+
</iati-activities>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<iati-activities version="2.03">
2+
<iati-activity default-currency="USD">
3+
<iati-identifier>XE-EXAMPLE-CC-01</iati-identifier>
4+
<transaction>
5+
<transaction-type code="2"/>
6+
<transaction-date iso-date="2022-01-01" />
7+
<value>1000</value>
8+
</transaction>
9+
</iati-activity>
10+
<iati-activity>
11+
<iati-identifier>XE-EXAMPLE-CC-02</iati-identifier>
12+
<transaction>
13+
<transaction-type code="2"/>
14+
<transaction-date iso-date="2012-01-01" />
15+
<value currency="EUR">1000</value>
16+
</transaction>
17+
</iati-activity>
18+
<iati-activity>
19+
<iati-identifier>XE-EXAMPLE-CC-03</iati-identifier>
20+
<transaction>
21+
<transaction-type code="2"/>
22+
<transaction-date iso-date="2012-01-01" />
23+
<value currency="GBP">1000</value>
24+
</transaction>
25+
</iati-activity>
26+
</iati-activities>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<iati-activities version="2.03" default-currency="USD">
2+
<iati-activity>
3+
<iati-identifier>XE-EXAMPLE-AA-01</iati-identifier>
4+
<transaction>
5+
<transaction-type code="1"/>
6+
<transaction-date iso-date="2022-01-01" />
7+
<value>1000</value>
8+
<provider-org provider-activity-id="XE-EXAMPLE-BB-01" type="10" ref="XE-EXAMPLE-BB" />
9+
</transaction>
10+
<transaction>
11+
<transaction-type code="1"/>
12+
<transaction-date iso-date="2022-01-01" />
13+
<value>1000</value>
14+
<provider-org provider-activity-id="XE-EXAMPLE-CC-01" type="10" ref="XE-EXAMPLE-CC" />
15+
</transaction>
16+
<transaction>
17+
<transaction-type code="1"/>
18+
<transaction-date iso-date="2022-01-01" />
19+
<value>1000</value>
20+
<provider-org provider-activity-id="XE-EXAMPLE-CC-02" type="10" ref="XE-EXAMPLE-CC" />
21+
</transaction>
22+
</iati-activity>
23+
</iati-activities>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extras": [{"key":"filetype","value":"activity"}]
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extras": [{"key":"filetype","value":"activity"}]
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extras": [{"key":"filetype","value":"activity"}]
3+
}

Diff for: traceable_percentages.csv.expected

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
funder,1,1,100.0,0,0,
2+
funder2,2,3,67,2284.4666822899517,3869.2116470760116,59

Diff for: traceable_percentages.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import csv
2+
import json
3+
import sys
4+
5+
6+
traceable_activities_by_publisher = json.load(open("out/current/aggregated/traceable_activities_by_publisher_id.json"))
7+
# This may be different from the total number of activity identifiers
8+
total_activities_by_publisher = json.load(open("out/current/aggregated/traceable_activities_by_publisher_id_denominator.json"))
9+
traceable_spend_by_publisher = json.load(open("out/current/aggregated/traceable_sum_commitments_and_disbursements_by_publisher_id.json"))
10+
total_spend_by_publisher = json.load(open("out/current/aggregated/traceable_sum_commitments_and_disbursements_by_publisher_id_denominator.json"))
11+
12+
csvwriter = csv.writer(sys.stdout)
13+
14+
for publisher, total_activities in total_activities_by_publisher.items():
15+
traceable_activities = traceable_activities_by_publisher.get(publisher, 0)
16+
percentage_activities = traceable_activities / total_activities * 100
17+
traceable_spend = traceable_spend_by_publisher.get(publisher, 0)
18+
total_spend = total_spend_by_publisher.get(publisher, 0)
19+
if total_activities == 0 or traceable_activities == 0:
20+
continue
21+
csvwriter.writerow([
22+
publisher,
23+
traceable_activities,
24+
total_activities,
25+
f"{percentage_activities}" if percentage_activities == 100 else f"{percentage_activities:.2g}",
26+
traceable_spend,
27+
total_spend,
28+
"" if total_spend == 0 else f"{(traceable_spend / total_spend * 100):.2g}",
29+
])

0 commit comments

Comments
 (0)