浏览代码

Fix the unit-tests

- Fix style error from code removed where imports are no longer needed
- Fix the data returned by the internal API when we moving calculating
  the diff of branches to a worker
- Fix tests with the ordering of the flags returned

Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
Pierre-Yves Chibon 5 年之前
父节点
当前提交
f523b91d3a

+ 0 - 2
pagure/hooks/pagure_force_commit.py

@@ -13,7 +13,6 @@ from __future__ import unicode_literals
 import sys
 
 import sqlalchemy as sa
-import pygit2
 import wtforms
 
 try:
@@ -26,7 +25,6 @@ from sqlalchemy.orm import backref
 import pagure.lib.git
 from pagure.hooks import BaseHook, BaseRunner, RequiredIf
 from pagure.lib.model import BASE, Project
-from pagure.utils import get_repo_path
 
 
 class PagureForceCommitTable(BASE):

+ 2 - 2
pagure/hooks/pagure_hook.py

@@ -11,7 +11,6 @@
 from __future__ import unicode_literals
 
 import logging
-import os
 
 import pygit2
 import sqlalchemy as sa
@@ -29,7 +28,7 @@ import pagure.config
 import pagure.lib.git
 from pagure.hooks import BaseHook, BaseRunner
 from pagure.lib.model import BASE, Project
-from pagure.utils import get_repo_path
+
 
 _log = logging.getLogger(__name__)
 pagure_config = pagure.config.reload_config()
@@ -308,3 +307,4 @@ class PagureHook(BaseHook):
     db_object = PagureTable
     backref = "pagure_hook"
     form_fields = ["active"]
+    runner = PagureRunner

+ 0 - 1
pagure/hooks/pagure_no_new_branches.py

@@ -23,7 +23,6 @@ from sqlalchemy.orm import backref
 
 from pagure.hooks import BaseHook, BaseRunner
 from pagure.lib.model import BASE, Project
-from pagure.utils import get_repo_path
 
 
 class PagureNoNewBranchesTable(BASE):

+ 0 - 58
pagure/hooks/pagure_request_hook.py

@@ -10,9 +10,6 @@
 
 from __future__ import unicode_literals
 
-import os
-
-import flask
 import sqlalchemy as sa
 import wtforms
 
@@ -24,7 +21,6 @@ from sqlalchemy.orm import relation
 from sqlalchemy.orm import backref
 
 import pagure.lib.git
-from pagure.config import config as pagure_config
 from pagure.hooks import BaseHook, BaseRunner
 from pagure.lib.model import BASE, Project
 
@@ -125,57 +121,3 @@ class PagureRequestHook(BaseHook):
     backref = "pagure_hook_requests"
     form_fields = ["active"]
     runner = PagureRequestRunner
-
-    @classmethod
-    def set_up(cls, project):
-        """ Install the generic post-receive hook that allow us to call
-        multiple post-receive hooks as set per plugin.
-        """
-        repopath = os.path.join(pagure_config["REQUESTS_FOLDER"], project.path)
-        if not os.path.exists(repopath):
-            flask.abort(404, "No git repo found")
-
-        hook_files = os.path.join(
-            os.path.dirname(os.path.realpath(__file__)), "files"
-        )
-
-        # Make sure the hooks folder exists
-        hookfolder = os.path.join(repopath, "hooks")
-        if not os.path.exists(hookfolder):
-            os.makedirs(hookfolder)
-
-        # Install the main post-receive file
-        postreceive = os.path.join(hookfolder, "post-receive")
-        hook_file = os.path.join(hook_files, "post-receive")
-        if not os.path.exists(postreceive):
-            os.symlink(hook_file, postreceive)
-
-    @classmethod
-    def install(cls, project, dbobj):
-        """ Method called to install the hook for a project.
-
-        :arg project: a ``pagure.model.Project`` object to which the hook
-            should be installed
-
-        """
-        repopaths = [
-            os.path.join(pagure_config["REQUESTS_FOLDER"], project.path)
-        ]
-
-        cls.base_install(
-            repopaths, dbobj, "pagure-requests", "pagure_hook_requests.py"
-        )
-
-    @classmethod
-    def remove(cls, project):
-        """ Method called to remove the hook of a project.
-
-        :arg project: a ``pagure.model.Project`` object to which the hook
-            should be installed
-
-        """
-        repopaths = [
-            os.path.join(pagure_config["REQUESTS_FOLDER"], project.path)
-        ]
-
-        cls.base_remove(repopaths, "pagure-requests")

+ 0 - 1
pagure/hooks/pagure_unsigned_commits.py

