#411 tests: replace Dingus with Mock
Closed 6 years ago by kparal. Opened 6 years ago by kparal.

file modified
-2
@@ -59,11 +59,9 @@ 

  BuildRequires:  sed

  

  %if 0%{?fedora} <= 27

- BuildRequires:  python-dingus >= 0.3.4

  BuildRequires:  python-progressbar >= 2.3

  BuildRequires:  PyYAML >= 3.11

  %else

- BuildRequires:  python2-dingus >= 0.3.4

  BuildRequires:  python2-progressbar >= 2.3

  BuildRequires:  python2-pyyaml >= 3.11

  %endif

file modified
-1
@@ -25,7 +25,6 @@ 

  testcloud >= 0.1.15

  

  # Test suite requirements

- dingus >= 0.3.4

  mock >= 2.0.0

  pytest >= 2.7.3

  pytest-cov >= 2.2.1

@@ -5,7 +5,7 @@ 

  

  '''Functional tests for libtaskotron/koji_utils.py'''

  

- from dingus import Dingus

+ import mock

  import os

  

  from libtaskotron.ext.fedora import koji_utils
@@ -35,7 +35,7 @@ 

          is missing an rpm """

  

          rpmdir = tmpdir.mkdir("rpmdownload")

-         stub_koji = Dingus(getBuild__returns = self.ref_build)

+         stub_koji = mock.MagicMock(**{'getBuild.return_value': self.ref_build})

          test_koji = koji_utils.KojiClient(stub_koji)

  

          test_koji.get_nvr_rpms(self.ref_nvr, str(rpmdir), arches=[self.ref_arch])
@@ -45,7 +45,7 @@ 

  

      def test_get_nvr_rpms_dest_exists(self, tmpdir, monkeypatch):

          '''Destination dir must be created even if no files are downloaded'''

-         stub_koji = Dingus()

+         stub_koji = mock.Mock()

          test_koji = koji_utils.KojiClient(stub_koji)

  

          monkeypatch.setattr(test_koji, 'nvr_to_urls', lambda *args, **kwargs: [])
@@ -60,9 +60,9 @@ 

  

      def test_get_tagged_rpms_dest_exists(self, tmpdir, monkeypatch):

          '''Destination dir must be created even if no files are downloaded'''

-         stub_koji = Dingus(listTagged__returns=[])

+         stub_koji = mock.Mock(**{'listTagged.return_value': []})

          test_koji = koji_utils.KojiClient(stub_koji)

-         stub_get_nvr_rpms = Dingus()

+         stub_get_nvr_rpms = mock.Mock()

  

          monkeypatch.setattr(test_koji, 'get_nvr_rpms', stub_get_nvr_rpms)

  
@@ -70,4 +70,3 @@ 

          test_koji.get_tagged_rpms('some tag', dest=rpmdir)

  

          assert os.path.isdir(rpmdir)

- 

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

  # See the LICENSE file for more details on Licensing

  

  import pytest

- from dingus import Dingus

+ import mock

  import configparser

  

  from libtaskotron.directives import resultsdb_directive
@@ -65,10 +65,11 @@ 

                              u'start_time': None,

                              u'status': u'SCHEDULED'}

  

-         self.stub_rdb = Dingus('resultsdb', get_testcase__returns={},

-                                create_job__returns=self.ref_jobdata,

-                                create_result__returns=self.ref_resultdata,

-                                )

+         self.stub_rdb = mock.Mock(**{

+             'get_testcase.return_value': {},

+             'create_job.return_value': self.ref_jobdata,

+             'create_result.return_value': self.ref_resultdata,

+             })

          self.test_rdb = resultsdb_directive.ResultsdbDirective(self.stub_rdb)

  

          # while it appears useless, this actually sets config in several tests
@@ -94,15 +95,10 @@ 

          # we expect rdb to be called 2 times:

          # check for testcase, and report result

  

-         assert len(self.stub_rdb.calls()) == 2

+         assert len(self.stub_rdb.method_calls) == 2

  

-         # Select the first call of "create_result" method.

-         # This could be written as self.stub_rdb.calls()[0] at the moment, but

-         #   this is more future-proof, and accidental addition of resultsdb

-         #   calls is handled by the previous assert.

-         call = [call for call in self.stub_rdb.calls() if call[0] == 'create_result'][0]

-         # Select the keyword arguments of that call

-         call_data = call[2]

+         # Select the keyword arguments of create_results call

+         call_data = self.stub_rdb.create_result.call_args[1]

  

          # the log url depends on the arg_data, so construct it here

          ref_log_url = '%s/%s' % (self.conf.artifacts_baseurl, self.ref_arg_data['uuid'])
@@ -131,4 +127,4 @@ 

          with pytest.raises(exc.TaskotronDirectiveError):

              self.test_rdb.process(self.ref_input, self.ref_arg_data)

  

-         assert len(self.stub_rdb.calls()) == 0

+         assert len(self.stub_rdb.method_calls) == 0

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

  import pytest

  import mock

  import StringIO

- from dingus import Dingus

+ import mock

  

  from libtaskotron.directives import yumrepoinfo_directive

  from libtaskotron.exceptions import TaskotronDirectiveError
@@ -83,7 +83,7 @@ 

          repoinfo = yumrepoinfo.YumRepoInfo(filelist=[], arch='x86_64')

          repoinfo.parser.readfp(StringIO.StringIO(TEST_CONF))

  

-         stub_getrepoinfo = Dingus(return_value=repoinfo)

+         stub_getrepoinfo = mock.MagicMock(return_value=repoinfo)

          monkeypatch.setattr(yumrepoinfo, 'get_yumrepoinfo', stub_getrepoinfo)

  

          # don't set the repoinfo object, we've stubbed out the code that would
@@ -94,7 +94,7 @@ 

          directive.process(ref_input, None)

  

          # check the first arg of the first call to the stub object

-         assert stub_getrepoinfo.calls()[0][1][0] == ref_arch

+         assert stub_getrepoinfo.call_args_list[0][0][0] == ref_arch

  

      def test_only_meta_arches(self):

          directive = yumrepoinfo_directive.YumrepoinfoDirective(filelist=[self.temp_conf.strpath])

file modified
+37 -47
@@ -6,7 +6,7 @@ 

  '''Unit tests for libtaskotron/directives/bodhi_directive.py'''

  

  import pytest

- from dingus import Dingus

+ import mock

  

  from libtaskotron.directives import bodhi_directive

  from libtaskotron.exceptions import TaskotronDirectiveError
@@ -36,21 +36,23 @@ 

          self.ref_rpmfile = '%s/%s.rpm' % (self.ref_targetdir, self.ref_nvr1)

  

          self.helper = bodhi_directive.BodhiDirective()

+         self.stub_bodhi = mock.Mock(

+             **{'get_update.return_value': self.ref_update})

+         self.stub_koji = mock.Mock(

+             **{'get_nvr_rpms.return_value': [self.ref_rpmfile]})

  

  

      def test_action_download_existing_update(self):

          '''Test download of existing update'''

-         stub_bodhi = Dingus(get_update__returns=self.ref_update)

-         stub_koji = Dingus(get_nvr_rpms__returns=[self.ref_rpmfile])

- 

-         test_bodhi = bodhi_directive.BodhiDirective(stub_bodhi, stub_koji)

+         test_bodhi = bodhi_directive.BodhiDirective(self.stub_bodhi,

+             self.stub_koji)

  

          output_data = test_bodhi.process(self.ref_input, None)

  

          ref_output_data = {'downloaded_rpms': [self.ref_rpmfile,

                                                 self.ref_rpmfile]}

-         getrpms_calls = stub_koji.calls()

-         requested_nvrs = map(lambda x: x[1][0], getrpms_calls)

+         getrpms_calls = self.stub_koji.get_nvr_rpms.call_args_list

+         requested_nvrs = [call[0][0] for call in getrpms_calls]

  

          # checks whether get_nvr_rpms was called for every update

          # with correct nvrs
@@ -63,19 +65,17 @@ 

          '''Test download when all arches are demanded'''

          self.ref_input['arch'] = 'all'

  

-         stub_bodhi = Dingus(get_update__returns=self.ref_update)

-         stub_koji = Dingus(get_nvr_rpms__returns=[self.ref_rpmfile])

- 

-         test_bodhi = bodhi_directive.BodhiDirective(stub_bodhi, stub_koji)

+         test_bodhi = bodhi_directive.BodhiDirective(self.stub_bodhi,

+             self.stub_koji)

  

          test_bodhi.process(self.ref_input, None)

  

          ref_arches = set(config.get_config().supported_arches + ['noarch'])

-         getrpms_calls = stub_koji.calls()

-         req_arches = map(lambda x: x[1][2], getrpms_calls)

+         getrpms_calls = self.stub_koji.get_nvr_rpms.call_args_list

+         req_arches = [call[0][2] for call in getrpms_calls]

  

          # checks whether all get_nvr_rpms calls demanded all arches

-         assert all(map(lambda x: set(x) == ref_arches, req_arches))

+         assert all([set(arches) == ref_arches for arches in req_arches])

  

      def test_action_download_source(self):

          '''Test download of source packages'''
@@ -83,73 +83,64 @@ 

          self.ref_input['arch'] = []

          self.ref_input['src'] = True

  

-         stub_bodhi = Dingus(get_update__returns=self.ref_update)

-         stub_koji = Dingus(get_nvr_rpms__returns=[self.ref_rpmfile])

- 

-         test_bodhi = bodhi_directive.BodhiDirective(stub_bodhi, stub_koji)

+         test_bodhi = bodhi_directive.BodhiDirective(self.stub_bodhi,

+             self.stub_koji)

  

          test_bodhi.process(self.ref_input, None)

  

-         getrpm_calls = stub_koji.calls()

+         getrpms_calls = self.stub_koji.get_nvr_rpms.call_args_list

  

          # checks whether all get_nvr_rpms calls demanded only source pkgs

-         assert all(map(lambda x: x[1][2] == [], getrpm_calls))

-         assert all(map(lambda x: x[2]['src'], getrpm_calls))

+         assert all([call[0][2] == [] for call in getrpms_calls])

+         assert all([call[1]['src'] for call in getrpms_calls])

  

      def test_action_download_multiple_arch(self):

          '''Test download of multiple arches packages'''

          self.ref_arch = ['x86_64', 'noarch']

          self.ref_input['arch'] = self.ref_arch

  

-         stub_bodhi = Dingus(get_update__returns=self.ref_update)

-         stub_koji = Dingus(get_nvr_rpms__returns=[self.ref_rpmfile])

- 

-         test_bodhi = bodhi_directive.BodhiDirective(stub_bodhi, stub_koji)

+         test_bodhi = bodhi_directive.BodhiDirective(self.stub_bodhi,

+             self.stub_koji)

  

          test_bodhi.process(self.ref_input, None)

  

-         getrpms_calls = stub_koji.calls()

-         req_arches = map(lambda x: x[1][2], getrpms_calls)

+         getrpms_calls = self.stub_koji.get_nvr_rpms.call_args_list

+         req_arches = [call[0][2] for call in getrpms_calls]

  

-         # checks whether all get_nvr_rpms calls demanded only source pkgs

-         assert all(map(lambda x: x == self.ref_arch, req_arches))

+         assert all([arches == self.ref_arch for arches in req_arches])

  

      def test_action_download_added_noarch(self):

          '''Test whether noarch is automaticaly added'''

          self.ref_input['arch'] = 'i386'

  

-         stub_bodhi = Dingus(get_update__returns=self.ref_update)

-         stub_koji = Dingus(get_nvr_rpms__returns=[self.ref_rpmfile])

- 

-         test_bodhi = bodhi_directive.BodhiDirective(stub_bodhi, stub_koji)

+         test_bodhi = bodhi_directive.BodhiDirective(self.stub_bodhi,

+             self.stub_koji)

  

          test_bodhi.process(self.ref_input, None)

  

-         getrpms_calls = stub_koji.calls()

-         req_arches = map(lambda x: x[1][2], getrpms_calls)

+         getrpms_calls = self.stub_koji.get_nvr_rpms.call_args_list

+         req_arches = [call[0][2] for call in getrpms_calls]

  

          # checks whether noarch is demanded in all get_nvr_rpms calls

-         assert all(map(lambda x: 'noarch' in x, req_arches))

- 

+         assert all(['noarch' in arches for arches in req_arches])

  

      def test_action_download_nonexisting_update(self):

          '''Test whether exception is raised when no update is found'''

-         stub_bodhi = Dingus(get_update__returns=None)

-         stub_koji = Dingus(get_nvr_rpms__returns="It shouldn't go this far")

+         stub_bodhi = mock.Mock(**{'get_update.return_value': None})

+         stub_koji = mock.Mock(

+             **{'get_nvr_rpms.return_value': "It shouldn't go this far"})

  

          test_bodhi = bodhi_directive.BodhiDirective(stub_bodhi, stub_koji)

  

-         # No update is found, b. directive should raise an Exception

+         # No update is found, bodhi directive should raise an Exception

          with pytest.raises(TaskotronDirectiveError):

              test_bodhi.process(self.ref_input, None)

  

- 

      def test_invalid_action(self):

          '''Test response on non-existing action'''

          self.ref_input['action'] = 'foo'

- 

-         stub_bodhi = Dingus()

-         stub_koji = Dingus()

+         stub_bodhi = mock.Mock()

+         stub_koji = mock.Mock()

  

          test_bodhi = bodhi_directive.BodhiDirective(stub_bodhi, stub_koji)

  
@@ -159,9 +150,8 @@ 

  

      def test_action_download_insufficient_params(self):

          '''Test response on unsufficient input for download action'''

-         stub_bodhi = Dingus()

-         stub_koji = Dingus()

- 

+         stub_bodhi = mock.Mock()

+         stub_koji = mock.Mock()

          test_bodhi = bodhi_directive.BodhiDirective(stub_bodhi, stub_koji)

  

          for missing_arg in ['action', 'arch', 'update_id', 'target_dir']:

file modified
+6 -11
@@ -6,7 +6,7 @@ 

  '''Unit tests for libtaskotron/bodhi_utils.py'''

  

  import pytest

- from dingus import Dingus

+ import mock

  from munch import Munch

  

  import fedora.client.bodhi
@@ -52,7 +52,7 @@ 

      def test_query_existing_update(self):

          '''Test query for existing update'''

          ref_query_answer = {'updates': [self.ref_update]}

-         stub_bodhi = Dingus(query__returns=ref_query_answer)

+         stub_bodhi = mock.Mock(**{'query.return_value': ref_query_answer})

          bodhi = bodhi_utils.BodhiUtils(client=stub_bodhi)

          update = bodhi.get_update(self.ref_update_id)

  
@@ -61,7 +61,7 @@ 

      def test_query_non_existing_update(self, monkeypatch):

          '''Test query for non-existing update'''

          ref_query_answer = {'updates': []}

-         stub_bodhi = Dingus(query__returns=ref_query_answer)

+         stub_bodhi = mock.Mock(**{'query.return_value': ref_query_answer})

          bodhi = bodhi_utils.BodhiUtils(client=stub_bodhi)

          update = bodhi.get_update(self.ref_update_id)

  
@@ -88,8 +88,6 @@ 

  

      def mock_query(self, builds):

          '''Mock bodhi.client.query()'''

-         # this will allow us to track calls

-         self.query_dingus.mock_query(builds)

          builds = builds.split()

          updates = []

          for build in builds:
@@ -101,12 +99,9 @@ 

      @pytest.fixture

      def setup(self, monkeypatch):

          '''Run this before every test invocation'''

-         self.client = Dingus()

+         self.client = mock.Mock()

          self.bodhi = bodhi_utils.BodhiUtils(self.client)

-         # replace send_request() with a fake function

-         self.client.query = self.mock_query

-         # this will allow us to track calls

-         self.query_dingus = Dingus()

+         self.client.query = mock.Mock(side_effect=self.mock_query)

  

      def test_basic(self):

          '''One update per build, mixed results'''
@@ -217,7 +212,7 @@ 

                                                       'multi2-a-1.0-1.fc20',

                                                       'foo-fail-1.2-3.fc20'])

  

-         calls = self.query_dingus.calls()

+         calls = self.client.query.call_args_list

          # 3 calls, before one of multi1 packages should be skipped

          assert len(calls) == 3

  

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

- from dingus import Dingus

+ # -*- coding: utf-8 -*-

+ # Copyright 2009-2018, Red Hat, Inc.

+ # License: GPL-2.0+ <http://spdx.org/licenses/GPL-2.0+>

+ # See the LICENSE file for more details on Licensing

  

  from libtaskotron import buildbot_utils

  

@@ -5,7 +5,7 @@ 

  

  import os.path

  import pytest

- from dingus import Dingus

+ import mock

  import mock

  

  from libtaskotron import file_utils
@@ -32,7 +32,7 @@ 

                            'path': self.ref_path,

                            'target_dir': '/var/tmp/foo'}

  

-         self.mock_download = Dingus()

+         self.mock_download = mock.Mock()

          monkeypatch.setattr(file_utils, 'download', self.mock_download)

  

      def _get_url(self, path):
@@ -46,10 +46,10 @@ 

      def test_download(self):

          self.helper.process(self.ref_input, None)

  

-         download_calls = self.mock_download.calls

+         download_calls = self.mock_download.call_args_list

          assert len(download_calls) == 1

-         assert download_calls[0][1][0] == self._get_url(self.ref_path[0])

-         assert download_calls[0][1][2] == os.path.join(self.ref_input['target_dir'],

+         assert download_calls[0][0][0] == self._get_url(self.ref_path[0])

+         assert download_calls[0][0][2] == os.path.join(self.ref_input['target_dir'],

                                                         self.ref_path[0])

  

      def test_localpath(self):
@@ -57,10 +57,10 @@ 

  

          self.helper.process(self.ref_input, None)

  

-         download_calls = self.mock_download.calls

+         download_calls = self.mock_download.call_args_list

          assert len(download_calls) == 1

-         assert download_calls[0][1][0] == self._get_url(self.ref_path[0])

-         assert download_calls[0][1][2] == os.path.join(self.ref_input['target_dir'],

+         assert download_calls[0][0][0] == self._get_url(self.ref_path[0])

+         assert download_calls[0][0][2] == os.path.join(self.ref_input['target_dir'],

                                                         self.ref_localpath[0])

  

      def test_multiple_localpath(self):
@@ -71,13 +71,13 @@ 

  

          self.helper.process(self.ref_input, None)

  

-         download_calls = self.mock_download.calls

+         download_calls = self.mock_download.call_args_list

          assert len(download_calls) == 2

-         assert download_calls[0][1][0] == self._get_url(ref_path[0])

-         assert download_calls[1][1][0] == self._get_url(ref_path[1])

-         assert download_calls[0][1][2] == os.path.join(self.ref_input['target_dir'],

+         assert download_calls[0][0][0] == self._get_url(ref_path[0])

+         assert download_calls[1][0][0] == self._get_url(ref_path[1])

+         assert download_calls[0][0][2] == os.path.join(self.ref_input['target_dir'],

                                                         ref_localpath[0])

-         assert download_calls[1][1][2] == os.path.join(self.ref_input['target_dir'],

+         assert download_calls[1][0][2] == os.path.join(self.ref_input['target_dir'],

                                                         ref_localpath[1])

  

      def test_incorrect_localpath(self):
@@ -113,9 +113,9 @@ 

  

          self.helper.process(self.ref_input, None)

  

-         download_calls = self.mock_download.calls

+         download_calls = self.mock_download.call_args_list

          assert len(download_calls) == 1

-         assert download_calls[0][1][0] == self._get_url(self.ref_path[0])

+         assert download_calls[0][0][0] == self._get_url(self.ref_path[0])

  

      def test_missing_path(self):

          self.ref_input.pop('path', None)
@@ -135,10 +135,10 @@ 

  

          self.helper.process(self.ref_input, None)

  

-         download_calls = self.mock_download.calls

+         download_calls = self.mock_download.call_args_list

          assert len(download_calls) == 1

          # self.ref_nvr was not touched, so if nvr parsing gets priority, the URL will not match

-         assert download_calls[0][1][0] == self._get_url(self.ref_path[0])

+         assert download_calls[0][0][0] == self._get_url(self.ref_path[0])

  

      def test_raises_on_404(self, monkeypatch):

          '''Directive must raise when file is missing in distgit (404)'''
@@ -191,5 +191,5 @@ 

  

          self.helper.process(self.ref_input, None)

  

-         download_calls = self.mock_download.calls

-         assert download_calls[0][1][0] == self._get_url(self.ref_path[0])

+         download_calls = self.mock_download.call_args_list

+         assert download_calls[0][0][0] == self._get_url(self.ref_path[0])

file modified
+54 -57
@@ -3,7 +3,6 @@ 

  # License: GPL-2.0+ <http://spdx.org/licenses/GPL-2.0+>

  # See the LICENSE file for more details on Licensing

  

- from dingus import Dingus

  import pytest

  import mock

  import os
@@ -32,16 +31,15 @@ 

                            'koji_build': self.ref_nvr,

                            'target_dir': self.ref_targetdir}

  

-         stub_koji = Dingus(get_nvr_rpms__returns = self.ref_rpms)

- 

+         stub_koji = mock.Mock(**{'get_nvr_rpms.return_value': self.ref_rpms})

          test_helper = koji_directive.KojiDirective(stub_koji)

  

          test_helper.process(self.ref_input, None)

  

-         getrpm_calls = stub_koji.calls()

-         requested_nvr = getrpm_calls[0][1][0]

-         requested_src = getrpm_calls[0][2]['src']

-         requested_debuginfo = getrpm_calls[0][2]['debuginfo']

+         getrpm_calls = stub_koji.get_nvr_rpms.call_args_list

+         requested_nvr = getrpm_calls[0][0][0]

+         requested_src = getrpm_calls[0][1]['src']

+         requested_debuginfo = getrpm_calls[0][1]['debuginfo']

  

          assert len(getrpm_calls) == 1

          assert requested_nvr == self.ref_nvr
@@ -49,45 +47,40 @@ 

          assert not requested_debuginfo

  

      def test_parse_download_tag_command(self):

- 

          self.ref_input = {'action': 'download_tag',

                            'arch': self.ref_arch,

                            'koji_tag': self.ref_tag,

                            'target_dir': self.ref_targetdir}

- 

-         stub_koji = Dingus(get_tagged_rpms__returns=self.ref_rpms)

- 

+         stub_koji = mock.Mock(

+             **{'get_tagged_rpms.return_value': self.ref_rpms})

          test_helper = koji_directive.KojiDirective(stub_koji)

  

          test_helper.process(self.ref_input, None)

  

-         getrpm_calls = stub_koji.calls()

-         requested_tag = getrpm_calls[0][1][0]

+         getrpm_calls = stub_koji.get_tagged_rpms.call_args_list

+         requested_tag = getrpm_calls[0][0][0]

  

          assert len(getrpm_calls) == 1

          assert requested_tag == self.ref_tag

  

      def test_parse_download_latest_stable_command(self):

- 

          self.ref_input = {'action': 'download_latest_stable',

                            'arch': self.ref_arch,

                            'koji_build': self.ref_nvr,

                            'target_dir': self.ref_targetdir}

- 

-         stub_koji = Dingus(get_nvr_rpms__returns=self.ref_rpms,

-                            latest_by_tag__returns=self.ref_previous_nvr)

- 

+         stub_koji = mock.Mock(**

+             {'get_nvr_rpms.return_value': self.ref_rpms,

+              'latest_by_tag.return_value': self.ref_previous_nvr})

          test_helper = koji_directive.KojiDirective(stub_koji)

  

          test_helper.process(self.ref_input, None)

  

-         koji_calls = stub_koji.calls()

- 

-         getrpm_calls = koji_calls[1]

-         requested_nvr = getrpm_calls[1][0]

-         requested_src = getrpm_calls[2]['src']

-         requested_debuginfo = getrpm_calls[2]['debuginfo']

+         getrpm_calls = stub_koji.get_nvr_rpms.call_args

+         requested_nvr = getrpm_calls[0][0]

+         requested_src = getrpm_calls[1]['src']

+         requested_debuginfo = getrpm_calls[1]['debuginfo']

  

+         koji_calls = stub_koji.method_calls

          assert len(koji_calls) == 2

          assert requested_nvr == self.ref_previous_nvr

          assert not requested_src
@@ -95,20 +88,17 @@ 

  

      def test_download_latest_stable_no_builds(self):

          '''Don't do anything if there are no latest stable builds'''

- 

          self.ref_input = {'action': 'download_latest_stable',

                            'arch': self.ref_arch,

                            'koji_build': self.ref_nvr,

                            'target_dir': self.ref_targetdir}

- 

-         stub_koji = Dingus(latest_by_tag__returns=None)

+         stub_koji = mock.Mock(**{'latest_by_tag.return_value': None})

          test_helper = koji_directive.KojiDirective(stub_koji)

  

          retval = test_helper.process(self.ref_input, None)

  

-         koji_calls = stub_koji.calls()

+         koji_calls = stub_koji.latest_by_tag.call_args_list

          assert len(koji_calls) == 1

-         assert koji_calls[0][0] == 'latest_by_tag'

          assert retval == {}

  

      @pytest.mark.parametrize('action', ACTIONS)
@@ -117,12 +107,13 @@ 

          ref_input = {'action': action, 'arch': self.ref_arch,

                       'koji_build': self.ref_nvr, 'koji_tag': self.ref_tag,

                       'target_dir': self.ref_targetdir}

- 

-         stub_koji = Dingus('koji_utils')

+         stub_koji = mock.Mock()

          test_helper = koji_directive.KojiDirective(stub_koji)

+ 

          test_helper.process(ref_input, None)

  

-         getrpm_calls = [call for call in stub_koji.calls() if call[0] in self.koji_calls]

+         getrpm_calls = [call for call in stub_koji.method_calls

+             if call[0] in self.koji_calls]

          assert len(getrpm_calls) >= 1

          for call in getrpm_calls:

              requested_arches = call[2]['arches']
@@ -133,13 +124,13 @@ 

          ref_input = {'action': action, 'arch': self.ref_arch,

                       'koji_build': self.ref_nvr, 'koji_tag': self.ref_tag,

                       'target_dir': self.ref_targetdir}

- 

-         stub_koji = Dingus('koji_utils')

- 

+         stub_koji = mock.Mock()

          test_helper = koji_directive.KojiDirective(stub_koji)

+ 

          test_helper.process(ref_input, None)

  

-         getrpm_calls = [call for call in stub_koji.calls() if call[0] in self.koji_calls]

+         getrpm_calls = [call for call in stub_koji.method_calls

+             if call[0] in self.koji_calls]

          assert len(getrpm_calls) >= 1

          for call in getrpm_calls:

              requested_arches = call[2]['arches']
@@ -150,13 +141,13 @@ 

          ref_input = {'action': action, 'arch': [self.ref_arch],

                       'koji_build': self.ref_nvr, 'koji_tag': self.ref_tag,

                       'target_dir': self.ref_targetdir}

- 

-         stub_koji = Dingus('koji_utils')

- 

+         stub_koji = mock.Mock()

          test_helper = koji_directive.KojiDirective(stub_koji)

+ 

          test_helper.process(ref_input, None)

  

-         getrpm_calls = [call for call in stub_koji.calls() if call[0] in self.koji_calls]

+         getrpm_calls = [call for call in stub_koji.method_calls

+             if call[0] in self.koji_calls]

          assert len(getrpm_calls) >= 1

          for call in getrpm_calls:

              requested_arches = call[2]['arches']
@@ -167,12 +158,13 @@ 

          ref_input = {'action': action, 'arch': 'x86_64',

                       'koji_build': self.ref_nvr, 'koji_tag': self.ref_tag,

                       'target_dir': self.ref_targetdir}

- 

-         stub_koji = Dingus()

+         stub_koji = mock.Mock()

          test_helper = koji_directive.KojiDirective(stub_koji)

+ 

          test_helper.process(ref_input, None)

  

-         getrpm_calls = [call for call in stub_koji.calls() if call[0] in self.koji_calls]

+         getrpm_calls = [call for call in stub_koji.method_calls

+             if call[0] in self.koji_calls]

          assert len(getrpm_calls) >= 1

          for call in getrpm_calls:

              requested_arches = call[2]['arches']
@@ -182,15 +174,17 @@ 

  

      @pytest.mark.parametrize('action', ACTIONS)

      def test_exclude_arch(self, action):

-         ref_input = {'action': action, 'arch': 'all', 'arch_exclude': ['x86_64', 'noarch'],

+         ref_input = {'action': action, 'arch': 'all',

+                      'arch_exclude': ['x86_64', 'noarch'],

                       'koji_build': self.ref_nvr, 'koji_tag': self.ref_tag,

                       'target_dir': self.ref_targetdir}

- 

-         stub_koji = Dingus()

+         stub_koji = mock.Mock()

          test_helper = koji_directive.KojiDirective(stub_koji)

+ 

          test_helper.process(ref_input, None)

  

-         getrpm_calls = [call for call in stub_koji.calls() if call[0] in self.koji_calls]

+         getrpm_calls = [call for call in stub_koji.method_calls

+             if call[0] in self.koji_calls]

          assert len(getrpm_calls) >= 1

          for call in getrpm_calls:

              requested_arches = call[2]['arches']
@@ -205,12 +199,13 @@ 

          ref_input = {'action': action, 'arch': [], 'src': True,

                       'koji_build': self.ref_nvr, 'koji_tag': self.ref_tag,

                       'target_dir': self.ref_targetdir}

- 

-         stub_koji = Dingus()

+         stub_koji = mock.Mock()

          test_helper = koji_directive.KojiDirective(stub_koji)

+ 

          test_helper.process(ref_input, None)

  

-         getrpm_calls = [call for call in stub_koji.calls() if call[0] in self.koji_calls]

+         getrpm_calls = [call for call in stub_koji.method_calls

+             if call[0] in self.koji_calls]

          assert len(getrpm_calls) >= 1

          for call in getrpm_calls:

              requested_arches = call[2]['arches']
@@ -223,12 +218,13 @@ 

          ref_input = {'action': action, 'arch': [], 'debuginfo': True,

                       'koji_build': self.ref_nvr, 'koji_tag': self.ref_tag,

                       'target_dir': self.ref_targetdir}

- 

-         stub_koji = Dingus()

+         stub_koji = mock.Mock()

          test_helper = koji_directive.KojiDirective(stub_koji)

+ 

          test_helper.process(ref_input, None)

  

-         getrpm_calls = [call for call in stub_koji.calls() if call[0] in self.koji_calls]

+         getrpm_calls = [call for call in stub_koji.method_calls

+             if call[0] in self.koji_calls]

          assert len(getrpm_calls) >= 1

          for call in getrpm_calls:

              requested_arches = call[2]['arches']
@@ -246,7 +242,8 @@ 

  

          test_helper.process(ref_input, None)

  

-         build_log_calls = [call for call in stub_koji.method_calls if call[0] == 'get_build_log']

+         build_log_calls = [call for call in stub_koji.method_calls

+             if call[0] == 'get_build_log']

          if action in BUILD_LOG_ACTIONS:

              assert len(build_log_calls) == 1

          else:
@@ -257,7 +254,8 @@ 

          ref_input = {'action': action, 'arch': [], 'build_log': True,

                       'koji_build': self.ref_nvr, 'koji_tag': self.ref_tag,

                       'target_dir': self.ref_targetdir}

-         ref_get_bl_return = {'ok': ['/path/build.log.arch'], 'error': ['some_arch']}

+         ref_get_bl_return = {'ok': ['/path/build.log.arch'],

+             'error': ['some_arch']}

          stub_koji = mock.MagicMock()

          stub_koji.get_build_log.return_value = ref_get_bl_return

          test_helper = koji_directive.KojiDirective(stub_koji)
@@ -273,8 +271,7 @@ 

                            'arch': self.ref_arch,

                            'koji_build': self.ref_nvr,

                            'target_dir': rpmdir}

- 

-         stub_koji = Dingus(get_nvr_rpms__returns=self.ref_rpms)

+         stub_koji = mock.Mock(**{'get_nvr_rpms.return_value': self.ref_rpms})

          test_helper = koji_directive.KojiDirective(stub_koji)

  

          assert not os.path.exists(rpmdir)

file modified
+85 -54
@@ -6,7 +6,6 @@ 

  '''Unit tests for libtaskotron/koji_utils.py'''

  

  import pytest

- from dingus import Dingus

  import os

  import itertools

  import mock
@@ -80,8 +79,12 @@ 

      # =====================

  

      def test_latest_by_tag_first_tag_miss(self):

-         stub_koji = Dingus(listTagged__returns=None,

-                            multiCall__returns=[[[]], [[{'nvr': self.ref_latest_stable}]]])

+         stub_koji = mock.Mock(**

+             {'listTagged.return_value': None,

+              'multiCall.return_value': [

+                 [[]], [[{'nvr': self.ref_latest_stable}]]

+                 ]

+             })

  

          test_koji = koji_utils.KojiClient(stub_koji)

          outcome = test_koji.latest_by_tag(self.ref_tags, self.ref_name)
@@ -89,8 +92,12 @@ 

          assert outcome == self.ref_latest_stable

  

      def test_latest_by_tag_second_tag_miss(self):

-         stub_koji = Dingus(listTagged__returns=None,

-                            multiCall__returns=[[[{'nvr': self.ref_latest_stable}]], [[]]])

+         stub_koji = mock.Mock(**

+             {'listTagged.return_value': None,

+              'multiCall.return_value': [

+                 [[{'nvr': self.ref_latest_stable}]], [[]]

+                 ]

+             })

  

          test_koji = koji_utils.KojiClient(stub_koji)

          outcome = test_koji.latest_by_tag(self.ref_tags, self.ref_name)
@@ -98,8 +105,12 @@ 

          assert outcome == self.ref_latest_stable

  

      def test_latest_by_tag_build_not_found(self):

-         stub_koji = Dingus(listTagged__returns=None,

-                            multiCall__returns=[[[]], [[]]])

+         stub_koji = mock.Mock(**

+             {'listTagged.return_value': None,

+              'multiCall.return_value': [

+                 [[]], [[]]

+                 ]

+             })

  

          test_koji = koji_utils.KojiClient(stub_koji)

          assert test_koji.latest_by_tag(self.ref_tags, self.ref_name) is None
@@ -109,11 +120,13 @@ 

      # =====================

  

      def test_rpms_to_build(self):

-         stub_koji = Dingus(getBuild__returns=None,

-                            getRPM__returns=None,

-                            multiCall=create_multicall(

-                                [[self.ref_rpms[0]], [self.ref_rpms[1]]],

-                                [[self.ref_build], [self.ref_build]]))

+         stub_koji = mock.Mock(**

+             {'getBuild.return_value': None,

+              'getRPM.return_value': None,

+              'multiCall': create_multicall(

+                 [[self.ref_rpms[0]], [self.ref_rpms[1]]],

+                 [[self.ref_build], [self.ref_build]])

+             })

  

          test_koji = koji_utils.KojiClient(stub_koji)

          outcome = test_koji.rpms_to_build([self.ref_filename,self.ref_filename])
@@ -121,39 +134,47 @@ 

          assert outcome == [self.ref_build, self.ref_build]

          # because two rpms come from same build, it gets called twice for each

          # rpm, once for build

-         assert len(stub_koji.calls) == 3

- 

+         assert len(stub_koji.mock_calls) == 3

  

      def test_rpms_to_build_exceptions(self):

-         stub_koji = Dingus(getRPM__returns=None,

-                            multiCall__returns=[{"faultCode": -1,

-                                                 "faultString": "failed"}])

+         stub_koji = mock.Mock(**

+             {'getRPM.return_value': None,

+              'multiCall.return_value':

+                 [{"faultCode": -1, "faultString": "failed"}]

+             })

          test_koji = koji_utils.KojiClient(stub_koji)

  

          with pytest.raises(exc.TaskotronRemoteError):

              test_koji.rpms_to_build([self.ref_filename])

  

-         stub_koji = Dingus(getBuild__returns=None,

-                            getRPM__returns=None,

-                            multiCall=create_multicall([[self.ref_rpms[0]]], [

-                                {"faultCode": -1, "faultString": "failed"}]))

+         stub_koji = mock.Mock(**

+             {'getBuild.return_value': None,

+              'getRPM.return_value': None,

+              'multiCall': create_multicall(

+                 [[self.ref_rpms[0]]],

+                 [{"faultCode": -1, "faultString": "failed"}])

+             })

  

          test_koji = koji_utils.KojiClient(stub_koji)

          with pytest.raises(exc.TaskotronRemoteError):

              test_koji.rpms_to_build([self.ref_filename])

  

-         stub_koji = Dingus(getBuild__returns=None,

-                            getRPM__returns=None,

-                            multiCall__returns=[[None]])

+         stub_koji = mock.Mock(**

+             {'getBuild.return_value': None,

+              'getRPM.return_value': None,

+              'multiCall.return_value': [[None]],

+             })

  

          test_koji = koji_utils.KojiClient(stub_koji)

          with pytest.raises(exc.TaskotronRemoteError):

              test_koji.rpms_to_build([self.ref_filename])

  

-         stub_koji = Dingus(getBuild__returns=None,

-                            getRPM__returns=None,

-                            multiCall=create_multicall([[self.ref_rpms[0]]],

-                                                       [[None]]))

+         stub_koji = mock.Mock(**

+             {'getBuild.return_value': None,

+              'getRPM.return_value': None,

+              'multiCall': create_multicall(

+                 [[self.ref_rpms[0]]], [[None]]),

+             })

  

          test_koji = koji_utils.KojiClient(stub_koji)

          with pytest.raises(exc.TaskotronRemoteError):
@@ -228,8 +249,10 @@ 

      # ===================

  

      def test_get_urls(self):

-         stub_koji = Dingus(getBuild__returns=self.ref_build,

-                            listRPMs__returns=self.ref_rpms)

+         stub_koji = mock.Mock(**

+             {'getBuild.return_value': self.ref_build,

+              'listRPMs.return_value': self.ref_rpms,

+             })

          test_koji = koji_utils.KojiClient(stub_koji)

          koji_baseurl = config.get_config().pkg_url

  
@@ -240,14 +263,18 @@ 

  

      def should_not_throw_exception_norpms(self):

          '''It's possible to have no RPMs (for the given arch) in a build'''

-         stub_koji = Dingus(getBuild__returns = self.ref_build)

+         stub_koji = mock.MagicMock(**

+             {'getBuild.return_value': self.ref_build,

+             })

          test_koji = koji_utils.KojiClient(stub_koji)

  

          test_koji.nvr_to_urls(self.ref_nvr, arches = [self.ref_arch])

  

      def test_nvr_to_urls_debuginfo(self):

-         stub_koji = Dingus(getBuild__returns=self.ref_build,

-                            listRPMs__returns=self.ref_rpms)

+         stub_koji = mock.Mock(**

+             {'getBuild.return_value': self.ref_build,

+              'listRPMs.return_value': self.ref_rpms,

+             })

          test_koji = koji_utils.KojiClient(stub_koji)

  

          # debuginfo enabled
@@ -275,7 +302,7 @@ 

  

      def test_get_nvr_rpms_simple(self, monkeypatch):

          '''NVR contains a few RPMs'''

-         test_koji = koji_utils.KojiClient(Dingus())

+         test_koji = koji_utils.KojiClient(mock.Mock())

  

          stub_urls = [

              'http://localhost/file1.rpm',
@@ -283,7 +310,7 @@ 

          monkeypatch.setattr(test_koji, 'nvr_to_urls',

                              lambda *args, **kwargs: stub_urls)

          monkeypatch.setattr(file_utils, 'download', mock_download)

-         monkeypatch.setattr(file_utils, 'makedirs', Dingus())

+         monkeypatch.setattr(file_utils, 'makedirs', mock.Mock())

  

          rpmdir = '/fake'

          rpm_files = test_koji.get_nvr_rpms(self.ref_nvr, dest=rpmdir)
@@ -294,11 +321,11 @@ 

  

      def test_get_nvr_rpms_empty(self, monkeypatch):

          '''NVR contains no RPMs (e.g. of a particular arch)'''

-         test_koji = koji_utils.KojiClient(Dingus())

+         test_koji = koji_utils.KojiClient(mock.Mock())

  

          monkeypatch.setattr(test_koji, 'nvr_to_urls', lambda *args, **kwargs: [])

          monkeypatch.setattr(file_utils, 'download', mock_download)

-         monkeypatch.setattr(file_utils, 'makedirs', Dingus())

+         monkeypatch.setattr(file_utils, 'makedirs', mock.Mock())

  

          rpmdir = '/fake'

          rpm_files = test_koji.get_nvr_rpms(self.ref_nvr, dest=rpmdir)
@@ -307,37 +334,37 @@ 

  

      def test_get_nvr_rpms_production_profile(self, monkeypatch):

          '''caching should be disabled in production profile'''

-         test_koji = koji_utils.KojiClient(Dingus())

-         stub_download = Dingus()

+         test_koji = koji_utils.KojiClient(mock.Mock())

+         stub_download = mock.Mock()

  

          monkeypatch.setattr(test_koji, 'nvr_to_urls',

                              lambda *args, **kwargs: ['foo'])

          monkeypatch.setattr(file_utils, 'download', stub_download)

-         monkeypatch.setattr(file_utils, 'makedirs', Dingus())

+         monkeypatch.setattr(file_utils, 'makedirs', mock.Mock())

          monkeypatch.setattr(config, '_config', config.ProductionConfig)

  

          rpmdir = '/fake'

          test_koji.get_nvr_rpms(self.ref_nvr, dest=rpmdir)

  

-         call = stub_download.calls[0]

-         assert call[2]['cachedir'] is None

+         call = stub_download.call_args

+         assert call[1]['cachedir'] is None

  

      def test_get_nvr_rpms_development_profile(self, monkeypatch):

          '''caching should be disabled in development profile'''

-         test_koji = koji_utils.KojiClient(Dingus())

-         stub_download = Dingus()

+         test_koji = koji_utils.KojiClient(mock.Mock())

+         stub_download = mock.Mock()

  

          monkeypatch.setattr(test_koji, 'nvr_to_urls',

                              lambda *args, **kwargs: ['foo'])

          monkeypatch.setattr(file_utils, 'download', stub_download)

-         monkeypatch.setattr(file_utils, 'makedirs', Dingus())

+         monkeypatch.setattr(file_utils, 'makedirs', mock.Mock())

          monkeypatch.setattr(config, '_config', config.Config)

  

          rpmdir = '/fake'

          test_koji.get_nvr_rpms(self.ref_nvr, dest=rpmdir)

  

-         call = stub_download.calls[0]

-         assert call[2]['cachedir'] is not None

+         call = stub_download.call_args

+         assert call[1]['cachedir'] is not None

  

      # =======================

      #    get_tagged_rpms()
@@ -345,7 +372,9 @@ 

  

      def test_get_tagged_rpms_single(self, monkeypatch):

          '''Single NVR in a tag'''

-         stub_koji = Dingus(listTagged__returns=[self.ref_build])

+         stub_koji = mock.Mock(**

+             {'listTagged.return_value': [self.ref_build]

+             })

          test_koji = koji_utils.KojiClient(stub_koji)

  

          stub_rpms = [
@@ -361,10 +390,10 @@ 

  

      def test_get_tagged_rpms_multiple(self, monkeypatch):

          '''Multiple NVRs in a tag'''

-         stub_koji = Dingus(listTagged__returns=[self.ref_build,

-                                                 {'nvr': 'bar-1-1'}])

+         stub_koji = mock.Mock(**

+             {'listTagged.return_value': [self.ref_build, {'nvr': 'bar-1-1'}]

+             })

          test_koji = koji_utils.KojiClient(stub_koji)

- 

          stub_rpms = {self.ref_build['nvr']: ['/fake/file1.rpm',

                                               '/fake/file2.rpm'],

                       'bar-1-1': ['/fake/bar1.rpm']
@@ -379,9 +408,11 @@ 

  

      def test_get_tagged_rpms_none(self, monkeypatch):

          '''No NVRs in a tag'''

-         stub_koji = Dingus(listTagged__returns=[])

+         stub_koji = mock.Mock(**

+             {'listTagged.return_value': [],

+             })

          test_koji = koji_utils.KojiClient(stub_koji)

-         stub_get_nvr_rpms = Dingus()

+         stub_get_nvr_rpms = mock.Mock()

  

          monkeypatch.setattr(test_koji, 'get_nvr_rpms', stub_get_nvr_rpms)

          monkeypatch.setattr(file_utils, 'makedirs', lambda *args, **kwargs: None)
@@ -390,7 +421,7 @@ 

  

          assert rpm_files == []

          # get_nvr_rpms() should not be called

-         assert stub_get_nvr_rpms.calls() == []

+         stub_get_nvr_rpms.assert_not_called()

  

      # =====================

      #    get_build_log()

file modified
+12 -14
@@ -4,7 +4,7 @@ 

  # See the LICENSE file for more details on Licensing

  

  import pytest

- from dingus import Dingus

+ import mock

  import os

  import argparse

  
@@ -19,12 +19,10 @@ 

      @pytest.fixture

      def setup(self, monkeypatch):

          self.ref_artifactsdir = '/dir/'

-         self.stub_config = Dingus()

-         self.stub_get_config = Dingus()

+         self.stub_config = mock.Mock(artifactsdir=self.ref_artifactsdir)

+         self.stub_get_config = mock.Mock(return_value=self.stub_config)

  

-         self.stub_get_config.return_value = self.stub_config

          monkeypatch.setattr(config, 'get_config', self.stub_get_config)

-         self.stub_config.artifactsdir = self.ref_artifactsdir

  

          self.ref_input = {'arch': 'x86_64',

                            'item': 'foo-1.2-3.fc99',
@@ -106,35 +104,35 @@ 

                             {}]

  

          for ref_params in ref_params_bad:

-             stub_error = Dingus()

-             stub_parser = Dingus()

+             stub_error = mock.Mock()

+             stub_parser = mock.Mock()

              stub_parser.error = stub_error

              args = self.empty_args.copy()

              args.update(ref_params)

              main.check_args(stub_parser, args)

-             assert len(stub_error.calls()) == 1

+             assert len(stub_error.mock_calls) == 1

  

          for ref_params in ref_params_good:

-             stub_error = Dingus()

-             stub_parser = Dingus()

+             stub_error = mock.Mock()

+             stub_parser = mock.Mock()

              stub_parser.error = stub_error

              args = self.empty_args.copy()

              args.update(ref_params)

              main.check_args(stub_parser, args)

-             assert len(stub_error.calls()) == 0

+             assert len(stub_error.mock_calls) == 0

  

      def test_ssh_bad_usermachine(self):

          '''fail on invalid user@machine[:port] specifier'''

          ref_params = {'ssh': 'user#machine'}

  

-         stub_error = Dingus()

-         stub_parser = Dingus()

+         stub_error = mock.Mock()

+         stub_parser = mock.Mock()

          stub_parser.error = stub_error

          args = self.empty_args

          args.update(ref_params)

          main.check_args(stub_parser, args)

  

-         assert len(stub_error.calls()) == 1

+         assert len(stub_error.mock_calls) == 1

  

  

  class TestGetParser():

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

  

  import os

  import pytest

- from dingus import Dingus, exception_raiser

+ import mock

  import configparser

  

  from libtaskotron.directives import resultsdb_directive
@@ -65,10 +65,11 @@ 

                              'uuid': 'c25237a4-b6b3-11e4-b98a-3c970e018701',

                              'description': self.cd.checkname}

  

-         self.stub_rdb = Dingus('resultsdb', get_testcase__returns={},

-                                create_job__returns=self.ref_jobdata,

-                                create_result__returns=self.ref_resultdata,

-                                )

+         self.stub_rdb = mock.Mock(**

+             {'get_testcase.return_value': {},

+              'create_job.return_value': self.ref_jobdata,

+              'create_result.return_value': self.ref_resultdata,

+             })

          self.test_rdb = resultsdb_directive.ResultsdbDirective(self.stub_rdb)

  

          # while it appears useless, this actually sets config in several tests
@@ -96,14 +97,15 @@ 

          assert cds[0].__dict__ == my_cd[0].__dict__

  

          # no call should have been made

-         assert len(self.stub_rdb.calls()) == 0

+         assert len(self.stub_rdb.mock_calls) == 0

  

          config._config = None

  

      def test_failed_yaml_import(self, monkeypatch):

          """Checks if failed YAML import raises exception"""

-         monkeypatch.setattr(check, 'import_YAML',

-                             exception_raiser(TaskotronValueError("Testing Error")))

+         mock_import_yaml = mock.Mock(

+             side_effect=TaskotronValueError("Testing Error"))

+         monkeypatch.setattr(check, 'import_YAML', mock_import_yaml)

  

          with pytest.raises(TaskotronDirectiveError):

              self.test_rdb.process(self.ref_input, self.ref_arg_data)
@@ -155,13 +157,14 @@ 

          # we expect rdb to be called 2 times:

          # check for testcase, and report result

  

-         assert len(self.stub_rdb.calls()) == 2

+         assert len(self.stub_rdb.mock_calls) == 2

  

          # Select the first call of "create_result" method.

          # This could be written as self.stub_rdb.calls()[0] at the moment, but

          #   this is more future-proof, and accidental addition of resultsdb

          #   calls is handled by the previous assert.

-         call = [call for call in self.stub_rdb.calls() if call[0] == 'create_result'][0]

+         call = [call for call in self.stub_rdb.mock_calls

+             if call[0] == 'create_result'][0]

          # Select the keyword arguments of that call

          call_data = call[2]

  
@@ -191,7 +194,7 @@ 

  

          for ref_yaml in [yaml1, yaml2]:

              self.test_rdb.process({'results': ref_yaml}, self.ref_arg_data)

-             assert len(self.stub_rdb.calls()) == 0

+             assert len(self.stub_rdb.mock_calls) == 0

  

      def test_empty_file(self):

          """Should raise for a completely empty file"""
@@ -199,7 +202,7 @@ 

          with pytest.raises(TaskotronDirectiveError):

              self.test_rdb.process({'results': ''}, self.ref_arg_data)

  

-         assert len(self.stub_rdb.calls()) == 0

+         assert len(self.stub_rdb.mock_calls) == 0

  

      def test_both_file_and_results(self, monkeypatch):

          ref_input = {'results': 'foobar', 'file': 'foo.bar'}
@@ -254,13 +257,14 @@ 

          # we expect rdb to be called 4 times: create job, update to RUNNING,

          # check for testcase, report result and complete job

  

-         assert len(self.stub_rdb.calls()) == 2

+         assert len(self.stub_rdb.mock_calls) == 2

  

          # Select the first call of "create_result" method.

          # This could be written as self.stub_rdb.calls()[0] at the moment, but

          #   this is more future-proof, and accidental addition of resultsdb

          #   calls is handled by the previous assert.

-         call = [call for call in self.stub_rdb.calls() if call[0] == 'create_result'][0]

+         call = [call for call in self.stub_rdb.mock_calls

+             if call[0] == 'create_result'][0]

          # Select the keyword arguments of that call

          call_data = call[2]

  
@@ -279,7 +283,7 @@ 

  

          assert test_jobdata == self.ref_jobdata

  

-         rdb_calls = self.stub_rdb.calls()

+         rdb_calls = self.stub_rdb.mock_calls

          # we expect only one call to resultsdb when reporting a result

          assert len(rdb_calls) == 0

  
@@ -287,15 +291,16 @@ 

          # check to see if the testcase is created in the case that it doesn't

          # already exist

  

-         self.stub_rdb.get_testcase = exception_raiser(ResultsDBapiException('Testcase not found'))

+         self.stub_rdb.get_testcase.side_effect = ResultsDBapiException(

+             'Testcase not found')

  

          self.test_rdb.ensure_testcase_exists(self.cd.checkname)

  

-         rdb_calls = self.stub_rdb.calls()

+         rdb_calls = self.stub_rdb.mock_calls

  

-         # dingus doesn't record calls to exception_raiser

-         assert len(rdb_calls) == 1

-         assert rdb_calls[0][0] == 'create_testcase'

+         assert len(rdb_calls) == 2

+         assert rdb_calls[0][0] == 'get_testcase'

+         assert rdb_calls[1][0] == 'create_testcase'

  

      def test_ensure_testcase_creation_exists(self):

          # check to make sure that a testcase is _not_ created in the case that
@@ -303,7 +308,7 @@ 

  

          self.test_rdb.ensure_testcase_exists(self.cd.checkname)

  

-         rdb_calls = self.stub_rdb.calls()

+         rdb_calls = self.stub_rdb.mock_calls

  

          assert len(rdb_calls) == 1

          assert rdb_calls[0][0] == 'get_testcase'
@@ -314,7 +319,7 @@ 

          self.test_rdb.ensure_testcase_exists(self.cd.checkname)

          self.test_rdb.ensure_testcase_exists(self.cd.checkname)

  

-         rdb_calls = self.stub_rdb.calls()

+         rdb_calls = self.stub_rdb.mock_calls

  

          assert len(rdb_calls) == 1

          assert rdb_calls[0][0] == 'get_testcase'

file modified
+3 -4
@@ -5,7 +5,6 @@ 

  

  import pytest

  from mock import Mock, MagicMock

- from dingus import Dingus

  

  from libtaskotron.ext.disposable import vm

  from libtaskotron import exceptions as exc
@@ -24,7 +23,7 @@ 

          stub_image = Mock(side_effect=tce.TestcloudImageError())

  

          monkeypatch.setattr(image, 'Image', stub_image)

-         monkeypatch.setattr(vm.ImageFinder, 'get_latest_metadata', Dingus())

+         monkeypatch.setattr(vm.ImageFinder, 'get_latest_metadata', Mock())

  

          test_vm = vm.TestCloudMachine(self.ref_uuid)

  
@@ -35,7 +34,7 @@ 

          stub_image = MagicMock()

  

          monkeypatch.setattr(image, 'Image', stub_image)

-         monkeypatch.setattr(vm.ImageFinder, 'get_latest_metadata', Dingus())

+         monkeypatch.setattr(vm.ImageFinder, 'get_latest_metadata', Mock())

  

          test_vm = vm.TestCloudMachine(self.ref_uuid)

  
@@ -157,7 +156,7 @@ 

                         '151008_0315-fedora-23-minimal-i386.qcow2',

                         '151008_0315-fedora-23-minimal-x86_64.qcow2',

                         '151008_0315-ubuntu-fabulous_fanthom-minimal-x86_64.qcow2']

-         self.stub_list_images = Dingus()

+         self.stub_list_images = Mock()

          monkeypatch.setattr(vm.ImageFinder, 'get_all_filenames', self.stub_list_images)