def datetime(value): try: return parse_datetime(value) except errors.Error: import argparse raise argparse.ArgumentTypeError( '{} is not a valid date/time'.format(value), )
def test_5m_ago(self): with mock.patch("touchdown.core.datetime.datetime") as mock_dt: mock_dt.utcnow.return_value = datetime.datetime(2015, 5, 25, 14, 23, 46, 890132) mock_dt.side_effect = datetime.datetime.now() self.assertEqual( parse_datetime("5m ago"), datetime.datetime(2015, 5, 25, 14, 18, 46, 890132, tzinfo=utc) )
def check(self, target): self.old_db_name = '{}-{:%Y%m%d%H%M%S}'.format(self.resource.name, now()) self.db = self.get_database(self.resource.name) if not self.db: raise errors.Error('Database {} not found?'.format(self.resource.name)) if self.get_database(self.old_db_name): raise errors.Error('Database {} already exists - restore in progress?'.format(self.old_db_name)) self.datetime_target = None try: self.datetime_target = parse_datetime(target) self.check_point_in_time(self.db, self.datetime_target) except errors.Error: self.check_snapshot(self.db, target)