#30 Added 4 API methods and their testcases for getting more stats of pagure users
Merged 6 years ago by cverna. Opened 6 years ago by pnemade.
Unknown source master  into  master

file modified
+107
@@ -520,6 +520,113 @@

  

          return return_value

  

+     def user_activity_stats(self, username, format=None):

+         """

+         Retrieve the activity stats about a specific user over the last year.

+ 

+         Params:

+             username (string): filters the username of the user whose activity you are interested in.

+             format (string): Allows changing the of the date/time returned from iso format

+                              to unix timestamp Can be: timestamp or isoformat

+         Returns:

+             dict: A dictionary of activities done by a given user for all the projects

+                   for a given Pagure instance.

+         """

+         request_url = "{}/api/0/user/{}/activity/stats".format(self.instance, username)

+ 

+         payload = {}

+         if username is not None:

+             payload['username'] = username

+         if format is not None:

+             payload['format'] = format

+ 

+         return_value = self._call_api(request_url, params=payload)

+ 

+         return return_value

+ 

+     def user_activity_stats_by_date(self, username, date, grouped=None):

+         """

+          Retrieve activity information about a specific user on the specified date.

+ 

+         Params:

+             username (string): filters the username of the user whose activity you are interested in.

+             date (string): filters by the date of interest, best provided in ISO format: YYYY-MM-DD

+             grouped (boolean): filters whether or not to group the commits

+ 

+         Returns:

+             list: A list of activities done by a given user on some particular

+                   date for all the projects for given Pagure instance.

+         """

+         request_url = "{}/api/0/user/{}/activity/{}".format(self.instance, username, date)

+ 

+         payload = {}

+         if username is not None:

+             payload['username'] = username

+         if date is not None:

+             payload['date'] = date

+         if grouped is not None:

+             payload['grouped'] = grouped

+ 

+         return_value = self._call_api(request_url, params=payload)

+ 

+         return return_value['activities']

+ 

+     def list_pull_requests(self, username, page, status=None):

+         """

+         List pull-requests filed by user.

+ 

+         Params:

+             username (string): filters the username of the user whose activity you are interested in.

+             page (integer): the page requested. Defaults to 1.

+             status (string): filter the status of pull requests. Default: Open,

+                              can be Closed, Merged, All.

+ 

+         Returns:

+             list: A list of Pull-Requests filed by a given user for all the

+                   projects for given Pagure instance.

+         """

+         request_url = "{}/api/0/user/{}/requests/filed".format(self.instance, username)

+ 

+         payload = {}

+         if username is not None:

+             payload['username'] = username

+         if page is not None:

+             payload['page'] = page

+         if status is not None:

+             payload['status'] = status

+ 

+         return_value = self._call_api(request_url, params=payload)

+ 

+         return return_value['requests']

+ 

+     def list_prs_actionable_by_user(self, username, page, status=None):

+         """

+         List PRs actionable by user.

+ 

+         Params:

+             username (string): filters the username of the user whose activity you are interested in.

+             page (integer): the page requested. Defaults to 1.

+             status (string): filter the status of pull requests. Default: Open,

+                              can be Closed, Merged, All.

+ 

+         Returns:

+             list: A list of Pull-Requests a user is able to action for all the

+                   projects for given Pagure instance.

+         """

+         request_url = "{}/api/0/user/{}/requests/actionable".format(self.instance, username)

+ 

+         payload = {}

+         if username is not None:

+             payload['username'] = username

+         if page is not None:

+             payload['page'] = page

+         if status is not None:

+             payload['status'] = status

+ 

+         return_value = self._call_api(request_url, params=payload)

+ 

+         return return_value['requests']

