fix the post event without time argument
* make sure that the test uses the current time if time is not provided Change-Id: I9aac4906ed4629c9730c012a2382657335a78d18
This commit is contained in:
parent
e50d0f0dc2
commit
614c531247
@ -16,6 +16,7 @@ from argparse import ArgumentParser
|
||||
from argparse import ArgumentTypeError
|
||||
|
||||
# noinspection PyPackageRequirements
|
||||
from datetime import datetime
|
||||
import mock
|
||||
from testtools import ExpectedException
|
||||
|
||||
@ -28,7 +29,8 @@ class EventPostTest(CliTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(EventPostTest, self).setUp()
|
||||
self.event_post = EventPost(mock.Mock(), mock.Mock())
|
||||
self.app = mock.Mock()
|
||||
self.event_post = EventPost(self.app, mock.Mock())
|
||||
|
||||
def test_parsing_iso8601_with_not_a_date_string(self):
|
||||
self.assertRaises(ArgumentTypeError, self.event_post.iso8601, 'bla')
|
||||
@ -52,13 +54,6 @@ class EventPostTest(CliTestCase):
|
||||
'--time', '-5',
|
||||
'--details', 'blabla'])
|
||||
|
||||
@mock.patch.object(ArgumentParser, "error")
|
||||
def test_parser_event_post_without_time(self, mock_parser):
|
||||
mock_parser.side_effect = self._my_parser_error_func
|
||||
parser = self.event_post.get_parser('vitrage event post')
|
||||
|
||||
parser.parse_args(args=['--type', 'bla', '--details', 'blabla'])
|
||||
|
||||
@mock.patch.object(ArgumentParser, "error")
|
||||
def test_parser_event_post_type_required(self, mock_parser):
|
||||
mock_parser.side_effect = self._my_parser_error_func
|
||||
@ -67,3 +62,20 @@ class EventPostTest(CliTestCase):
|
||||
# noinspection PyCallByClass
|
||||
with ExpectedException(ArgumentTypeError, r'.*--type'):
|
||||
parser.parse_args(args=['--details', 'blabla'])
|
||||
|
||||
@mock.patch('vitrageclient.v1.cli.event.datetime')
|
||||
def test_parser_event_post_without_time_uses_time_now(self, dt_mock):
|
||||
current_time = datetime.now()
|
||||
dt_mock.now.return_value = current_time
|
||||
iso_time = current_time.isoformat()
|
||||
parser = self.event_post.get_parser('vitrage event post')
|
||||
args = parser.parse_args(args=['--type', 'bla',
|
||||
'--details', '{"blabla":[]}'
|
||||
])
|
||||
|
||||
with mock.patch.object(self.app.client.event, 'post') as poster_mock:
|
||||
self.event_post.take_action(args)
|
||||
|
||||
poster_mock.assert_called_with(event_time=iso_time,
|
||||
details={'blabla': []},
|
||||
event_type='bla')
|
||||
|
Loading…
Reference in New Issue
Block a user