#116 Use pytest
Merged 4 years ago by pingou. Opened 4 years ago by zlopez.
zlopez/pagure-dist-git pytest  into  master

file modified
+1 -1
@@ -75,7 +75,7 @@ 

  The tests here require the *test suite* of pagure itself to work.  You have to

  modify your PYTHONPATH to find them. Run with::

  

-     $ PYTHONPATH=.:/path/to/pagure/checkout nosetests pagure_distgit_tests/

+     $ PYTHONPATH=.:/path/to/pagure/checkout pytest pagure_distgit_tests/

  

  You can use our requirements-testing.txt to install testing dependencies with pip:

      $ pip install -r /path/to/pagure/checkout/requirements.txt

pagure_distgit_tests/test_bugzilla_overrides.py pagure_distgit_tests/bugzilla_overrides_tests.py
file renamed
file was moved with no change to the file
pagure_distgit_tests/test_dist_git_auth.py pagure_distgit_tests/dist_git_auth_tests.py
file renamed
+57 -67
@@ -17,58 +17,6 @@ 

  import dist_git_auth

  

  

- def patch_pdc(values):

-     """ Decorator to patch the PDC calls to return values for this test.

- 

-     Args:

-         values (dict): A dictionary where the keys are project fullnames

-             (i.e. namespace/name), and the values are dicts with key branch

-             names, and values their supported status.

-             Note that as namespace, the PDC "type" is used, which lacks the "s"

-             for rpms and modules.

-             e.g.: {'rpm/test': {'f28': True, 'f27': False}}

-     """

- 

-     def pdc_get_paged(_, global_component, type, name, fields):

-         """ Function that emulates the pdc.get_paged call

- 

-         Args as provided by dist_git_auth's calls to it.

- 

-         Args:

-             _ (anything): PDCClient internal

-             global_component (string): package name

-             type (string): The PDC "type": "rpm", "module", ...

-             name (string): The branch name

-             fields (list): Always ["active"]

-         """

-         fullname = "%s/%s" % (type, global_component)

-         if fullname not in values:

-             return []

-         val = values[fullname]

-         if name not in val:

-             return []

-         val = val[name]

-         if val in (True, False):

-             return [{"active": val}]

-         # This case is used to emulate "weird" results

-         return val

- 

-     def decorator(func):

-         def test_wrapper(*args, **kwargs):

-             if dist_git_auth.PDCClient:

-                 with patch.object(dist_git_auth.PDCClient, "__getitem__"):

-                     with patch.object(

-                         dist_git_auth.PDCClient,

-                         "get_paged",

-                         side_effect=pdc_get_paged,

-                     ):

-                         return func(*args, **kwargs)

- 

-         return test_wrapper

- 

-     return decorator

- 

- 

  class DistGitAuthTests(tests.Modeltests):

      """ Test DistGitAuth ACLs with Fedora config. """

  
@@ -149,7 +97,11 @@ 

  

  

  class DistGitAuthTestsGeneric(DistGitAuthTests):

-     dga_config = {}

