From 7eac89ff49f2aa4b2c05fdf75fd099b608a1657a Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Feb 18 2017 22:24:17 +0000 Subject: Use autospeccing in tests Signed-off-by: Adam Williamson --- diff --git a/test_relvalconsumer.py b/test_relvalconsumer.py index e855d57..a3820d7 100644 --- a/test_relvalconsumer.py +++ b/test_relvalconsumer.py @@ -91,17 +91,17 @@ def _fakegetcurr2(branched=False): # a bunch of patches we need throughout the tests # ALL SLEEPS MUST DIE -mock.patch('time.sleep').start() +mock.patch('time.sleep', autospec=True).start() # we have to stub this as we are skipping FedmsgConsumer __init__ -mock.patch('relvalconsumer.RelvalConsumer._log').start() +mock.patch('relvalconsumer.RelvalConsumer._log', autospec=True).start() # page init requires wiki trip mock.patch('mwclient.page.Page.__init__', _fakepginit).start() # testtypes are read from wiki mock.patch('wikitcms.wiki.Wiki.testtypes', ['Installation', 'Desktop', 'Server', 'Cloud', 'Base']).start() # login hits the wiki, obviously -mock.patch('wikitcms.wiki.Wiki.login').start() +mock.patch('wikitcms.wiki.Wiki.login', autospec=True).start() # so does site init -mock.patch('mwclient.client.Site.site_init').start() +mock.patch('mwclient.client.Site.site_init', autospec=True).start() # this we need to switch at Branch point, so name it. It hits the # 'collections' API. @@ -135,9 +135,9 @@ ATOMIC1 = 'Fedora-Atomic-25-20160725.1' # obviously we don't really want to create the event. we mock this # separately for each test, instead of just once, to make the call # asserts simple. -@mock.patch('wikitcms.event.ValidationEvent.create') +@mock.patch('wikitcms.event.ValidationEvent.create', autospec=True) # ditto sending emails. -@mock.patch('smtplib.SMTP') +@mock.patch('smtplib.SMTP', autospec=True) # this obviously hits mirrors; we have a couple of functions for faking # 'same' and 'different' package sets, for different tests @mock.patch('fedfind.release.Pungi4Release.get_package_nvras', _fakegetsame) @@ -152,10 +152,10 @@ ATOMIC1 = 'Fedora-Atomic-25-20160725.1' def test_rawhide1(fakesmtp, fakecreate): """Creating first Rawhide nightly for next release.""" CONSUMER.consume(_fakemsg(RAWHIDE1)) - fakecreate.assert_called_with(check=True) + assert fakecreate.call_args[1]['check'] is True -@mock.patch('wikitcms.event.ValidationEvent.create') -@mock.patch('smtplib.SMTP') +@mock.patch('wikitcms.event.ValidationEvent.create', autospec=True) +@mock.patch('smtplib.SMTP', autospec=True) @mock.patch('fedfind.release.Pungi4Release.get_package_nvras', _fakegetdifferent) @mock.patch('wikitcms.wiki.Wiki.current_event', wikitcms.event.NightlyEvent(None, '25', 'Rawhide', '20160601.n.0')) def test_rawhide2(fakesmtp, fakecreate): @@ -166,8 +166,8 @@ def test_rawhide2(fakesmtp, fakecreate): assert fakecreate.call_count == 0 assert fakesmtp.call_count == 0 -@mock.patch('wikitcms.event.ValidationEvent.create') -@mock.patch('smtplib.SMTP') +@mock.patch('wikitcms.event.ValidationEvent.create', autospec=True) +@mock.patch('smtplib.SMTP', autospec=True) @mock.patch('fedfind.release.Pungi4Release.get_package_nvras', _fakegetsame) @mock.patch('wikitcms.wiki.Wiki.current_event', wikitcms.event.NightlyEvent(None, '25', 'Rawhide', '20160601.n.0')) def test_rawhide3_same(fakesmtp, fakecreate): @@ -178,8 +178,8 @@ def test_rawhide3_same(fakesmtp, fakecreate): assert fakecreate.call_count == 0 assert fakesmtp.call_count == 0 -@mock.patch('wikitcms.event.ValidationEvent.create') -@mock.patch('smtplib.SMTP') +@mock.patch('wikitcms.event.ValidationEvent.create', autospec=True) +@mock.patch('smtplib.SMTP', autospec=True) @mock.patch('fedfind.release.Pungi4Release.get_package_nvras', _fakegetdifferent) @mock.patch('wikitcms.wiki.Wiki.current_event', wikitcms.event.NightlyEvent(None, '25', 'Rawhide', '20160601.n.0')) def test_rawhide3_different(fakesmtp, fakecreate): @@ -187,10 +187,10 @@ def test_rawhide3_different(fakesmtp, fakecreate): event if the packages are different. """ CONSUMER.consume(_fakemsg(RAWHIDE3)) - fakecreate.assert_called_with(check=True) + assert fakecreate.call_args[1]['check'] is True -@mock.patch('wikitcms.event.ValidationEvent.create') -@mock.patch('smtplib.SMTP') +@mock.patch('wikitcms.event.ValidationEvent.create', autospec=True) +@mock.patch('smtplib.SMTP', autospec=True) @mock.patch('fedfind.release.Pungi4Release.get_package_nvras', _fakegetsame) @mock.patch('wikitcms.wiki.Wiki.current_event', wikitcms.event.NightlyEvent(None, '25', 'Rawhide', '20160605.n.0')) def test_rawhide4(fakesmtp, fakecreate): @@ -198,12 +198,12 @@ def test_rawhide4(fakesmtp, fakecreate): even if the packages are the same. """ CONSUMER.consume(_fakemsg(RAWHIDE4)) - fakecreate.assert_called_with(check=True) + assert fakecreate.call_args[1]['check'] is True # BRANCH POINT -@mock.patch('wikitcms.event.ValidationEvent.create') -@mock.patch('smtplib.SMTP') +@mock.patch('wikitcms.event.ValidationEvent.create', autospec=True) +@mock.patch('smtplib.SMTP', autospec=True) @mock.patch('fedfind.release.Pungi4Release.get_package_nvras', _fakegetsame) @mock.patch('wikitcms.wiki.Wiki.current_event', wikitcms.event.NightlyEvent(None, '25', 'Rawhide', '20160620.n.0')) def test_branched1(fakesmtp, fakecreate): @@ -217,23 +217,23 @@ def test_branched1(fakesmtp, fakecreate): assert fakecreate.call_count == 0 assert fakesmtp.call_count == 0 -@mock.patch('wikitcms.event.ValidationEvent.create') -@mock.patch('smtplib.SMTP') +@mock.patch('wikitcms.event.ValidationEvent.create', autospec=True) +@mock.patch('smtplib.SMTP', autospec=True) @mock.patch('fedfind.release.Pungi4Release.get_package_nvras', _fakegetdifferent) @mock.patch('wikitcms.wiki.Wiki.current_event', wikitcms.event.NightlyEvent(None, '25', 'Rawhide', '20160620.n.0')) def test_branched2(fakesmtp, fakecreate): """Second branched compose some days later should create an event. """ CONSUMER.consume(_fakemsg(BRANCHED2)) - fakecreate.assert_called_with(check=True) + assert fakecreate.call_args[1]['check'] is True # this has to be mocked when the 'new' event is a production one; # to find the correct event from the compose ID, wikitcms gets a # Production instance from fedfind and checks its label property, # then parses that @mock.patch('fedfind.release.Production.label', 'Alpha-1.1') -@mock.patch('wikitcms.event.ValidationEvent.create') -@mock.patch('smtplib.SMTP') +@mock.patch('wikitcms.event.ValidationEvent.create', autospec=True) +@mock.patch('smtplib.SMTP', autospec=True) @mock.patch('fedfind.release.Pungi4Release.get_package_nvras', _fakegetsame) @mock.patch('wikitcms.wiki.Wiki.current_event', wikitcms.event.NightlyEvent(None, '25', 'Branched', '20160629.n.0')) def test_alpha1(fakesmtp, fakecreate): @@ -241,15 +241,15 @@ def test_alpha1(fakesmtp, fakecreate): for the same date and package set as BRANCHED2. """ CONSUMER.consume(_fakemsg(ALPHA1)) - fakecreate.assert_called_with(check=True) + assert fakecreate.call_args[1]['check'] is True # this has to be mocked whenever the current event is a candidate IDed # by milestone and compose; wikitcms asks fedfind for the compose for # the current event, fedfind will return a Compose if it exists. @mock.patch('fedfind.release.Compose.exists', return_value=True) @mock.patch('fedfind.release.Production.label', 'Alpha-1.2') -@mock.patch('wikitcms.event.ValidationEvent.create') -@mock.patch('smtplib.SMTP') +@mock.patch('wikitcms.event.ValidationEvent.create', autospec=True) +@mock.patch('smtplib.SMTP', autospec=True) @mock.patch('fedfind.release.Pungi4Release.get_package_nvras', _fakegetsame) @mock.patch('wikitcms.event.ComposeEvent.creation_date', '20160629') @mock.patch('wikitcms.wiki.Wiki.current_event', wikitcms.event.ComposeEvent(None, '25', 'Alpha', '1.1')) @@ -259,11 +259,11 @@ def test_alpha2(fakesmtp, fakecreate, fakecompexists): but it's what ought to happen). """ CONSUMER.consume(_fakemsg(ALPHA2)) - fakecreate.assert_called_with(check=True) + assert fakecreate.call_args[1]['check'] is True @mock.patch('fedfind.release.Compose.exists', return_value=True) -@mock.patch('wikitcms.event.ValidationEvent.create') -@mock.patch('smtplib.SMTP') +@mock.patch('wikitcms.event.ValidationEvent.create', autospec=True) +@mock.patch('smtplib.SMTP', autospec=True) @mock.patch('fedfind.release.Pungi4Release.get_package_nvras', _fakegetdifferent) @mock.patch('wikitcms.event.ComposeEvent.creation_date', '20160629') @mock.patch('wikitcms.wiki.Wiki.current_event', wikitcms.event.ComposeEvent(None, '25', 'Alpha', '1.2')) @@ -276,8 +276,8 @@ def test_branched3(fakesmtp, fakecreate, fakecompexists): assert fakesmtp.call_count == 0 @mock.patch('fedfind.release.Compose.exists', return_value=True) -@mock.patch('wikitcms.event.ValidationEvent.create') -@mock.patch('smtplib.SMTP') +@mock.patch('wikitcms.event.ValidationEvent.create', autospec=True) +@mock.patch('smtplib.SMTP', autospec=True) @mock.patch('fedfind.release.Pungi4Release.get_package_nvras', _fakegetsame) @mock.patch('wikitcms.event.ComposeEvent.creation_date', '20160629') @mock.patch('wikitcms.wiki.Wiki.current_event', wikitcms.event.ComposeEvent(None, '25', 'Alpha', '1.2')) @@ -290,8 +290,8 @@ def test_branched4_same(fakesmtp, fakecreate, fakecompexists): assert fakesmtp.call_count == 0 @mock.patch('fedfind.release.Compose.exists', return_value=True) -@mock.patch('wikitcms.event.ValidationEvent.create') -@mock.patch('smtplib.SMTP') +@mock.patch('wikitcms.event.ValidationEvent.create', autospec=True) +@mock.patch('smtplib.SMTP', autospec=True) @mock.patch('fedfind.release.Pungi4Release.get_package_nvras', _fakegetolder) @mock.patch('wikitcms.event.ComposeEvent.creation_date', '20160629') @mock.patch('wikitcms.wiki.Wiki.current_event', wikitcms.event.ComposeEvent(None, '25', 'Alpha', '1.2')) @@ -304,8 +304,8 @@ def test_branched4_older(fakesmtp, fakecreate, fakecompexists): assert fakesmtp.call_count == 0 @mock.patch('fedfind.release.Compose.exists', return_value=True) -@mock.patch('wikitcms.event.ValidationEvent.create') -@mock.patch('smtplib.SMTP') +@mock.patch('wikitcms.event.ValidationEvent.create', autospec=True) +@mock.patch('smtplib.SMTP', autospec=True) @mock.patch('fedfind.release.Pungi4Release.get_package_nvras', _fakegetdifferent) @mock.patch('wikitcms.event.ComposeEvent.creation_date', '20160629') @mock.patch('wikitcms.wiki.Wiki.current_event', wikitcms.event.ComposeEvent(None, '25', 'Alpha', '1.2')) @@ -314,11 +314,11 @@ def test_branched4_newer(fakesmtp, fakecreate, fakecompexists): packages should create event. """ CONSUMER.consume(_fakemsg(BRANCHED4)) - fakecreate.assert_called_with(check=True) + assert fakecreate.call_args[1]['check'] is True @mock.patch('fedfind.release.Production.label', 'Alpha-1.3') -@mock.patch('wikitcms.event.ValidationEvent.create') -@mock.patch('smtplib.SMTP') +@mock.patch('wikitcms.event.ValidationEvent.create', autospec=True) +@mock.patch('smtplib.SMTP', autospec=True) @mock.patch('fedfind.release.Pungi4Release.get_package_nvras', _fakegetdifferent) @mock.patch('wikitcms.wiki.Wiki.current_event', wikitcms.event.NightlyEvent(None, '25', 'Branched', '20160705.n.0')) def test_alpha3(fakesmtp, fakecreate): @@ -326,11 +326,11 @@ def test_alpha3(fakesmtp, fakecreate): even though it's only been one day. """ CONSUMER.consume(_fakemsg(ALPHA3)) - fakecreate.assert_called_with(check=True) + assert fakecreate.call_args[1]['check'] is True @mock.patch('fedfind.release.Compose.exists', return_value=True) -@mock.patch('wikitcms.event.ValidationEvent.create') -@mock.patch('smtplib.SMTP') +@mock.patch('wikitcms.event.ValidationEvent.create', autospec=True) +@mock.patch('smtplib.SMTP', autospec=True) @mock.patch('fedfind.release.Pungi4Release.get_package_nvras', _fakegetdifferent) @mock.patch('wikitcms.event.ComposeEvent.creation_date', '20160706') @mock.patch('wikitcms.wiki.Wiki.current_event', wikitcms.event.ComposeEvent(None, '25', 'Alpha', '1.3')) @@ -341,10 +341,10 @@ def test_branched5(fakesmtp, fakecreate, fakecompexists): here. """ CONSUMER.consume(_fakemsg(BRANCHED5)) - fakecreate.assert_called_with(check=True) + assert fakecreate.call_args[1]['check'] is True -@mock.patch('wikitcms.event.ValidationEvent.create') -@mock.patch('smtplib.SMTP') +@mock.patch('wikitcms.event.ValidationEvent.create', autospec=True) +@mock.patch('smtplib.SMTP', autospec=True) @mock.patch('fedfind.release.Pungi4Release.get_package_nvras', _fakegetdifferent) @mock.patch('wikitcms.wiki.Wiki.current_event', wikitcms.event.NightlyEvent(None, '25', 'Branched', '20160710.n.0')) def test_rawhide5(fakesmtp, fakecreate): @@ -358,19 +358,19 @@ def test_rawhide5(fakesmtp, fakecreate): assert fakesmtp.call_count == 0 @mock.patch('fedfind.release.Production.label', 'Beta-1.1') -@mock.patch('wikitcms.event.ValidationEvent.create') -@mock.patch('smtplib.SMTP') +@mock.patch('wikitcms.event.ValidationEvent.create', autospec=True) +@mock.patch('smtplib.SMTP', autospec=True) @mock.patch('fedfind.release.Pungi4Release.get_package_nvras', _fakegetdifferent) @mock.patch('wikitcms.wiki.Wiki.current_event', wikitcms.event.NightlyEvent(None, '25', 'Branched', '20160710.n.0')) def test_beta1(fakesmtp, fakecreate): """OK, here comes Beta. We should get an event, of course.""" CONSUMER.consume(_fakemsg(BETA1)) - fakecreate.assert_called_with(check=True) + assert fakecreate.call_args[1]['check'] is True @mock.patch('fedfind.release.Production.label', 'RC-1.1') @mock.patch('fedfind.release.Compose.exists', return_value=True) -@mock.patch('wikitcms.event.ValidationEvent.create') -@mock.patch('smtplib.SMTP') +@mock.patch('wikitcms.event.ValidationEvent.create', autospec=True) +@mock.patch('smtplib.SMTP', autospec=True) @mock.patch('fedfind.release.Pungi4Release.get_package_nvras', _fakegetdifferent) @mock.patch('wikitcms.event.ComposeEvent.creation_date', '20160714') @mock.patch('wikitcms.wiki.Wiki.current_event', wikitcms.event.ComposeEvent(None, '25', 'Beta', '1.1')) @@ -380,12 +380,13 @@ def test_final1(fakesmtp, fakecreate, fakecompexists): this is unlikely ever to happen. We should get an event. """ CONSUMER.consume(_fakemsg(FINAL1)) - fakecreate.assert_called_with(check=True) + #assert fakecreate.call_args[1]['check'] is True + assert fakecreate.call_args[1]['check'] is True @mock.patch('fedfind.release.Production.label', 'RC-20161120.0') @mock.patch('fedfind.release.Compose.exists', return_value=True) -@mock.patch('wikitcms.event.ValidationEvent.create') -@mock.patch('smtplib.SMTP') +@mock.patch('wikitcms.event.ValidationEvent.create', autospec=True) +@mock.patch('smtplib.SMTP', autospec=True) @mock.patch('fedfind.release.Pungi4Release.get_package_nvras', _fakegetdifferent) @mock.patch('wikitcms.event.ComposeEvent.creation_date', '20160721') @mock.patch('wikitcms.wiki.Wiki.current_event', wikitcms.event.ComposeEvent(None, '25', 'RC', '1.1'))