Ejemplo n.º 1
0
 def test_datetime_or_none(self):
     naive_dt = datetime.datetime.now()
     dt = timeutils.parse_isotime(timeutils.isotime(naive_dt))
     self.assertEqual(utils.datetime_or_none(dt), dt)
     self.assertEqual(utils.datetime_or_none(dt), naive_dt.replace(tzinfo=iso8601.iso8601.Utc(), microsecond=0))
     self.assertIsNone(utils.datetime_or_none(None))
     self.assertRaises(ValueError, utils.datetime_or_none, "foo")
Ejemplo n.º 2
0
 def test_datetime_or_none(self):
     naive_dt = datetime.datetime.now()
     dt = timeutils.parse_isotime(timeutils.isotime(naive_dt))
     self.assertEqual(utils.datetime_or_none(dt), dt)
     self.assertEqual(utils.datetime_or_none(dt),
                      naive_dt.replace(tzinfo=iso8601.iso8601.Utc(),
                                       microsecond=0))
     self.assertIsNone(utils.datetime_or_none(None))
     self.assertRaises(ValueError, utils.datetime_or_none, 'foo')
Ejemplo n.º 3
0
 def test_refresh(self):
     host = self.fake_conductor["hostname"]
     t0 = self.fake_conductor["updated_at"]
     t1 = t0 + datetime.timedelta(seconds=10)
     returns = [dict(self.fake_conductor, updated_at=t0), dict(self.fake_conductor, updated_at=t1)]
     expected = [mock.call(host), mock.call(host)]
     with mock.patch.object(self.dbapi, "get_conductor", side_effect=returns, autospec=True) as mock_get_cdr:
         c = objects.Conductor.get_by_hostname(self.context, host)
         # ensure timestamps have tzinfo
         self.assertEqual(c.updated_at, obj_utils.datetime_or_none(t0))
         c.refresh()
         self.assertEqual(c.updated_at, obj_utils.datetime_or_none(t1))
         self.assertEqual(mock_get_cdr.call_args_list, expected)
Ejemplo n.º 4
0
 def test_refresh(self):
     host = self.fake_conductor['hostname']
     t0 = self.fake_conductor['updated_at']
     t1 = t0 + datetime.timedelta(seconds=10)
     returns = [dict(self.fake_conductor, updated_at=t0),
                dict(self.fake_conductor, updated_at=t1)]
     expected = [mock.call(host), mock.call(host)]
     with mock.patch.object(self.dbapi, 'get_conductor',
                            side_effect=returns,
                            autospec=True) as mock_get_cdr:
         c = objects.Conductor.get_by_hostname(self.context, host)
         # ensure timestamps have tzinfo
         self.assertEqual(obj_utils.datetime_or_none(t0), c.updated_at)
         c.refresh()
         self.assertEqual(obj_utils.datetime_or_none(t1), c.updated_at)
         self.assertEqual(expected, mock_get_cdr.call_args_list)
Ejemplo n.º 5
0
 def test_datetime_or_none(self):
     dt = datetime.datetime.now()
     self.assertEqual(utils.datetime_or_none(dt), dt)
     self.assertEqual(utils.datetime_or_none(None), None)
     self.assertRaises(ValueError, utils.datetime_or_none, 'foo')