Use assertRegex instead of assertRegexpMatches

In Python3, assertRegexpMatches & assertNotRegexpMatches
are deprecated in favor of assertRegex and assertNotRegex

Change-Id: I52b84fd49bed43902f0a57983710c0fb08649b12
This commit is contained in:
Vu Cong Tuan 2017-11-07 13:42:36 +07:00
parent e13f529621
commit 8b6260e10f
4 changed files with 46 additions and 48 deletions

View File

@ -161,18 +161,17 @@ class TestEmail(base.PluginTestCase):
email = _parse_email(self.trap.pop(0))
self.assertRegexpMatches(email['from'], 'hpcs.mon@hp.com')
self.assertRegexpMatches(email['to'], 'me@here.com')
self.assertRegexpMatches(email['raw'], 'Content-Type: text/plain')
self.assertRegexpMatches(email['raw'],
'Content-Transfer-Encoding: base64')
self.assertRegexpMatches(email['subject'],
'ALARM LOW "test Alarm .*" for Host: foo1.*')
self.assertRegexpMatches(email['body'], 'Alarm .test Alarm.')
self.assertRegexpMatches(email['body'], 'On host .foo1.')
self.assertRegexpMatches(email['body'], UNICODE_CHAR)
self.assertRegexpMatches(email['body'], 'Link: some-link')
self.assertRegexpMatches(email['body'], 'Lifecycle state: OPEN')
self.assertRegex(email['from'], 'hpcs.mon@hp.com')
self.assertRegex(email['to'], 'me@here.com')
self.assertRegex(email['raw'], 'Content-Type: text/plain')
self.assertRegex(email['raw'], 'Content-Transfer-Encoding: base64')
self.assertRegex(email['subject'],
'ALARM LOW "test Alarm .*" for Host: foo1.*')
self.assertRegex(email['body'], 'Alarm .test Alarm.')
self.assertRegex(email['body'], 'On host .foo1.')
self.assertRegex(email['body'], UNICODE_CHAR)
self.assertRegex(email['body'], 'Link: some-link')
self.assertRegex(email['body'], 'Lifecycle state: OPEN')
return_value = self.trap.pop(0)
self.assertTrue(return_value)
@ -191,16 +190,15 @@ class TestEmail(base.PluginTestCase):
email = _parse_email(self.trap.pop(0))
self.assertRegexpMatches(email['from'], 'hpcs.mon@hp.com')
self.assertRegexpMatches(email['to'], 'me@here.com')
self.assertRegexpMatches(email['raw'], 'Content-Type: text/plain')
self.assertRegexpMatches(email['raw'],
'Content-Transfer-Encoding: base64')
self.assertRegexpMatches(email['subject'],
'ALARM LOW .test Alarm.* Target: some_where')
self.assertRegexpMatches(email['body'], "Alarm .test Alarm.")
self.assertRegexpMatches(email['body'], "On host .foo1.")
self.assertRegexpMatches(email['body'], UNICODE_CHAR)
self.assertRegex(email['from'], 'hpcs.mon@hp.com')
self.assertRegex(email['to'], 'me@here.com')
self.assertRegex(email['raw'], 'Content-Type: text/plain')
self.assertRegex(email['raw'], 'Content-Transfer-Encoding: base64')
self.assertRegex(email['subject'],
'ALARM LOW .test Alarm.* Target: some_where')
self.assertRegex(email['body'], "Alarm .test Alarm.")
self.assertRegex(email['body'], "On host .foo1.")
self.assertRegex(email['body'], UNICODE_CHAR)
return_value = self.trap.pop(0)
self.assertTrue(return_value)
@ -219,15 +217,15 @@ class TestEmail(base.PluginTestCase):
email = _parse_email(self.trap.pop(0))
self.assertRegexpMatches(email['from'], "From: hpcs.mon@hp.com")
self.assertRegexpMatches(email['to'], "To: me@here.com")
self.assertRegexpMatches(email['raw'], "Content-Type: text/plain")
self.assertRegexpMatches(email['subject'], "Subject: ALARM LOW .test Alarm.")
self.assertRegexpMatches(email['body'], "Alarm .test Alarm.")
self.assertRegexpMatches(email['body'], "foo1")
self.assertRegexpMatches(email['body'], "foo2")
self.assertRegexpMatches(email['body'], "bar1")
self.assertRegexpMatches(email['body'], "bar2")
self.assertRegex(email['from'], "From: hpcs.mon@hp.com")
self.assertRegex(email['to'], "To: me@here.com")
self.assertRegex(email['raw'], "Content-Type: text/plain")
self.assertRegex(email['subject'], "Subject: ALARM LOW .test Alarm.")
self.assertRegex(email['body'], "Alarm .test Alarm.")
self.assertRegex(email['body'], "foo1")
self.assertRegex(email['body'], "foo2")
self.assertRegex(email['body'], "bar1")
self.assertRegex(email['body'], "bar2")
return_value = self.trap.pop(0)
self.assertTrue(return_value)

