def test__log_event_logs_correctly(self, mock_gettext, mock__logger): event_info = {'timestamp': 1449260644.097711, 'local_received': 1449260669.830475, 'type': 'fake-type', 'hostname': 'fake-worker'} worker_watcher._parse_and_log_event(event_info) log_string = ("'%(type)s' sent at time %(timestamp)s from %(worker_name)s, received at " "time: %(local_received)s") mock_gettext.assert_called_with(log_string) mock__logger.assert_called_once()
def test__parse_and_log_event(self, mock__log_event, mock_datetime): event = { 'timestamp': mock.Mock(), 'type': mock.Mock(), 'hostname': mock.Mock() } result = worker_watcher._parse_and_log_event(event) # assert that the timestamp got converted using utcfromtimestamp() mock_datetime.utcfromtimestamp.assert_called_once_with( event['timestamp']) # assert that the resul dictionary has the right keys self.assertTrue('timestamp' in result) self.assertTrue('type' in result) self.assertTrue('worker_name' in result) # assert that the values in the resul dictionary are right self.assertTrue( result['timestamp'] is mock_datetime.utcfromtimestamp.return_value) self.assertTrue(result['type'] is event['type']) self.assertTrue(result['worker_name'] is event['hostname']) # assert that the event info is passed to _log_event mock__log_event.assert_called_once_with(result)
def test__parse_and_log_event(self): event = {'timestamp': 1449260644.097711, 'local_received': 1449260669.830475, 'type': 'fake-type', 'hostname': 'fake-worker'} result = worker_watcher._parse_and_log_event(event) # assert that the values in the result dictionary are right self.assertEqual(result['timestamp'], datetime.datetime.utcfromtimestamp(1449260644.097711)) self.assertEqual(result['local_received'], datetime.datetime.utcfromtimestamp(1449260669.830475)) self.assertTrue(result['type'] is event['type']) self.assertTrue(result['worker_name'] is event['hostname'])
def test__parse_and_log_event(self, mock__log_event, mock_datetime): event = {'timestamp': mock.Mock(), 'type': mock.Mock(), 'hostname': mock.Mock()} result = worker_watcher._parse_and_log_event(event) # assert that the timestamp got converted using utcfromtimestamp() mock_datetime.utcfromtimestamp.assert_called_once_with(event['timestamp']) # assert that the resul dictionary has the right keys self.assertTrue('timestamp' in result) self.assertTrue('type' in result) self.assertTrue('worker_name' in result) # assert that the values in the resul dictionary are right self.assertTrue(result['timestamp'] is mock_datetime.utcfromtimestamp.return_value) self.assertTrue(result['type'] is event['type']) self.assertTrue(result['worker_name'] is event['hostname']) # assert that the event info is passed to _log_event mock__log_event.assert_called_once_with(result)