#5056 Fix API project options/update
Merged 3 years ago by pingou. Opened 3 years ago by bmwiedemann.
bmwiedemann/pagure api-project  into  master

api/project: Extend test coverage
Bernhard M. Wiedemann • 3 years ago  
api/project: Fix handling of "false"
Bernhard M. Wiedemann • 3 years ago  
file modified
+1 -1
@@ -2828,7 +2828,7 @@ 

      if str(value).lower() in ["true"]:

          value = True

      elif str(value).lower() in ["false"]:

-         value = True

+         value = False

aouch!

      elif str(value).isdigit():

          value = int(value)

      return value

@@ -4136,6 +4136,65 @@ 

          before["settings"]["issues_default_to_private"] = True

          self.assertEqual(after, before)

  

+     def test_api_modify_project_options2(self):

+         """ Test accessing api_modify_project_options w/ auth header. """

+ 

+         # check before

+         headers = {"Authorization": "token aaabbbcccddd"}

+         output = self.app.get("/api/0/test/options", headers=headers)

+         self.assertEqual(output.status_code, 200)

+         before = json.loads(output.get_data(as_text=True))

+         self.assertEqual(

+             before,

+             {

+                 "settings": {

+                     "Enforce_signed-off_commits_in_pull-request": False,

+                     "Minimum_score_to_merge_pull-request": -1,

+                     "Only_assignee_can_merge_pull-request": False,

+                     "Web-hooks": None,

+                     "always_merge": False,

+                     "disable_non_fast-forward_merges": False,

+                     "fedmsg_notifications": True,

+                     "issue_tracker": True,

+                     "issue_tracker_read_only": False,

+                     "issues_default_to_private": False,

+                     "mqtt_notifications": True,

+                     "notify_on_commit_flag": False,

+                     "notify_on_pull-request_flag": False,

+                     "open_metadata_access_to_all": False,

+                     "project_documentation": False,

+                     "pull_request_access_only": False,

+                     "pull_requests": True,

+                     "stomp_notifications": True,

+                 },

+                 "status": "ok",

+             },

+         )

+ 

+         # Update: `issue_tracker`.

+         data = {"issue_tracker": False}

+         output = self.app.post(

+             "/api/0/test/options/update", headers=headers, data=data

+         )

+         self.assertEqual(output.status_code, 200)

+         data = json.loads(output.get_data(as_text=True))

+         self.assertEqual(

+             data,

+             {

+                 "message": "Edited successfully settings of repo: test",

+                 "status": "ok",

+             },

+         )

+ 

+         # check after

+         headers = {"Authorization": "token aaabbbcccddd"}

+         output = self.app.get("/api/0/test/options", headers=headers)

+         self.assertEqual(output.status_code, 200)

+         after = json.loads(output.get_data(as_text=True))

+         self.assertNotEqual(before, after)

+         before["settings"]["issue_tracker"] = False

+         self.assertEqual(after, before)

+ 

  

  class PagureFlaskApiProjectCreateAPITokenTests(tests.Modeltests):

      """ Tests for the flask API of pagure for creating user project API token

Many many thanks for tracking and finding this, I will not run git blame on this line of code by fear of seeing who made that accident...

If jenkins agrees, I'll merge this :)

Was from commit 473ccbe - always happy to help :-P

For the record, I'm not clicking on that link :D

2 new commits added

  • api/project: Extend test coverage
  • api/project: Fix handling of "false"
3 years ago

Something is still not right. I cannot even set values to true

Is the "Modify an existing project" API-token ACL the right one?

Am I doing something wrong in the script (see gist linked above)?

Is the "Modify an existing project" API-token ACL the right one?

Yes: https://pagure.io/pagure/blob/3c528059761a2e6d7133b2d576ea04d31eae86f8/f/pagure/api/project.py#_2843

Am I doing something wrong in the script (see gist linked above)?

Do you have the full output returned by pagure? The JSON should have some clues.

rebased onto 457dbd1

3 years ago

I was able to reproduce the issue locally and the answer is: that API endpoint did not accept JSON input, so you either have to provide the different argument as HTML arguments, or wait for the incoming PR :)

Pull-Request has been merged by pingou

3 years ago