@@ -25,7 +25,6 @@ from sqlalchemy.orm import backref
 import pagure.config
 from pagure.hooks import BaseHook, BaseRunner
 from pagure.lib.model import BASE, Project
-from pagure.utils import get_repo_path
 
 
 _config = pagure.config.reload_config()

+ 4 - 4
tests/test_pagure_flask_api_pr_flag.py

@@ -484,10 +484,10 @@ class PagureFlaskApiPRFlagtests(tests.Modeltests):
         request = pagure.lib.search_pull_requests(
             self.session, project_id=1, requestid=1)
         self.assertEqual(len(request.flags), 2)
-        self.assertEqual(request.flags[0].comment, 'Tests passed')
-        self.assertEqual(request.flags[0].percent, 100)
-        self.assertEqual(request.flags[1].comment, 'Tests running again')
-        self.assertEqual(request.flags[1].percent, None)
+        self.assertEqual(request.flags[0].comment, 'Tests running again')
+        self.assertEqual(request.flags[0].percent, None)
+        self.assertEqual(request.flags[1].comment, 'Tests passed')
+        self.assertEqual(request.flags[1].percent, 100)
 
     @patch.dict('pagure.config.config',
                 {

+ 43 - 40
tests/test_pagure_flask_internal.py

@@ -36,6 +36,8 @@ from pagure.lib.repo import PagureRepo
 class PagureFlaskInternaltests(tests.Modeltests):
     """ Tests for flask Internal controller of pagure """
 
+    maxDiff = None
+
     def setUp(self):
         """ Set up the environnment, ran before every tests. """
         super(PagureFlaskInternaltests, self).setUp()
@@ -2382,12 +2384,9 @@ class PagureFlaskInternaltests(tests.Modeltests):
         js_data = json.loads(output.get_data(as_text=True))
         self.assertEqual(
             sorted(js_data.keys()),
-            ['code', 'message']
+            ['code', 'task']
         )
         self.assertEqual(js_data['code'], 'OK')
-        self.assertEqual(
-            js_data['message'],
-            {'branch_w_pr': {}, 'new_branch': {}})
 
     def test_get_pull_request_ready_branch_on_fork(self):
         '''Test the get_pull_request_ready_branch from the internal API on
@@ -2433,18 +2432,19 @@ class PagureFlaskInternaltests(tests.Modeltests):
         js_data = json.loads(output.get_data(as_text=True))
         self.assertEqual(
             sorted(js_data.keys()),
-            ['code', 'message']
+            ['code', 'task']
         )
         self.assertEqual(js_data['code'], 'OK')
-        self.assertListEqual(
-            sorted(js_data['message'].keys()),
-            ['branch_w_pr', 'new_branch'])
-        self.assertEqual(js_data['message']['branch_w_pr'], {})
-        self.assertListEqual(
-            list(js_data['message']['new_branch']), ['feature'])
-        self.assertEqual(js_data['message']['new_branch']['feature']['commits'], 2)
+        output = self.app.get('/pv/task/' + js_data['task'])
+        self.assertEqual(output.status_code, 200)
+        js_data = json.loads(output.get_data(as_text=True))
         self.assertEqual(
-            js_data['message']['new_branch']['feature']['target_branch'], 'master')
+            js_data,
+            {'results': {
+                'branch_w_pr': {},
+                'new_branch': {'feature':
+                    {'commits': 2, 'target_branch': 'master'}}}}
+        )
 
     def test_get_pull_request_ready_branch_on_fork_no_parent_no_pr(self):
         '''Test the get_pull_request_ready_branch from the internal API on
@@ -2561,18 +2561,19 @@ class PagureFlaskInternaltests(tests.Modeltests):
         js_data = json.loads(output.get_data(as_text=True))
         self.assertEqual(
             sorted(js_data.keys()),
-            ['code', 'message']
+            ['code', 'task']
         )
         self.assertEqual(js_data['code'], 'OK')
+        output = self.app.get('/pv/task/' + js_data['task'])
+        self.assertEqual(output.status_code, 200)
+        js_data = json.loads(output.get_data(as_text=True))
         self.assertEqual(
-            sorted(js_data['message'].keys()),
-            ['branch_w_pr', 'new_branch'])
-        self.assertEqual(js_data['message']['branch_w_pr'], {})
-        self.assertListEqual(
-            list(js_data['message']['new_branch']), ['feature'])
-        self.assertEqual(js_data['message']['new_branch']['feature']['commits'], 2)
-        self.assertEqual(
-            js_data['message']['new_branch']['feature']['target_branch'], 'master')
+            js_data,
+            {'results': {
+                'branch_w_pr': {},
+                'new_branch': {'feature':
+                    {'commits': 2, 'target_branch': 'master'}}}}
+        )
 
     def test_get_pull_request_ready_branch_matching_target_off(self):
         '''Test the get_pull_request_ready_branch from the internal API on
@@ -2625,18 +2626,19 @@ class PagureFlaskInternaltests(tests.Modeltests):
         js_data = json.loads(output.get_data(as_text=True))
         self.assertEqual(
             sorted(js_data.keys()),
-            ['code', 'message']
+            ['code', 'task']
         )
         self.assertEqual(js_data['code'], 'OK')
-        self.assertListEqual(
-            sorted(js_data['message'].keys()),
-            ['branch_w_pr', 'new_branch'])
-        self.assertEqual(js_data['message']['branch_w_pr'], {})
-        self.assertListEqual(
-            list(js_data['message']['new_branch']), ['feature'])
-        self.assertEqual(js_data['message']['new_branch']['feature']['commits'], 2)
+        output = self.app.get('/pv/task/' + js_data['task'])
+        self.assertEqual(output.status_code, 200)
+        js_data = json.loads(output.get_data(as_text=True))
         self.assertEqual(
-            js_data['message']['new_branch']['feature']['target_branch'], 'master')
+            js_data,
+            {'results': {
+                'branch_w_pr': {},
+                'new_branch': {'feature':
+                    {'commits': 2, 'target_branch': 'master'}}}}
+        )
 
     @patch.dict('pagure.config.config', {'PR_TARGET_MATCHING_BRANCH': True})
     def test_get_pull_request_ready_branch_matching_target_on(self):
@@ -2690,18 +2692,19 @@ class PagureFlaskInternaltests(tests.Modeltests):
         js_data = json.loads(output.get_data(as_text=True))
         self.assertEqual(
             sorted(js_data.keys()),
-            ['code', 'message']
+            ['code', 'task']
         )
         self.assertEqual(js_data['code'], 'OK')
-        self.assertListEqual(
-            sorted(js_data['message'].keys()),
-            ['branch_w_pr', 'new_branch'])
-        self.assertEqual(js_data['message']['branch_w_pr'], {})
-        self.assertListEqual(
-            list(js_data['message']['new_branch']), ['feature'])
-        self.assertEqual(js_data['message']['new_branch']['feature']['commits'], 1)
+        output = self.app.get('/pv/task/' + js_data['task'])
+        self.assertEqual(output.status_code, 200)
+        js_data = json.loads(output.get_data(as_text=True))
         self.assertEqual(
-            js_data['message']['new_branch']['feature']['target_branch'], 'feature')
+            js_data,
+            {'results': {
+                'branch_w_pr': {},
+                'new_branch': {'feature':
+                    {'commits': 1, 'target_branch': 'feature'}}}}
+        )
 
     def test_task_info_task_running(self):
         """ Test the task_info internal API endpoint when the task isn't

+ 2 - 12
tests/test_pagure_flask_ui_fork.py

@@ -3115,18 +3115,8 @@ index 0000000..2a552bb
             )
             self.assertEqual(output.status_code, 200)
             data = json.loads(output.get_data(as_text=True))
-            self.assertEqual(
-                data,
-                {
-                  "code": "OK",
-                  "message": {
-                    "branch_w_pr": {
-                      "feature": "test/pull-request/1"
-                    },
-                    "new_branch": {}
-                  }
-                }
-            )
+            self.assertEqual(sorted(data.keys()), ['code', 'task'])
+            self.assertEqual(data['code'], 'OK')
 
     @patch('pagure.lib.notify.send_email')
     def test_fork_edit_file(self, send_email):

+ 0 - 10
tests/test_pagure_flask_ui_plugins_pagure_request_hook.py

@@ -147,16 +147,6 @@ class PagureFlaskPluginPagureRequestHooktests(tests.SimplePagureTest):
                 self.path, 'requests', 'test.git', 'hooks',
                 'post-receive.pagure-requests')))
 
-            # Try re-activate hook w/o the git repo
-            data = {
-                'csrf_token': csrf_token,
-                'active': 'y',
-            }
-            shutil.rmtree(os.path.join(self.path, 'repos', 'requests', 'test.git'))
-
-            output = self.app.post('/test/settings/Pagure requests', data=data)
-            self.assertEqual(output.status_code, 404)
-
 
 if __name__ == '__main__':
     unittest.main(verbosity=2)