Skip to content

Commit

Permalink
Filtering by priority tests. Closes #1668.
Browse files Browse the repository at this point in the history
  • Loading branch information
teleyinex committed Oct 4, 2017
1 parent 11db2f0 commit 0b6070f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pybossa/model/helpingmaterial.py
Expand Up @@ -16,7 +16,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with PYBOSSA. If not, see <http://www.gnu.org/licenses/>.

from sqlalchemy import Integer, Text
from sqlalchemy import Integer, Text, Float
from sqlalchemy.schema import Column, ForeignKey
from sqlalchemy.dialects.postgresql import TIMESTAMP, JSON
from pybossa.core import db
Expand Down
16 changes: 16 additions & 0 deletions test/test_api/test_api_helpingmaterial.py
Expand Up @@ -119,6 +119,22 @@ def test_query_helpingmaterial(self):
for i in range(len(helpingmaterials)):
assert helpingmaterials_by_id[i].id == data[i]['id']

# Test priority filtering
helpingmaterials.append(HelpingMaterialFactory.create(priority=1.0,
project_id=project.id))
helpingmaterials.append(HelpingMaterialFactory.create(priority=0.5,
project_id=project.id))
helpingmaterials.append(HelpingMaterialFactory.create(priority=0.1,
project_id=project.id))

url = "/api/helpingmaterial?orderby=priority&desc=true"
res = self.app.get(url)
data = json.loads(res.data)
err_msg = "It should get the last item first."
helpingmaterials_by_priority = sorted(helpingmaterials, key=lambda x: x.priority, reverse=True)
for i in range(3):
assert helpingmaterials_by_priority[i].id == data[i]['id'], (helpingmaterials_by_priority[i].id, data[i]['id'])

@with_context
def test_helpingmaterial_post(self):
"""Test API HelpingMaterialpost creation."""
Expand Down

0 comments on commit 0b6070f

Please sign in to comment.