View File

@ -126,8 +126,8 @@ class TestNotificationProcessor(base.BaseTestCase):
for msg in self.trap:
if "From: hpcs.mon@hp.com" in msg:
self.assertRegexpMatches(msg, "From: hpcs.mon@hp.com")
self.assertRegexpMatches(msg, "To: me@here.com")
self.assertRegexpMatches(msg, "Content-Type: text/plain")
self.assertRegexpMatches(msg, "Alarm .test Alarm.")
self.assertRegexpMatches(msg, "On host .foo1.")
self.assertRegex(msg, "From: hpcs.mon@hp.com")
self.assertRegex(msg, "To: me@here.com")
self.assertRegex(msg, "Content-Type: text/plain")
self.assertRegex(msg, "Alarm .test Alarm.")
self.assertRegex(msg, "On host .foo1.")

View File

@ -134,9 +134,9 @@ class TestPagerduty(base.PluginTestCase):
self.assertEqual(details['message'], 'I am alarming!')
def pagerduty_http_error(self, log_msg, http_response):
self.assertRegexpMatches(log_msg, "Error with pagerduty request.")
self.assertRegexpMatches(log_msg, "key=<ABCDEF>")
self.assertRegexpMatches(log_msg, "response=%s" % http_response)
self.assertRegex(log_msg, "Error with pagerduty request.")
self.assertRegex(log_msg, "key=<ABCDEF>")
self.assertRegex(log_msg, "response=%s" % http_response)
@mock.patch('monasca_notification.plugins.pagerduty_notifier.requests')
def notify(self, http_func, mock_requests):
@ -277,8 +277,8 @@ class TestPagerduty(base.PluginTestCase):
results = self.trap.get(timeout=1)
self.assertRegexpMatches(results, "Exception on pagerduty request")
self.assertRegexpMatches(results, "key=<ABCDEF>")
self.assertRegex(results, "Exception on pagerduty request")
self.assertRegex(results, "key=<ABCDEF>")
return_value = self.trap.get()
self.assertFalse(return_value)

View File

@ -128,11 +128,11 @@ class TestWebhook(base.PluginTestCase):
error = self.trap.get()
self.assertNotRegexpMatches(error, "alarm_id.: .test Alarm")
self.assertNotRegexpMatches(error, "content-type.: .application/json")
self.assertNotRegex(error, "alarm_id.: .test Alarm")
self.assertNotRegex(error, "content-type.: .application/json")
self.assertRegexpMatches(error, "HTTP code 404")
self.assertRegexpMatches(error, "post on URL http://mock:3333/")
self.assertRegex(error, "HTTP code 404")
self.assertRegex(error, "post on URL http://mock:3333/")
return_value = self.trap.get()
self.assertFalse(return_value)
@ -150,10 +150,10 @@ class TestWebhook(base.PluginTestCase):
result = self.trap.get()
self.assertNotRegexpMatches(result, "alarm_id.: .test Alarm")
self.assertNotRegexpMatches(result, "content-type.: .application/json")
self.assertNotRegex(result, "alarm_id.: .test Alarm")
self.assertNotRegex(result, "content-type.: .application/json")
self.assertRegexpMatches(result, "Error trying to post on URL http://mock:3333/")
self.assertRegex(result, "Error trying to post on URL http://mock:3333/")
return_value = self.trap.get()
self.assertFalse(return_value)