Skip to content

Commit

Permalink
Merge pull request #871 from eciis/fix-get-all-institutions
Browse files Browse the repository at this point in the history
Fix query handler to find only active institutions
  • Loading branch information
mayzabeel authored Mar 6, 2018
2 parents fdc9654 + b3a8584 commit 06bd7c4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion backend/handlers/institution_collection_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def get(self, user):
"""Get all institutions."""

INSTITUTION_ATTRIBUTES = ['name', 'key', 'acronym', 'address', 'photo_url', 'description']
ACTIVE_STATE = "active"

page = to_int(
self.request.get('page', Utils.DEFAULT_PAGINATION_OFFSET),
Expand All @@ -33,7 +34,7 @@ def get(self, user):
QueryException,
"Query param limit must be an integer")

queryInstitutions = Institution.query()
queryInstitutions = Institution.query(Institution.state == ACTIVE_STATE)

queryInstitutions, more = offset_pagination(
page,
Expand Down
12 changes: 9 additions & 3 deletions backend/test/institution_collection_handler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ def test_get(self, verify_token):
user = mocks.create_user('[email protected]')
# new Institution FIRST INST
first_inst = mocks.create_institution('FIRST INST')
# new Institution SECOND INST
first_inst.state = "active"
first_inst.put()
# new Institution SECOND INST with pending state default
second_inst = mocks.create_institution('SECOND INST')
# new Institution THIRD INST
third_inst = mocks.create_institution('THIRD INST')
third_inst.state = "active"
third_inst.put()

# Call the get method
all_institutions = self.testapp.get("/api/institutions?page=0&&limit=2").json
Expand All @@ -43,5 +49,5 @@ def test_get(self, verify_token):
self.assertEqual(all_institutions['institutions'][0]['name'], first_inst.name,
"The name of institituion should be equal to the first_inst name")

self.assertEqual(all_institutions['institutions'][1]['name'], second_inst.name,
"The name of institution should be equal to the second_inst name")
self.assertEqual(all_institutions['institutions'][1]['name'], third_inst.name,
"The name of institution should be equal to the third_inst name")

0 comments on commit 06bd7c4

Please sign in to comment.