#244 Use pytest-cov for coverage testing, set minimal coverage percentage to 80%.
Merged 8 months ago by jkaluza. Opened 8 months ago by jkaluza.
jkaluza/odcs generating-timeout  into  master

file modified
+1 -1

@@ -223,7 +223,7 @@ 

      if backend == 'noauth':

          # Do not enable any authentication backend working with frontend

          # authentication module in Apache.

-         log.warn("Authorization is disabled in ODCS configuration.")

+         log.warning("Authorization is disabled in ODCS configuration.")

          return

      if backend == 'kerberos':

          _validate_kerberos_config()

@@ -141,8 +141,8 @@ 

  

          # Be nice and don't fail when directory does not exist.

          if not os.path.exists(toplevel_dir):

-             log.warn("Cannot remove directory %s, it does not exist",

-                      toplevel_dir)

+             log.warning("Cannot remove directory %s, it does not exist",

+                         toplevel_dir)

              return

  

          # If toplevel_dir is a symlink, remove the symlink and

file modified
+1 -1

@@ -99,7 +99,7 @@ 

              # But otherwise get the latest module in this name:stream from MBS

              # and add it to new_modules/module_map.

              for deps in mmd.get_dependencies():

-                 for name, streams in deps.get_requires().items():

+                 for name, streams in deps.peek_requires().items():

                      for stream in streams.get():

                          key = "%s:%s" % (name, stream)

                          if key not in module_map:

file modified
+3 -2

@@ -84,8 +84,9 @@ 

  class ODCSAPI(MethodView):

      def _get_compose_owner(self):

          if conf.auth_backend == "noauth":

-             log.warn("Cannot determine the owner of compose, because "

-                      "'noauth' auth_backend is used.")

+             log.warning(

+                 "Cannot determine the owner of compose, because "

+                 "'noauth' auth_backend is used.")

              return "unknown"

          else:

              return g.user.username

file modified
+10 -9

@@ -20,6 +20,7 @@ 

  #

  # Written by Jan Kaluza <jkaluza@redhat.com>

  

+ import six

  import os

  import shutil

  

@@ -100,7 +101,7 @@ 

              flags=flags)

          db.session.commit()

  

-         with self.assertRaisesRegexp(ModuleLookupError, match):

+         with six.assertRaisesRegex(self, ModuleLookupError, match):

              resolve_compose(c)

  

      @mock_mbs(1)

@@ -145,7 +146,7 @@ 

              flags=flags)

          db.session.commit()

  

-         with self.assertRaisesRegexp(ModuleLookupError, match):

+         with six.assertRaisesRegex(self, ModuleLookupError, match):

              resolve_compose(c)

  

      def test_resolve_compose_module_not_found(self):

@@ -228,7 +229,7 @@ 

          koji_session = MagicMock()

          koji_session.getTag.return_value = None

  

-         with self.assertRaisesRegexp(ValueError, 'Unknown Koji tag foo.'):

+         with six.assertRaisesRegex(self, ValueError, 'Unknown Koji tag foo.'):

              koji_get_inherited_tags(koji_session, "foo")

  

      @patch("odcs.server.backend.koji_get_inherited_tags")

@@ -528,7 +529,7 @@ 

  

          c1 = Compose.query.filter(Compose.id == 1).one()

          self.assertEqual(c1.state, COMPOSE_STATES["failed"])

-         self.assertRegexpMatches(c1.state_reason, r'Error while generating compose: Failed to find all the content_sets.*')

+         six.assertRegex(self, c1.state_reason, r'Error while generating compose: Failed to find all the content_sets.*')

  

      @patch("odcs.server.backend.resolve_compose")

      @patch("odcs.server.backend.generate_pungi_compose")

@@ -550,8 +551,8 @@ 

  

          c1 = Compose.query.filter(Compose.id == 1).one()

          self.assertEqual(c1.state, COMPOSE_STATES["failed"])

