#103 Add a test of the runroot hub plugin.
Merged 5 years ago by mikem. Opened 5 years ago by ralph.
ralph/koji runroot-tests  into  master

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

  	@git clean -d -q -x

  

  test:

- 	PYTHONPATH=hub/. nosetests --with-coverage --cover-package .

+ 	PYTHONPATH=hub/.:plugins/hub/. nosetests --with-coverage --cover-package .

  

  subdirs:

  	for d in $(SUBDIRS); do make -C $$d; [ $$? = 0 ] || exit 1; done

file modified
-11
@@ -568,17 +568,6 @@ 

      koji.plugin.run_callbacks('postTaskStateChange', attribute='state', old=None, new='FREE', info=opts)

      return task_id

  

- def mktask(__taskopts,__method,*args,**opts):

-     """A wrapper around make_task with alternate signature

- 

-     Parameters:

-         _taskopts: a dictionary of task options (e.g. priority, ...)

-         _method: the method to be invoked

- 

-     All remaining args (incl. optional ones) are passed on to the task.

-     """

-     return make_task(__method,koji.encode_args(*args,**opts),**__taskopts)

- 

  def eventCondition(event, table=None):

      """return the proper WHERE condition to select data at the time specified by event. """

      if not table:

file modified
+6 -5
@@ -9,9 +9,9 @@ 

  import random

  import sys

  

- #XXX - have to import kojihub for mktask

+ #XXX - have to import kojihub for make_task

  sys.path.insert(0, '/usr/share/koji-hub/')

- from kojihub import mktask, get_tag, get_all_arches

+ import kojihub

  

  __all__ = ('runroot',)

  
@@ -38,12 +38,12 @@ 

  

      if arch == 'noarch':

          #not all arches can generate a proper buildroot for all tags

-         tag = get_tag(tagInfo)

+         tag = kojihub.get_tag(tagInfo)

          if not tag['arches']:

              raise koji.GenericError, 'no arches defined for tag %s' % tag['name']

  

          #get all known arches for the system

-         fullarches = get_all_arches()

+         fullarches = kojihub.get_all_arches()

  

          tagarches = tag['arches'].split()

  
@@ -57,5 +57,6 @@ 

                              % (tagInfo, taskopts['channel'])

              taskopts['arch'] = koji.canonArch(random.choice(choices))

  

-     return mktask(taskopts,'runroot', tagInfo, arch, command, **opts)

+     args = koji.encode_args(tagInfo, arch, command,**opts)

+     return kojihub.make_task('runroot', args, **taskopts)

  

empty or binary file added
@@ -0,0 +1,22 @@ 

+ import unittest

+ import mock

+ 

+ import runroot_hub

+ 

+ 

+ class TestRunrootHub(unittest.TestCase):

+     @mock.patch('kojihub.make_task')

+     @mock.patch('runroot_hub.context')

+     def test_basic_invocation(self, context, make_task):

+         runroot_hub.runroot(

+             tagInfo='some_tag',

+             arch='x86_64',

+             command='ls',

+         )

+         make_task.assert_called_once_with(

+             'runroot',

+             ('some_tag', 'x86_64', 'ls'),

+             priority=15,

+             arch='x86_64',

+             channel='runroot',

+         )

... and remove mktask in favor of make_task (and fix all references).

These were all the references to mktask I could find:

hub/kojihub.py:def mktask(__taskopts,__method,*args,**opts):
plugins/hub/runroot_hub.py:#XXX - have to import kojihub for mktask
plugins/hub/runroot_hub.py:from kojihub import mktask, get_tag, get_all_arches
plugins/hub/runroot_hub.py:    return mktask(taskopts,'runroot', tagInfo, arch, command, **opts)

I wrote the test first to verify that make_task was being called as I expected. I then remove mktask, replaced references, and verified that the test case still passed.

Commit 8a54526 fixes this pull-request

Pull-Request has been merged by mikem@redhat.com

5 years ago