#330 Fix the test warnings, require 80% coverage, ignore third-party modules warnings.
Merged 8 months ago by jkaluza. Opened 8 months ago by jkaluza.
jkaluza/freshmaker fix-log-warn  into  master

@@ -150,7 +150,7 @@ 

          """

          return self._log(log.info, msg, *args, **kwargs)

  

-     def log_warning(self, msg, *args, **kwargs):

+     def log_warn(self, msg, *args, **kwargs):

          """

          Wraps log.warning, prefixes the message with a context of this handler.

          """

file modified
+12 -1

@@ -25,10 +25,12 @@ 

  import uuid

  import unittest

  import koji

+ from six.moves import queue

  

- from mock import patch

+ from mock import patch, MagicMock

  from functools import wraps

  

+ import freshmaker.consumer

  from freshmaker import events

  from freshmaker import db

  from freshmaker.models import User

@@ -94,6 +96,15 @@ 

          event = events.BaseEvent.from_fedmsg(message['body']['topic'], message['body'])

          return event

  

+     def create_consumer(self):

+         hub = MagicMock()

+         hub.config = {}

+         hub.config['freshmakerconsumer'] = True

+         hub.config['validate_signatures'] = False

+         consumer =  freshmaker.consumer.FreshmakerConsumer(hub)

+         consumer.incoming = queue.Queue()

+         return consumer

+ 

  

  class ModelsTestCase(FreshmakerTestCase):

  

file modified
+6 -12

@@ -34,12 +34,6 @@ 

  

  class ConsumerBaseTest(helpers.ModelsTestCase):

  

-     def _create_consumer(self):

-         hub = mock.MagicMock()

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

-         hub.config['freshmakerconsumer'] = True

-         return freshmaker.consumer.FreshmakerConsumer(hub)

- 

      def _module_state_change_msg(self, state=None):

          msg = {'body': {

              "msg_id": "2017-7afcb214-cf82-4130-92d2-22f45cf59cf7",

@@ -65,7 +59,7 @@ 

          to proper handler and is able to get the further work from

          the handler.

          """

-         consumer = self._create_consumer()

+         consumer = self.create_consumer()

          global_consumer.return_value = consumer

          handle.return_value = [freshmaker.events.TestingEvent("ModuleBuilt handled")]

  

@@ -80,7 +74,7 @@ 

          """

          Tests consumer will try to subscribe specified topics.

          """

-         consumer = self._create_consumer()

+         consumer = self.create_consumer()

          global_consumer.return_value = consumer

          topics = freshmaker.events.BaseEvent.get_parsed_topics()

          callback = consumer._consume_json if consumer.jsonify else consumer.consume

@@ -96,7 +90,7 @@ 

          Tests that Consumer.consume marks the DB Event as failed in case there

          is an error in a handler.

          """

-         consumer = self._create_consumer()

+         consumer = self.create_consumer()

          global_consumer.return_value = consumer

  

          @fail_event_on_handler_exception

@@ -124,7 +118,7 @@ 

                  new=['freshmaker.parsers.brew.sign_rpm:BrewSignRpmParser'])

      @mock.patch("freshmaker.consumer.get_global_consumer")

      def test_get_internal_event_parser(self, get_global_consumer):

-         consumer = self._create_consumer()

+         consumer = self.create_consumer()

          get_global_consumer.return_value = consumer

  

          msg = {

@@ -147,7 +141,7 @@ 

      @mock.patch("freshmaker.consumer.get_global_consumer")

      def test_get_internal_event_parser_no_msg_id_fallback(

              self, get_global_consumer):

-         consumer = self._create_consumer()

+         consumer = self.create_consumer()

          get_global_consumer.return_value = consumer

  

          msg = {

@@ -172,7 +166,7 @@ 

      @mock.patch("freshmaker.consumer.get_global_consumer")

      def test_get_internal_event_parser_no_msg(

              self, get_global_consumer):

-         consumer = self._create_consumer()

+         consumer = self.create_consumer()

          get_global_consumer.return_value = consumer

  

          msg = {

@@ -36,11 +36,6 @@ 

  

  class BaseTestCase(helpers.ModelsTestCase):

  

-     def create_consumer(self):

-         hub = MagicMock()

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

-         return FreshmakerConsumer(hub)

- 

      @patch("requests.request")

      @patch('freshmaker.consumer.get_global_consumer')

      def consume_fedmsg(self, msg, global_consumer, request):

file modified
+1 -10

@@ -67,15 +67,6 @@ 

      def tearDown(self):

          super(ConsumerTest, self). tearDown()

  

-     def _create_consumer(self):

-         hub = mock.MagicMock()

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

-         hub.config['freshmakerconsumer'] = True

-         consumer = freshmaker.consumer.FreshmakerConsumer(hub)

-         # Cleanup the queue.

-         consumer.incoming = queue.Queue()

-         return consumer

- 

      def _module_state_change_msg(self, state=None):

          msg = {'body': {

              "msg_id": "2017-7afcb214-cf82-4130-92d2-22f45cf59cf7",

@@ -106,7 +97,7 @@ 

          to proper handler and is able to get the further work from

          the handler.

          """

