Skip to content
This repository has been archived by the owner on Apr 22, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' into requires-io-master
Browse files Browse the repository at this point in the history
  • Loading branch information
Imogen Kutz committed Jun 18, 2018
2 parents 1d83d44 + 0088a72 commit becad3f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[run]
source =
iati_datastore
omit =
*/test/*
4 changes: 2 additions & 2 deletions iati_datastore/iatilib/crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

log = logging.getLogger("crawler")

CKAN_WEB_BASE = 'https://www.iatiregistry.org/dataset/%s'
CKAN_API = 'https://www.iatiregistry.org'
CKAN_WEB_BASE = 'https://iatiregistry.org/dataset/%s'
CKAN_API = 'https://iatiregistry.org'

registry = ckanapi.RemoteCKAN(CKAN_API)

Expand Down
2 changes: 1 addition & 1 deletion iati_datastore/iatilib/frontend/api1.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def get(self, format):


class DataStoreCSVView(DataStoreView):
def get(self, format=".csv"):
def get(self, format):
if format != ".csv":
abort(404)
return self.get_response()
Expand Down
8 changes: 6 additions & 2 deletions iati_datastore/iatilib/frontend/dsfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,13 @@ def participating_org_role(role):
)

def sector(sector_code):
return Activity.sector_percentages.any(
return or_(Activity.sector_percentages.any(
SectorPercentage.sector == sector_code
)
), Activity.transactions.any(
Transaction.sector_percentages.any(
SectorPercentage.sector == sector_code
)
))

def sector_text(sector):
return Activity.sector_percentages.any(
Expand Down
9 changes: 9 additions & 0 deletions iati_datastore/iatilib/test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,15 @@ def test_invalid_format(self):
resp = self.client.get(self.base_url + ".zzz")
self.assertEquals(404, resp.status_code)

def test_junk_before_format(self):
url = self.base_url[:-4] + '-bad.csv'
resp = self.client.get(url)
self.assertEquals(404, resp.status_code)

def test_junk_in_format(self):
url = self.base_url[:-4] + '.bad-csv'
resp = self.client.get(url)
self.assertEquals(404, resp.status_code)

class TestActivityView(ClientTestCase, ApiViewMixin):
base_url = '/api/1/access/activity.csv'
Expand Down
23 changes: 23 additions & 0 deletions iati_datastore/iatilib/test/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,29 @@ def test_by_sector(self):
self.assertIn(act_in, activities.all())
self.assertNotIn(act_not, activities.all())

def test_by_transaction_sector(self):
act_in = fac.ActivityFactory.create()
act_not = fac.ActivityFactory.create()
fac.TransactionFactory.create(
activity=act_in,
ref="12345",
sector_percentages=[
fac.SectorPercentageFactory.build(
sector=cl.Sector.primary_education),
])
fac.TransactionFactory.create(
activity=act_not,
ref="12345",
sector_percentages=[
fac.SectorPercentageFactory.build(
sector=cl.Sector.secondary_education),
])
activities = dsfilter.activities({
"sector": cl.Sector.from_string(u"11220")
})
self.assertIn(act_in, activities.all())
self.assertNotIn(act_not, activities.all())

def test_by_sector_name(self):
act_in = fac.ActivityFactory.create(
sector_percentages=[
Expand Down

0 comments on commit becad3f

Please sign in to comment.