#801 Add `all` status for fetching all the issues using the API
Merged 8 years ago by pingou. Opened 8 years ago by sayanchowdhury.
sayanchowdhury/pagure api_issues_all  into  master

file modified
+15 -20
@@ -160,7 +160,9 @@ 

      | 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 @@ 

          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)

I like this, cool :)

      else:

          issues = pagure.lib.search_issues(

              SESSION, repo, status='Open', tags=tags, assignee=assignee,

@@ -29,7 +29,6 @@ 

  

  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 @@ 

              }

          )

  

+         # 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()

no initial comment

Right now it's not possible to fetch issues of all the status using the API. This patch will resolve the issue.

Pull-Request has been updated

8 years ago

Pull-Request has been merged by pingou

8 years ago