+ 

      def new_project(self, name, description, namespace=None, url=None,

                      avatar_email=None, create_readme=False, private=False):

          """

file modified
+33
@@ -280,3 +280,36 @@

      simple_pg.project_branches()

      Pagure._call_api.assert_called_once_with(

          'https://pagure.io/api/0/testrepo/git/branches')

+ 

+ def test_user_activity_stats(mocker, simple_pg):

+     """ Test the API call to get stats about a user activity"""

+     mocker.patch('libpagure.Pagure._call_api')

+     simple_pg.user_activity_stats('auser')

+     expected = {'username': 'auser'}

+     Pagure._call_api.assert_called_once_with(

+         'https://pagure.io/api/0/user/auser/activity/stats', params=expected)

+ 

+ def test_user_activity_stats_by_date(mocker, simple_pg):

+     """ Test the API call to get stats about a user activity by specific date"""

+     mocker.patch('libpagure.Pagure._call_api')

+     simple_pg.user_activity_stats_by_date('auser',"2017-12-30")

+     expected = {'username': 'auser', 'date' : '2017-12-30'}

+     Pagure._call_api.assert_called_once_with(

+         'https://pagure.io/api/0/user/auser/activity/2017-12-30', params=expected)

+ 

+ def test_list_pull_requests(mocker, simple_pg):

+     """ Test the API call to get stats about a user's pull requests"""

+     mocker.patch('libpagure.Pagure._call_api')

+     simple_pg.list_pull_requests('auser', 1)

+     expected = {'username': 'auser', 'page': 1}

+     Pagure._call_api.assert_called_once_with(

+         'https://pagure.io/api/0/user/auser/requests/filed', params=expected)

+ 

+ 

+ def test_list_prs_actionable_by_user(mocker, simple_pg):

+     """ Test the API call to list PR's actionable for a given user"""

+     mocker.patch('libpagure.Pagure._call_api')

+     simple_pg.list_prs_actionable_by_user('auser', 1)

+     expected = {'username': 'auser', 'page': 1}

+     Pagure._call_api.assert_called_once_with(

+         'https://pagure.io/api/0/user/auser/requests/actionable', params=expected)

  • user_activity_stats
  • user_activity_stats_by_date
  • list_pull_requests
  • list_prs_actionable_by_user

Signed-off-by: Parag Nemade pnemade@fedoraproject.org

can some please review this pull-request?

It would be good to document the return value and its type here.

If username can be None won't that form an invalid request_url above?

Same here - shouldn't username be required and not default to None? Same for date. Won't these form an invalid URL?

It'd be good to document the return value and its type here.

This seems copy/pasted since it is identical to the first method, including the typo. It also seems that this isn't what this method does given the name of the method.

The name would imply that this is not an accurate description of this method.

This description needs to be updated as well.

Similar problems with username here.

It'd be good to document the return value and its type here.

It would be good to document the types of all these parameters, and the parameters in all the other new methods as well.

This description should be updated too.

It'd be good to document the return value, its type, and the type of all the parameters.

I recommend tests for these new methods.

rebased onto 29487b9

6 years ago

Thanks for your brief review @bowlofeggs

I will work on adding tests.

@bowlofeggs Sorry I was away from this work and want to resume here but I also see @cverna started working on writing test framework for this project. So I request please can you merge this? at least let all others use this really important missing functionality from this PR.

Once that PR#34 gets merged I can add tests for these 4 API methods.

@pnemade I just need #34 to be reviewed and +1 then I can merge it. If you want to give it a go please feel free.

yeah I am just looking into it right now ;-)

hm so I am not sure with the merge of all other PR's if this PR still able to merge or not

hm so I am not sure with the merge of all other PR's if this PR still able to merge or not

It looks ok and we can merge it with a merge commit.

if you want you can rebase your branch so that we keep the git history linear. Also do you want to add tests ?

rebased onto 59507ab

6 years ago

rebased onto 16c2869

6 years ago

@cverna Can you please review the testcases and if looks good merge this PR?

rebased onto a6e4e7a

6 years ago

Look good to me. Let's merge.

Thanks

Pull-Request has been merged by cverna

6 years ago

Thank you for your review and merge.