#492 Mock koji.read_config properly in tests
Merged 4 years ago by gnaponie. Opened 4 years ago by cqi.
cqi/freshmaker mock-koji-read_config  into  master

@@ -66,6 +66,10 @@ 

          super(CancelEventOnFreshmakerManageRequestTest, self).setUp()

          events.BaseEvent.register_parser(FreshmakerManageRequestParser)

  

+         self.koji_read_config_patcher = patch(

+             'koji.read_config', return_value={'server': 'http://localhost/'})

+         self.koji_read_config_patcher.start()

+ 

          self.db_event = models.Event.create(

              db.session, "2017-00000000-0000-0000-0000-000000000003", "RHSA-2018-103",

              events.TestingEvent)
@@ -76,6 +80,9 @@ 

              db.session, self.db_event, "bash", "module", build_id=1238,

              state=ArtifactBuildState.CANCELED.value)

  

+     def tearDown(self):

+         self.koji_read_config_patcher.stop()

+ 

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

      def test_cancel_event_on_freshmaker_manage_request(self, mocked_cancel_build):

          msg = get_fedmsg('freshmaker_manage_eventcancel')

file modified
+10
@@ -281,6 +281,10 @@ 

      def setUp(self):

          super(TestContainerImageObject, self).setUp()

  

+         self.koji_read_config_patcher = patch(

+             'koji.read_config', return_value={'server': 'http://localhost/'})

+         self.koji_read_config_patcher.start()

+ 

          self.patcher = helpers.Patcher(

              'freshmaker.lightblue.')

          self.get_distgit_files = self.patcher.patch("get_distgit_files")
@@ -313,6 +317,7 @@ 

      def tearDown(self):

          super(TestContainerImageObject, self).tearDown()

          self.patcher.unpatch_all()

+         self.koji_read_config_patcher.stop()

  

      def test_create(self):

          image = ContainerImage.create({
@@ -603,6 +608,10 @@ 

          # Clear the ContainerImage Koji cache.

          ContainerImage.KOJI_BUILDS_CACHE = {}

  

+         self.koji_read_config_patcher = patch(

+             'koji.read_config', return_value={'server': 'http://locahost/'})

+         self.koji_read_config_patcher.start()

+ 

          self.patcher = helpers.Patcher(

              'freshmaker.lightblue.')

          self.get_distgit_files = self.patcher.patch("get_distgit_files")
@@ -844,6 +853,7 @@ 

      def tearDown(self):

          super(TestQueryEntityFromLightBlue, self).tearDown()

          self.patcher.unpatch_all()

+         self.koji_read_config_patcher.stop()

  

      @patch('freshmaker.lightblue.requests.post')

      def test_find_container_images(self, post):

file modified
+8
@@ -39,6 +39,11 @@ 

  

      def setUp(self):

          super(TestCheckUnfinishedKojiTasks, self).setUp()

+ 

+         self.koji_read_config_patcher = patch(

+             'koji.read_config', return_value={'server': 'http://localhost/'})

+         self.koji_read_config_patcher.start()

+ 

          db_event = Event.get_or_create(

              db.session, "msg1", "current_event", ErrataAdvisoryRPMsSignedEvent)

          db_event.state = EventState.BUILDING
@@ -48,6 +53,9 @@ 

          self.build.build_id = 10

          db.session.commit()

  

+     def tearDown(self):

+         self.koji_read_config_patcher.stop()

+ 

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

      @patch("freshmaker.consumer.get_global_consumer")

      def test_koji_task_failed(self, global_consumer, get_task_info):

These tests do not require to read a real koji.conf from filesystem.

Signed-off-by: Chenxiong Qi qcxhome@gmail.com

Commit eefde6d fixes this pull-request

Pull-Request has been merged by gnaponie

4 years ago

Pull-Request has been merged by gnaponie

4 years ago