diff --git a/pagure/api/fork.py b/pagure/api/fork.py index 1dc7f5e..89d495f 100644 --- a/pagure/api/fork.py +++ b/pagure/api/fork.py @@ -648,13 +648,39 @@ def api_pull_request_add_flag(repo, requestid, username=None, namespace=None): :: { - "message": "Flag added" + "flag": { + "comment": "Tests failed", + "date_created": "1510742565", + "percent": 0, + "pull_request_uid": "62b49f00d489452994de5010565fab81", + "url": "http://jenkins.cloud.fedoraproject.org/", + "user": { + "default_email": "bar@pingou.com", + "emails": ["bar@pingou.com", "foo@pingou.com"], + "fullname": "PY C", + "name": "pingou"}, + "username": "Jenkins"}, + "message": u"Flag added", + "uid": u"jenkins_build_pagure_100+seed" } :: { - "message": "Flag updated" + "flag": { + "comment": "Tests failed", + "date_created": "1510742565", + "percent": 0, + "pull_request_uid": "62b49f00d489452994de5010565fab81", + "url": "http://jenkins.cloud.fedoraproject.org/", + "user": { + "default_email": "bar@pingou.com", + "emails": ["bar@pingou.com", "foo@pingou.com"], + "fullname": "PY C", + "name": "pingou"}, + "username": "Jenkins"}, + "message": u"Flag updated", + "uid": u"jenkins_build_pagure_100+seed" } """ # noqa @@ -690,7 +716,7 @@ def api_pull_request_add_flag(repo, requestid, username=None, namespace=None): uid = form.uid.data.strip() if form.uid.data else None try: # New Flag - message = pagure.lib.add_pull_request_flag( + message, uid = pagure.lib.add_pull_request_flag( SESSION, request=request, username=username, @@ -703,7 +729,10 @@ def api_pull_request_add_flag(repo, requestid, username=None, namespace=None): requestfolder=APP.config['REQUESTS_FOLDER'], ) SESSION.commit() + pr_flag = pagure.lib.get_pull_request_flag_by_uid(SESSION, uid) output['message'] = message + output['uid'] = uid + output['flag'] = pr_flag.to_json() except pagure.exceptions.PagureException as err: raise pagure.exceptions.APIError( 400, error_code=APIERROR.ENOCODE, error=str(err)) diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 754da8a..77e1c57 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -1316,7 +1316,7 @@ def add_pull_request_flag(session, request, username, percent, comment, url, redis=REDIS, ) - return 'Flag %s' % action + return ('Flag %s' % action, pr_flag.uid) def new_project(session, user, name, blacklist, allowed_prefix, diff --git a/pagure/lib/model.py b/pagure/lib/model.py index 05e3f90..236793b 100644 --- a/pagure/lib/model.py +++ b/pagure/lib/model.py @@ -2001,7 +2001,6 @@ class PullRequestFlag(BASE): ''' output = { - 'uid': self.uid, 'pull_request_uid': self.pull_request_uid, 'username': self.username, 'percent': self.percent, diff --git a/tests/test_pagure_flask_api_fork.py b/tests/test_pagure_flask_api_fork.py index 5c10619..8e52ff9 100644 --- a/tests/test_pagure_flask_api_fork.py +++ b/tests/test_pagure_flask_api_fork.py @@ -31,6 +31,8 @@ import tests class PagureFlaskApiForktests(tests.Modeltests): """ Tests for the flask API of pagure for issue """ + maxDiff = None + def setUp(self): """ Set up the environnment, ran before every tests. """ super(PagureFlaskApiForktests, self).setUp() @@ -1064,9 +1066,26 @@ class PagureFlaskApiForktests(tests.Modeltests): '/api/0/test/pull-request/1/flag', data=data, headers=headers) self.assertEqual(output.status_code, 200) data = json.loads(output.data) + data['flag']['date_created'] = u'1510742565' + data['flag']['pull_request_uid'] = u'62b49f00d489452994de5010565fab81' self.assertDictEqual( data, - {'message': 'Flag added'} + { + u'flag': { + u'comment': u'Tests failed', + u'date_created': u'1510742565', + u'percent': 0, + u'pull_request_uid': u'62b49f00d489452994de5010565fab81', + u'url': u'http://jenkins.cloud.fedoraproject.org/', + u'user': { + u'default_email': u'bar@pingou.com', + u'emails': [u'bar@pingou.com', u'foo@pingou.com'], + u'fullname': u'PY C', + u'name': u'pingou'}, + u'username': u'Jenkins'}, + u'message': u'Flag added', + u'uid': u'jenkins_build_pagure_100+seed' + } ) # One flag added @@ -1089,9 +1108,26 @@ class PagureFlaskApiForktests(tests.Modeltests): '/api/0/test/pull-request/1/flag', data=data, headers=headers) self.assertEqual(output.status_code, 200) data = json.loads(output.data) + data['flag']['date_created'] = u'1510742565' + data['flag']['pull_request_uid'] = u'62b49f00d489452994de5010565fab81' self.assertDictEqual( data, - {'message': 'Flag updated'} + { + u'flag': { + u'comment': u'Tests passed', + u'date_created': u'1510742565', + u'percent': 100, + u'pull_request_uid': u'62b49f00d489452994de5010565fab81', + u'url': u'http://jenkins.cloud.fedoraproject.org/', + u'user': { + u'default_email': u'bar@pingou.com', + u'emails': [u'bar@pingou.com', u'foo@pingou.com'], + u'fullname': u'PY C', + u'name': u'pingou'}, + u'username': u'Jenkins'}, + u'message': u'Flag updated', + u'uid': u'jenkins_build_pagure_100+seed' + } ) # One flag added @@ -1212,9 +1248,26 @@ class PagureFlaskApiForktests(tests.Modeltests): '/api/0/test/pull-request/1/flag', data=data, headers=headers) self.assertEqual(output.status_code, 200) data = json.loads(output.data) + data['flag']['date_created'] = u'1510742565' + data['flag']['pull_request_uid'] = u'62b49f00d489452994de5010565fab81' self.assertDictEqual( data, - {'message': 'Flag added'} + { + u'flag': { + u'comment': u'Tests failed', + u'date_created': u'1510742565', + u'percent': 0, + u'pull_request_uid': u'62b49f00d489452994de5010565fab81', + u'url': u'http://jenkins.cloud.fedoraproject.org/', + u'user': { + u'default_email': u'bar@pingou.com', + u'emails': [u'bar@pingou.com', u'foo@pingou.com'], + u'fullname': u'PY C', + u'name': u'pingou'}, + u'username': u'Jenkins'}, + u'message': u'Flag added', + u'uid': u'jenkins_build_pagure_100+seed' + } ) # One flag added @@ -1237,9 +1290,26 @@ class PagureFlaskApiForktests(tests.Modeltests): '/api/0/test/pull-request/1/flag', data=data, headers=headers) self.assertEqual(output.status_code, 200) data = json.loads(output.data) + data['flag']['date_created'] = u'1510742565' + data['flag']['pull_request_uid'] = u'62b49f00d489452994de5010565fab81' self.assertDictEqual( data, - {'message': 'Flag updated'} + { + u'flag': { + u'comment': u'Tests passed', + u'date_created': u'1510742565', + u'percent': 100, + u'pull_request_uid': u'62b49f00d489452994de5010565fab81', + u'url': u'http://jenkins.cloud.fedoraproject.org/', + u'user': { + u'default_email': u'bar@pingou.com', + u'emails': [u'bar@pingou.com', u'foo@pingou.com'], + u'fullname': u'PY C', + u'name': u'pingou'}, + u'username': u'Jenkins'}, + u'message': u'Flag updated', + u'uid': u'jenkins_build_pagure_100+seed' + } ) # One flag added diff --git a/tests/test_pagure_flask_api_ui_private_repo.py b/tests/test_pagure_flask_api_ui_private_repo.py index 12d5bb6..0346a74 100644 --- a/tests/test_pagure_flask_api_ui_private_repo.py +++ b/tests/test_pagure_flask_api_ui_private_repo.py @@ -1653,9 +1653,26 @@ class PagurePrivateRepotest(tests.Modeltests): '/api/0/test4/pull-request/1/flag', data=data, headers=headers) self.assertEqual(output.status_code, 200) data = json.loads(output.get_data(as_text=True)) + data['flag']['date_created'] = u'1510742565' + data['flag']['pull_request_uid'] = u'62b49f00d489452994de5010565fab81' self.assertDictEqual( data, - {'message': 'Flag added'} + { + u'flag': { + u'comment': u'Tests failed', + u'date_created': u'1510742565', + u'percent': 0, + u'pull_request_uid': u'62b49f00d489452994de5010565fab81', + u'url': u'http://jenkins.cloud.fedoraproject.org/', + u'user': { + u'default_email': u'bar@pingou.com', + u'emails': [u'bar@pingou.com', u'foo@pingou.com'], + u'fullname': u'PY C', + u'name': u'pingou'}, + u'username': u'Jenkins'}, + u'message': u'Flag added', + u'uid': u'jenkins_build_pagure_100+seed' + } ) # One flag added @@ -1678,9 +1695,26 @@ class PagurePrivateRepotest(tests.Modeltests): '/api/0/test4/pull-request/1/flag', data=data, headers=headers) self.assertEqual(output.status_code, 200) data = json.loads(output.get_data(as_text=True)) + data['flag']['date_created'] = u'1510742565' + data['flag']['pull_request_uid'] = u'62b49f00d489452994de5010565fab81' self.assertDictEqual( data, - {'message': 'Flag updated'} + { + u'flag': { + u'comment': u'Tests passed', + u'date_created': u'1510742565', + u'percent': 100, + u'pull_request_uid': u'62b49f00d489452994de5010565fab81', + u'url': u'http://jenkins.cloud.fedoraproject.org/', + u'user': { + u'default_email': u'bar@pingou.com', + u'emails': [u'bar@pingou.com', u'foo@pingou.com'], + u'fullname': u'PY C', + u'name': u'pingou'}, + u'username': u'Jenkins'}, + u'message': u'Flag updated', + u'uid': u'jenkins_build_pagure_100+seed' + } ) # One flag added diff --git a/tests/test_pagure_lib.py b/tests/test_pagure_lib.py index 0ebd630..9f17980 100644 --- a/tests/test_pagure_lib.py +++ b/tests/test_pagure_lib.py @@ -2601,7 +2601,7 @@ class PagureLibtests(tests.Modeltests): token='aaabbbcccddd', requestfolder=None, ) - self.assertEqual(msg, 'Flag added') + self.assertEqual(msg, ('Flag added', 'jenkins_build_pagure_34')) self.session.commit() self.assertEqual(len(request.flags), 1)