-         self.assertRegexpMatches(

-             c1.state_reason,

+         six.assertRegex(

+             self, c1.state_reason,

              r'Error while generating compose: Expected exception\n'

              'Compose failed for unknown reason*')

  

@@ -573,8 +574,8 @@ 

  

          c1 = Compose.query.filter(Compose.id == 1).one()

          self.assertEqual(c1.state, COMPOSE_STATES["failed"])

-         self.assertRegexpMatches(

-             c1.state_reason,

+         six.assertRegex(

+             self, c1.state_reason,

              r'Error while generating compose: Expected exception*')

  

      @patch('odcs.server.backend.tag_changed', return_value=True)

@@ -907,7 +908,7 @@ 

          super(TestValidatePungiCompose, self).tearDown()

  

      def test_missing_packages(self):

-         with self.assertRaisesRegexp(RuntimeError, 'not present.+pkg3'):

+         with six.assertRaisesRegex(self, RuntimeError, 'not present.+pkg3'):

              validate_pungi_compose(self.c)

  

      def test_all_packages_are_included(self):

@@ -18,7 +18,6 @@ 

  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

  # SOFTWARE.

  

- import fedmsg.config

  import mock

  

  from .utils import ModelsBaseTest, ConfigPatcher

@@ -33,8 +32,9 @@ 

  

      def _create_consumer(self):

          hub = mock.MagicMock()

-         hub.config = fedmsg.config.load_config()

+         hub.config = {}

          hub.config['odcsconsumer'] = True

+         hub.config['validate_signatures'] = False

          return ODCSConsumer(hub)

  

      def _compose_state_change_msg(self, id=1, state=None):

file modified
+3 -2

@@ -20,6 +20,7 @@ 

  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

  # SOFTWARE.

  

+ import six

  import unittest

  

  from mock import patch

@@ -38,8 +39,8 @@ 

  

      def test_execute_cmd_timeout_called(self):

          start_time = time.time()

-         with self.assertRaisesRegexp(

-                 RuntimeError, 'Compose has taken more time.*'):

+         with six.assertRaisesRegex(

+                 self, RuntimeError, 'Compose has taken more time.*'):

              execute_cmd(["/usr/bin/sleep", "5"], timeout=1)

          stop_time = time.time()

  

file modified
+5 -4

@@ -20,6 +20,7 @@ 

  #

  # Written by Jan Kaluza <jkaluza@redhat.com>

  

+ import six

  import contextlib

  import json

  

@@ -830,8 +831,8 @@ 

  

                  self.assertEqual(resp.status, '400 BAD REQUEST')

                  self.assertEqual(data['status'], 400)

-                 self.assertRegexpMatches(data['message'],

-                                          r"Compose \(id=%s\) can not be removed, its state need to be in .*." % new_c.id)

+                 six.assertRegex(self, data['message'],

+                                 r"Compose \(id=%s\) can not be removed, its state need to be in .*." % new_c.id)

                  self.assertEqual(data['error'], 'Bad Request')

  

      def test_delete_non_exist_compose(self):

@@ -911,8 +912,8 @@ 

          self.assertEqual(resp.status, '202 ACCEPTED')

          self.assertEqual(resp.status_code, 202)

          self.assertEqual(data['status'], 202)

-         self.assertRegexpMatches(data['message'],

-                                  r"The delete request for compose \(id=%s\) has been accepted and will be processed by backend later." % c3.id)

+         six.assertRegex(self, data['message'],

+                         r"The delete request for compose \(id=%s\) has been accepted and will be processed by backend later." % c3.id)

  

      @patch.object(odcs.server.config.Config, 'max_seconds_to_live', new_callable=PropertyMock)

      @patch.object(odcs.server.config.Config, 'seconds_to_live', new_callable=PropertyMock)

file modified
+1

@@ -1,4 +1,5 @@ 

  pytest

+ pytest-cov

  responses

  tox

  freezegun

file modified
+17 -12

@@ -4,7 +4,7 @@ 

  # and then run "tox" from this directory.

  

  [tox]

- envlist = py27, py3, coverage, flake8, bandit

+ envlist = py27, py3, flake8, bandit

  

  [testenv]

  # using sitepackages is not a good idea, but Koji... :(

@@ -13,21 +13,13 @@ 

  deps = -r{toxinidir}/test-requirements.txt

  commands =

      pip install .[server]

-     py.test {posargs}

+     py.test \

+         -W "ignore:inspect.getargspec:DeprecationWarning" \

+         {posargs}

  setenv =

      PYTHONPATH = {toxinidir}/common:{toxinidir}/server:{toxinidir}/client

      ODCS_DEVELOPER_ENV=1

  

- [testenv:coverage]

- basepython = python3

- deps =

-     {[testenv]deps}

-     coverage

- commands =

-     coverage run --parallel-mode -m pytest

-     coverage combine

-     coverage report --omit=tests/*,.tox/*,/usr/* -m --skip-covered

- 

  [testenv:flake8]

  basepython = python3

  skip_install = true

@@ -41,3 +33,16 @@ 

  commands =

      /bin/bash -c "bandit -r -ll $(find . -mindepth 1 -maxdepth 1 ! -name tests ! -name \.\* -type d -o -name \*.py)"

  ignore_outcome = True

+ 

+ [pytest]

+ addopts = --cov=odcs

+ 

+ [coverage:report]

+ skip_covered = 1

+ show_missing = 1

+ fail_under = 80

+ omit =

+      .tox

+      .env

+      tests/*

+      /usr/*