+     dga_config = {

+         "BLACKLIST_RES": [],

+         "RCM_BRANCHES": [],

+         "BYPASS_PR_ONLY_GROUPS": ["relenggroup"],

+     }

  

      def test_unused_repotype(self):

          self.assertFalse(
@@ -493,8 +445,12 @@ 

  

          self.expect_info_msg("RCM push")

  

-     @patch_pdc({"rpm/test": {"f26": False, "f27": True}})

-     def test_protected_unsupported_branch(self):

+     @patch("dist_git_auth.requests")

+     def test_protected_unsupported_branch(self, mock_requests):

+         res = Mock()

+         res.ok = True

+         res.json.return_value = {"results": [{"active": False}]}

+         mock_requests.get.return_value = res

          project = self.create_namespaced_project("rpms", "test")

  

          self.assertFalse(
@@ -514,9 +470,13 @@ 

  

          self.expect_info_msg("Branch refs/heads/f26 is unsupported")

  

-     @patch_pdc({"rpm/test": {"f26": False, "f27": True}})

-     def test_protected_supported_branch_committer(self):

+     @patch("dist_git_auth.requests")

+     def test_protected_supported_branch_committer(self, mock_requests):

          project = self.create_namespaced_project("rpms", "test")

+         res = Mock()

+         res.ok = True

+         res.json.return_value = {"results": [{"active": True}]}

+         mock_requests.get.return_value = res

  

          self.assertTrue(

              self.dga.check_acl(
@@ -535,9 +495,13 @@ 

  

          self.expect_info_msg("Branch refs/heads/f27 is supported")

  

-     @patch_pdc({"rpm/test": {"f26": False, "f27": True}})

-     def test_protected_supported_branch_non_committer(self):

+     @patch("dist_git_auth.requests")

+     def test_protected_supported_branch_non_committer(self, mock_requests):

          project = self.create_namespaced_project("rpms", "test")

+         res = Mock()

+         res.ok = True

+         res.json.return_value = {"results": [{"active": True}]}

+         mock_requests.get.return_value = res

  

          self.assertFalse(

              self.dga.check_acl(
@@ -556,9 +520,13 @@ 

  

          self.expect_info_msg("Branch refs/heads/f27 is supported")

  

-     @patch_pdc({"rpm/test": {"f26": False, "f27": True}})

-     def test_protected_unspecified_branch_blacklisted(self):

+     @patch("dist_git_auth.requests")

+     def test_protected_unspecified_branch_blacklisted(self, mock_requests):

          project = self.create_namespaced_project("rpms", "test")

+         res = Mock()

+         res.ok = True

+         res.json.return_value = {"results": []}

+         mock_requests.get.return_value = res

  

          self.assertFalse(

              self.dga.check_acl(
@@ -577,9 +545,15 @@ 

  

          self.expect_info_msg("Unspecified ref refs/heads/f28 is blocked")

  

-     @patch_pdc({"rpm/test": {"f26": False, "f27": True}})

-     def test_protected_unspecified_branch_normal_committer(self):

+     @patch("dist_git_auth.requests")

+     def test_protected_unspecified_branch_normal_committer(

+         self, mock_requests

+     ):

          project = self.create_namespaced_project("rpms", "test")

+         res = Mock()

+         res.ok = True

+         res.json.return_value = {"results": []}

+         mock_requests.get.return_value = res

  

          self.assertTrue(

              self.dga.check_acl(
@@ -598,9 +572,15 @@ 

  

          self.expect_info_msg("Unspecified branch push")

  

-     @patch_pdc({"rpm/test": {"f26": False, "f27": True}})

-     def test_protected_unspecified_branch_normal_non_committer(self):

+     @patch("dist_git_auth.requests")

+     def test_protected_unspecified_branch_normal_non_committer(

+         self, mock_requests

+     ):

          project = self.create_namespaced_project("rpms", "test")

+         res = Mock()

+         res.ok = True

+         res.json.return_value = {"results": []}

+         mock_requests.get.return_value = res

  

          self.assertFalse(

              self.dga.check_acl(
@@ -735,8 +715,13 @@ 

  

          self.expect_info_msg("SIG push")

  

-     def test_protected_sig_no_sig_member(self):

+     @patch("dist_git_auth.requests")

+     def test_protected_sig_no_sig_member(self, mock_requests):

          project = self.create_namespaced_project("rpms", "test")

+         res = Mock()

+         res.ok = True

+         res.json.return_value = {"results": []}

+         mock_requests.get.return_value = res

  

          self.assertFalse(

              self.dga.check_acl(
@@ -755,8 +740,13 @@ 

  

          self.expect_info_msg("Access to namespace rpms is restricted")

  

-     def test_protected_sig_sig_member_no_sig_branch(self):

+     @patch("dist_git_auth.requests")

+     def test_protected_sig_sig_member_no_sig_branch(self, mock_requests):

          project = self.create_namespaced_project("rpms", "test")

+         res = Mock()

+         res.ok = True

+         res.json.return_value = {"results": []}

+         mock_requests.get.return_value = res

  

          self.assertFalse(

              self.dga.check_acl(

pagure_distgit_tests/test_style.py pagure_distgit_tests/tests_style.py
file renamed
file was moved with no change to the file
file modified
+1 -1
@@ -1,4 +1,4 @@ 

  flake8

  flake8-import-order

- nose

  pdc_client

+ pytest