#71 Fix tests for new installer flavor
Merged 5 years ago by adamwill. Opened 5 years ago by adamwill.

file modified
+8 -1
@@ -346,7 +346,14 @@ 

      here.

      """

      version = str(version)

-     currrel = str(fedfind.helpers.get_current_release())

+     try:

+         currrel = str(fedfind.helpers.get_current_release())

+     except ValueError:

+         # but don't fail to schedule if fedfind fails...

+         logger.warning("jobs_from_update: could not determine current release! Assuming current "

+                        "release is same as update release. This may cause some tests to fail "

+                        "if that is not true.")

+         currrel = str(version)

      if not arch:

          # set a default in a way that works neatly with the CLI bits

          arch = 'x86_64'

file modified
+34 -16
@@ -406,8 +406,9 @@ 

      assert ret == ('', [])

  

  @mock.patch('fedfind.helpers.get_current_stables', return_value=[24, 25])

+ @mock.patch('fedfind.helpers.get_current_release', return_value=25)

  @mock.patch('fedora_openqa.schedule.OpenQA_Client', autospec=True)

- def test_jobs_from_update(fakeclient, fakecurr):

+ def test_jobs_from_update(fakeclient, fakecurrr, fakecurrs):

      """Tests for jobs_from_update."""

      # the OpenQA_Client instance mock

      fakeinst = fakeclient.return_value
@@ -416,19 +417,19 @@ 

      fakeinst.openqa_request.return_value = {'jobs': [], 'ids': [1]}

      # simple case

      ret = schedule.jobs_from_update('FEDORA-2017-b07d628952', '25')

-     # should get four jobs (as we schedule for four flavors by default)

-     assert ret == [1, 1, 1, 1]

+     # should get five jobs (as we schedule for five flavors by default)

+     assert ret == [1, 1, 1, 1, 1]

      # find the POST calls

      posts = [call for call in fakeinst.openqa_request.call_args_list if call[0][0] == 'POST']

-     # four flavors by default, four calls

-     assert len(posts) == 4

+     # five flavors by default, five calls

+     assert len(posts) == 5

      parmdicts = [call[0][2] for call in posts]

      # checking two lists of dicts are equivalent is rather tricky; I

      # don't think we can technically rely on the order always being

      # the same, and in Python 3, a list of dicts cannot be sorted.

      # So we assert the length of the list, and assert that each of the

      # expected dicts is in the actual list.

-     assert len(parmdicts) == 4

+     assert len(parmdicts) == 5

      checkdicts = [

          {

              'DISTRI': 'fedora',
@@ -474,6 +475,17 @@ 

              'HDD_1': 'disk_f25_desktop_4_x86_64.img',

              'FLAVOR': 'updates-workstation',

              'DESKTOP': 'gnome',

+         },

+         {

+             'DISTRI': 'fedora',

+             'VERSION': '25',

+             'ARCH': 'x86_64',

+             'BUILD': 'Update-FEDORA-2017-b07d628952',

+             'ADVISORY': 'FEDORA-2017-b07d628952',

+             '_ONLY_OBSOLETE_SAME_BUILD': '1',

+             'START_AFTER_TEST': '',

+             'FLAVOR': 'updates-installer',

+             'CURRREL': '25',

          }

      ]

      for checkdict in checkdicts:
@@ -488,19 +500,20 @@ 

      assert all(parmdict.get('DEVELOPMENT') == 1 for parmdict in parmdicts)

  

      # check we don't crash or fail to schedule if get_current_release

-     # fails

+     # or get_current_stables fail

      fakeinst.openqa_request.reset_mock()

-     fakecurr.side_effect = ValueError("Well, that was unfortunate")

+     fakecurrs.side_effect = ValueError("Well, that was unfortunate")

+     fakecurrr.side_effect = ValueError("Well, that was unfortunate")

      ret = schedule.jobs_from_update('FEDORA-2017-b07d628952', '26')

-     assert ret == [1, 1, 1, 1]

-     fakecurr.side_effect = None

+     assert ret == [1, 1, 1, 1, 1]

+     fakecurrs.side_effect = None

  

      # check we don't schedule upgrade jobs when update is for oldest

      # stable release

      fakeinst.openqa_request.reset_mock()

      ret = schedule.jobs_from_update('FEDORA-2017-b07d628952', '24')

-     # upgrade flavors skipped, so two jobs

-     assert ret == [1, 1]

+     # upgrade flavors skipped, so three jobs

+     assert ret == [1, 1, 1]

  

      # test 'flavors'

      fakeinst.openqa_request.reset_mock()
@@ -516,7 +529,7 @@ 

  

      # test dupe detection and 'force'

      fakeinst.openqa_request.reset_mock()

-     # this looks like a 'dupe' for the server and upgrade flavors

+     # this looks like a 'dupe' for the server, installer and upgrade flavors

      fakeinst.openqa_request.return_value = {

          'jobs': [

              {
@@ -526,6 +539,11 @@ 

              },

              {

                  'settings': {

+                     'FLAVOR': 'updates-installer',

+                 },

+             },

+             {

+                 'settings': {

                      'FLAVOR': 'updates-server-upgrade',

                  },

              },
@@ -539,7 +557,7 @@ 

      }

      ret = schedule.jobs_from_update('FEDORA-2017-b07d628952', '25')

      # should get one job, as we shouldn't POST for server, workstation-upgrade

-     # or server-upgrade

+     # server-upgrade or installer

      assert ret == [1]

      # find the POST calls

      posts = [call for call in fakeinst.openqa_request.call_args_list if call[0][0] == 'POST']
@@ -550,8 +568,8 @@ 

      # now try with force=True

      fakeinst.openqa_request.reset_mock()

      ret = schedule.jobs_from_update('FEDORA-2017-b07d628952', '25', force=True)

-     # should get four jobs this time

-     assert ret == [1, 1, 1, 1]

+     # should get five jobs this time

+     assert ret == [1, 1, 1, 1, 1]

  

      # test extraparams

      fakeinst.openqa_request.reset_mock()

Adding a new flavor broke the tests - which I clearly forgot to
run, because I am a bad person and I should feel bad. This fixes
them.

Signed-off-by: Adam Williamson awilliam@redhat.com

@lruzicka again, this is for your education =) I don't know how familiar you are with pytest stuff? Go ahead and ask if anything isn't clear.

Change the comment to: Five flavors by default, five calls.

I have not gone over all of the tests now, since I believe you are in a hurry and you want to have this fixed. I checked the additions and they seem reasonable. I suggested one little change.

Yes, you are correct about this change, good catch :) Will fix. I was hoping you could use reviewing this PR as an entry point to learning more about how the scheduler and tests work, but yes, I have a couple of things I also want to merge that I built on top of this because I wanted the test suite to be working :) So I'll go ahead and merge this now (with that fix).

I will put this into my task list and when I have some time I will go and explore this a bit more. I believe that learning where things are and how they really work is a very handy knowledge to have.

rebased onto e602c7f

5 years ago

Pull-Request has been merged by adamwill

5 years ago