From 70e0b054b0b44274c36edcc855c74e03f32a5cbb Mon Sep 17 00:00:00 2001
From: Lenka Segura <lenka@sepu.cz>
Date: Jan 04 2019 15:25:02 +0000
Subject: [PATCH 1/2] add PRs and assignee data to dev-data.py


---

diff --git a/dev-data.py b/dev-data.py
index b540734..0197be1 100644
--- a/dev-data.py
+++ b/dev-data.py
@@ -354,11 +354,83 @@ def insert_data(session, username, user_email):
         repo_to=repo,
         branch_to='master',
         title='Fixing code for unittest',
-        user=username
+        user=username,
+        status="Open"
     )
     session.commit()
 
-    ######################################
+    repo = pagure.lib.query.get_authorized_project(session, 'test')
+    forked_repo = pagure.lib.query.get_authorized_project(session, 'test')
+    req = pagure.lib.query.new_pull_request(
+        session=session,
+        repo_from=forked_repo,
+        branch_from='master',
+        repo_to=repo,
+        branch_to='master',
+        title='add very nice README',
+        user=username,
+        status="Open"
+    )
+    session.commit()
+
+    repo = pagure.lib.query.get_authorized_project(session, 'test')
+    forked_repo = pagure.lib.query.get_authorized_project(session, 'test')
+    req = pagure.lib.query.new_pull_request(
+        session=session,
+        repo_from=forked_repo,
+        branch_from='master',
+        repo_to=repo,
+        branch_to='master',
+        title='Add README',
+        user=username,
+        status="Closed"
+    )
+    session.commit()
+
+    repo = pagure.lib.query.get_authorized_project(session, 'test')
+    forked_repo = pagure.lib.query.get_authorized_project(session, 'test')
+    req = pagure.lib.query.new_pull_request(
+        session=session,
+        repo_from=forked_repo,
+        branch_from='master',
+        repo_to=repo,
+        branch_to='master',
+        title='Fix some containers',
+        user=username,
+        status="Merged"
+    )
+    session.commit()
+
+    repo = pagure.lib.query.get_authorized_project(session, 'test')
+    forked_repo = pagure.lib.query.get_authorized_project(session, 'test')
+    req = pagure.lib.query.new_pull_request(
+        session=session,
+        repo_from=forked_repo,
+        branch_from='master',
+        repo_to=repo,
+        branch_to='master',
+        title='Fix pull request statuses',
+        user=username,
+        status="Closed"
+    )
+    session.commit()
+
+    repo = pagure.lib.query.get_authorized_project(session, 'test')
+    forked_repo = pagure.lib.query.get_authorized_project(session, 'test')
+    req = pagure.lib.query.new_pull_request(
+        session=session,
+        repo_from=forked_repo,
+        branch_from='master',
+        repo_to=repo,
+        branch_to='master',
+        title='Fixing UI of issue',
+        user=username,
+        status="Merged"
+    )
+    session.commit()
+
+
+#####################################
     # tokens
     tests.create_tokens(session, user_id=pingou.id, project_id=project1.id)
 
@@ -425,12 +497,40 @@ def insert_data(session, username, user_email):
         percent=80,
         comment="Jenkins build passes",
         url=str(pr.id),
-        status="Open"
+        status="success"
+    )
+    session.add(item)
+    session.commit()
+
+    pr = pagure.lib.query.get_pull_request_of_user(session, "foo")[1]
+    item = pagure.lib.model.PullRequestFlag(
+        uid="oink oink uid",
+        pull_request_uid=pr.uid,
+        user_id=pingou.id,
+        username=pingou.user,
+        percent=80,
+        comment="Jenkins does not pass",
+        url=str(pr.id),
+        status="failure"
     )
     session.add(item)
     session.commit()
 
     ######################################
+    # pull_request_assignee
+    pr = pagure.lib.query.search_pull_requests(session, requestid='1006')
+    pr.assignee_id = pingou.id
+    session.commit()
+
+    pr = pagure.lib.query.search_pull_requests(session, requestid='1007')
+    pr.assignee_id = you.id
+    session.commit()
+
+    pr = pagure.lib.query.search_pull_requests(session, requestid='1004')
+    pr.assignee_id = foo.id
+    session.commit()
+
+    ######################################
     # tags_issues
     repo = pagure.lib.query.get_authorized_project(session, 'test')
     issues = pagure.lib.query.search_issues(session, repo)

