def testTimestampDefaultsToNone(self): """Missing or unreadable timestamps return None.""" update_obj = updater.Updater(config.MAP_PASSWORD, self.workdir, {}) self.updater = update_obj update_stamp = update_obj.GetUpdateTimestamp() modify_stamp = update_obj.GetModifyTimestamp() self.assertEqual(None, update_stamp, msg='update time did not default to None') self.assertEqual(None, modify_stamp, msg='modify time did not default to None') # touch a file, make it unreadable update_file = open(update_obj.update_file, 'w') modify_file = open(update_obj.modify_file, 'w') update_file.close() modify_file.close() os.chmod(update_obj.update_file, 0000) os.chmod(update_obj.modify_file, 0000) update_stamp = update_obj.GetUpdateTimestamp() modify_stamp = update_obj.GetModifyTimestamp() self.assertEqual(None, update_stamp, msg='unreadable update time did not default to None') self.assertEqual(None, modify_stamp, msg='unreadable modify time did not default to None')
def testTimestampInTheFuture(self): """Timestamps in the future are turned into now.""" update_obj = updater.Updater(config.MAP_PASSWORD, self.workdir, {}) expected_time = 1 update_time = 3601 update_file = open(update_obj.update_file, 'w') update_obj.WriteUpdateTimestamp(update_time) self.mox.StubOutWithMock(update_obj, '_GetCurrentTime') update_obj._GetCurrentTime().AndReturn(expected_time) self.mox.ReplayAll() self.assertEqual(expected_time, update_obj.GetUpdateTimestamp())
def testTimestampDir(self): """We read and write timestamps to the specified directory.""" update_obj = updater.Updater(config.MAP_PASSWORD, self.workdir, {}) self.updater = updater update_time = 1199149400 modify_time = 1199149200 update_obj.WriteUpdateTimestamp(update_time) update_obj.WriteModifyTimestamp(modify_time) update_stamp = update_obj.GetUpdateTimestamp() modify_stamp = update_obj.GetModifyTimestamp() self.assertEqual( update_time, update_stamp, msg=('retrieved a different update time than we stored: ' 'Expected: %r, observed: %r' % (update_time, update_stamp))) self.assertEqual( modify_time, modify_stamp, msg=('retrieved a different modify time than we stored: ' 'Expected %r, observed: %r' % (modify_time, modify_stamp)))
def testWriteWhenTimestampIsNone(self): update_obj = updater.Updater(config.MAP_PASSWORD, self.workdir, {}) self.assertEqual(True, update_obj.WriteUpdateTimestamp(None)) self.assertEqual(True, update_obj.WriteModifyTimestamp(None))