From 85a8f6268986d86d9311d3254eb3878fe764d1f3 Mon Sep 17 00:00:00 2001 From: Sayan Chowdhury Date: Mar 08 2016 13:54:22 +0000 Subject: [PATCH 1/2] Add a status all in the api the fetch all the issues from pagure --- diff --git a/pagure/api/issue.py b/pagure/api/issue.py index c570b14..4430177 100644 --- a/pagure/api/issue.py +++ b/pagure/api/issue.py @@ -160,7 +160,9 @@ def api_view_issues(repo, username=None): | Key | Type | Optionality | Description | +===============+=========+==============+===========================+ | ``status`` | string | Optional | | Filters the status of | - | | | | issues. Default: | + | | | | issues. Fetches all the | + | | | | issues if status is | + | | | | ``all``. Default: | | | | | ``Open`` | +---------------+---------+--------------+---------------------------+ | ``tags`` | string | Optional | | A list of tags you | @@ -246,26 +248,19 @@ def api_view_issues(repo, username=None): private = None if status is not None: + params = { + 'session': SESSION, + 'repo': repo, + 'tags': tags, + 'assignee': assignee, + 'author': author, + 'private': private + } if status.lower() == 'closed': - issues = pagure.lib.search_issues( - SESSION, - repo, - closed=True, - tags=tags, - assignee=assignee, - author=author, - private=private, - ) - else: - issues = pagure.lib.search_issues( - SESSION, - repo, - status=status, - tags=tags, - assignee=assignee, - author=author, - private=private, - ) + params.update({'closed': True}) + elif status.lower() != 'all': + params.update({'status': status}) + issues = pagure.lib.search_issues(**params) else: issues = pagure.lib.search_issues( SESSION, repo, status='Open', tags=tags, assignee=assignee, From e3c0af6437078b752b84531f3ec85703841d9713 Mon Sep 17 00:00:00 2001 From: Sayan Chowdhury Date: Mar 08 2016 14:18:54 +0000 Subject: [PATCH 2/2] Add tests for fetching all the issues from the API --- diff --git a/tests/test_pagure_flask_api_issue.py b/tests/test_pagure_flask_api_issue.py index 794e230..0675beb 100644 --- a/tests/test_pagure_flask_api_issue.py +++ b/tests/test_pagure_flask_api_issue.py @@ -29,7 +29,6 @@ import tests class PagureFlaskApiIssuetests(tests.Modeltests): """ Tests for the flask API of pagure for issue """ - def setUp(self): """ Set up the environnment, ran before every tests. """ super(PagureFlaskApiIssuetests, self).setUp() @@ -374,6 +373,61 @@ class PagureFlaskApiIssuetests(tests.Modeltests): } ) + # List all issues + output = self.app.get('/api/0/test/issues?status=All', headers=headers) + self.assertEqual(output.status_code, 200) + data = json.loads(output.data) + data['issues'][0]['date_created'] = '1431414800' + data['issues'][1]['date_created'] = '1431414800' + self.assertDictEqual( + data, + { + "args": { + "assignee": None, + "author": None, + "status": "All", + "tags": [] + }, + "total_issues": 2, + "issues": [ + { + "assignee": None, + "blocks": [], + "comments": [], + "content": "This issue needs attention", + "date_created": "1431414800", + "depends": [], + "id": 1, + "private": False, + "status": "Open", + "tags": [], + "title": "test issue", + "user": { + "fullname": "PY C", + "name": "pingou" + } + }, + { + "assignee": None, + "blocks": [], + "comments": [], + "content": "We should work on this", + "date_created": "1431414800", + "depends": [], + "id": 2, + "private": True, + "status": "Open", + "tags": [], + "title": "Test issue", + "user": { + "fullname": "PY C", + "name": "pingou" + } + } + ], + } + ) + def test_api_view_issue(self): """ Test the api_view_issue method of the flask api. """ self.test_api_new_issue()