-         consumer = self._create_consumer()

+         consumer = self.create_consumer()

          global_consumer.return_value = consumer

          handle.return_value = [freshmaker.events.TestingEvent("ModuleBuilt handled")]

  

file modified
+1 -9

@@ -302,17 +302,9 @@ 

              '', 'build', builds=['apache-commons-lang-2.6-15.el7', 'avalon-logkit-2.1-14.el7'],

              flags=['no_deps'], packages=[u'apache-commons-lang', u'avalon-logkit'], sigkeys=[])

  

-     def _create_consumer(self):

-         hub = MagicMock()

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

-         hub.config['freshmakerconsumer'] = True

-         consumer = FreshmakerConsumer(hub)

-         consumer.incoming = queue.Queue()

-         return consumer

- 

      @patch("freshmaker.consumer.get_global_consumer")

      def test_prepare_odcs_compose_with_image_rpms_dry_run(self, global_consumer):

-         consumer = self._create_consumer()

+         consumer = self.create_consumer()

          global_consumer.return_value = consumer

          image = self._get_fake_container_image()

  

file modified
+4 -12

@@ -50,18 +50,10 @@ 

          self.build.build_id = 10

          db.session.commit()

  

-     def _create_consumer(self):

-         hub = MagicMock()

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

-         hub.config['freshmakerconsumer'] = True

-         consumer = freshmaker.consumer.FreshmakerConsumer(hub)

-         consumer.incoming = queue.Queue()

-         return consumer

- 

      @patch('freshmaker.kojiservice.KojiService.get_task_info')

      @patch("freshmaker.consumer.get_global_consumer")

      def test_koji_task_failed(self, global_consumer, get_task_info):

-         consumer = self._create_consumer()

+         consumer = self.create_consumer()

          global_consumer.return_value = consumer

  

          get_task_info.return_value = {'state': koji.TASK_STATES['FAILED']}

@@ -76,7 +68,7 @@ 

      @patch('freshmaker.kojiservice.KojiService.get_task_info')

      @patch("freshmaker.consumer.get_global_consumer")

      def test_koji_task_closed(self, global_consumer, get_task_info):

-         consumer = self._create_consumer()

+         consumer = self.create_consumer()

          global_consumer.return_value = consumer

  

          get_task_info.return_value = {'state': koji.TASK_STATES['CLOSED']}

@@ -92,7 +84,7 @@ 

      @patch("freshmaker.consumer.get_global_consumer")

      def test_koji_task_dry_run(self, global_consumer, get_task_info):

          self.build.build_id = -10

-         consumer = self._create_consumer()

+         consumer = self.create_consumer()

          global_consumer.return_value = consumer

  

          get_task_info.return_value = {'state': koji.TASK_STATES['CLOSED']}

@@ -106,7 +98,7 @@ 

      @patch("freshmaker.consumer.get_global_consumer")

      def test_koji_task_open(self, global_consumer, get_task_info):

          self.build.build_id = -10

-         consumer = self._create_consumer()

+         consumer = self.create_consumer()

          global_consumer.return_value = consumer

  

          get_task_info.return_value = {'state': koji.TASK_STATES['OPEN']}

file modified
+7 -1

@@ -10,7 +10,12 @@ 

  skip_install = True

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

  commands =

-     py.test {posargs}

+     py.test \

+         -W "ignore::UserWarning:flask.sessions" \

+         -W "ignore:You do not have a working installation:UserWarning" \

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

+         -W "ignore:This method will be removed in future versions.  Use 'parser.read_file()':DeprecationWarning" \

+         {posargs}

  

  [testenv:flake8]

  basepython = python3

@@ -36,6 +41,7 @@ 

  [coverage:report]

  skip_covered = 1

  show_missing = 1

+ fail_under = 80

  omit =

       .tox

       .env