From 26e29c21f22a6bd9df937348fae44e44713df21d Mon Sep 17 00:00:00 2001
From: Lenka Segura <lenka@sepu.cz>
Date: Jan 04 2019 15:25:02 +0000
Subject: [PATCH 2/2] fix PR filtering by status in API calls


---

diff --git a/pagure/api/fork.py b/pagure/api/fork.py
index c2b7e71..0f563d9 100644
--- a/pagure/api/fork.py
+++ b/pagure/api/fork.py
@@ -164,7 +164,7 @@ def api_pull_request_views(repo, username=None, namespace=None):
 
     status_text = ("%s" % status).lower()
     requests = []
-    if status_text in ["0", "false", "closed"]:
+    if status_text in ["0", "false"]:
         requests = pagure.lib.query.search_pull_requests(
             flask.g.session,
             project_id=repo.id,
diff --git a/tests/test_pagure_flask_api_fork.py b/tests/test_pagure_flask_api_fork.py
index e6b546c..267d27c 100644
--- a/tests/test_pagure_flask_api_fork.py
+++ b/tests/test_pagure_flask_api_fork.py
@@ -139,8 +139,7 @@ class PagureFlaskApiForktests(tests.Modeltests):
 
         # Close the PR and try again
         pagure.lib.query.close_pull_request(
-            self.session, request=req, user='pingou',
-            merged=False)
+            self.session, request=req, user='pingou', merged=False)
 
         output = self.app.get('/api/0/test/pull-requests?status=closed')
         self.assertEqual(output.status_code, 200)
@@ -160,6 +159,95 @@ class PagureFlaskApiForktests(tests.Modeltests):
         )
         self.assertEqual(data['total_requests'], 1)
 
+        # Create two closed pull-requests
+        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        forked_repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        pagure.lib.query.new_pull_request(
+            session=self.session,
+            repo_from=forked_repo,
+            branch_from='master',
+            repo_to=repo,
+            branch_to='master',
+            title='closed pullrequest by user foo on repo test',
+            user='foo',
+            status='Closed',
+        )
+
+        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        forked_repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        pagure.lib.query.new_pull_request(
+            session=self.session,
+            repo_from=forked_repo,
+            branch_from='master',
+            repo_to=repo,
+            branch_to='master',
+            title='closed pullrequest by user pingou on repo test',
+            user='pingou',
+            status="Closed",
+        )
+        self.session.commit()
+
+        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        forked_repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        pagure.lib.query.new_pull_request(
+            session=self.session,
+            repo_from=forked_repo,
+            branch_from='master',
+            repo_to=repo,
+            branch_to='master',
+            title='merged pullrequest by user pingou on repo test',
+            user='pingou',
+            status="Merged",
+        )
+        self.session.commit()
+
+        repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        forked_repo = pagure.lib.query.get_authorized_project(self.session, 'test')
+        pagure.lib.query.new_pull_request(
+            session=self.session,
+            repo_from=forked_repo,
+            branch_from='master',
+            repo_to=repo,
+            branch_to='master',
+            title='merged pullrequest by user foo on repo test',
+            user='foo',
+            status='Merged',
+        )
+        self.session.commit()
+
+        # Test the API view of closed pull-requests
+        output = self.app.get(
+            '/api/0/test/pull-requests?status=closed')
+        self.assertEqual(output.status_code, 200)
+        data = json.loads(output.get_data(as_text=True))
+
+        self.assertEqual(len(data['requests']), 3)
+        self.assertEqual(
+            sorted(data.keys()),
+            [u'args', u'pagination', u'requests', u'total_requests'])
+        for req in data['requests']:
+            self.assertEqual(req['status'], 'Closed')
+        self.assertEqual(data['args']['status'], "closed")
+        self.assertEqual(data['args']['page'], 1)
+
+        self.assertEqual(data['total_requests'], 3)
+
+        # Test the API view of merged pull-requests
+        output = self.app.get(
+            '/api/0/test/pull-requests?status=merged')
+        self.assertEqual(output.status_code, 200)
+        data = json.loads(output.get_data(as_text=True))
+
+        self.assertEqual(len(data['requests']), 2)
+        self.assertEqual(
+            sorted(data.keys()),
+            [u'args', u'pagination', u'requests', u'total_requests'])
+        for req in data['requests']:
+            self.assertEqual(req['status'], 'Merged')
+        self.assertEqual(data['args']['status'], "merged")
+        self.assertEqual(data['args']['page'], 1)
+        self.assertEqual(data['total_requests'], 2)       
+ 
     @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
     def test_api_pull_request_views_all_pr(self):
         """ Test the api_pull_request_views method of the flask api to list

