def test_already_checked_today(self, message): now = datetime.now() store.set_last_version_check(now) store.set_update_available(None) check() assert store.get_last_version_check() == now assert store.get_update_available() is None assert not message.called
def test_update_available(self, message, current_version, latest_version): current_version.return_value = Version('1.8.0') latest_version.return_value = Version('1.9.0') two_days_ago = datetime.now() - timedelta(days=2) store.set_last_version_check(two_days_ago) store.set_update_available(None) check() assert store.get_last_version_check() > two_days_ago assert store.get_update_available() == Version('1.9.0') assert message.called
def test_update_found_previously_and_already_checked_today( self, message, current_version, latest_version): current_version.return_value = Version('1.8.0') latest_version.return_value = Version('1.10.0') now = datetime.now() store.set_last_version_check(now) store.set_update_available(Version('1.9.0')) check() assert store.get_last_version_check() == now assert store.get_update_available() == Version('1.9.0') assert message.called
def test_update_found_previously_and_just_updated(self, message, current_version, latest_version): current_version.return_value = Version('1.9.0') latest_version.return_value = Version('1.9.0') now = datetime.now() store.set_last_version_check(now) store.set_update_available(Version('1.9.0')) check() assert store.get_last_version_check() == now assert store.get_update_available() is None assert not message.called
def check(): """ Checks if a new version is available. Checks once every 8 hours at most. If a new version is available, a message will be shown for every executed command until the update has been installed. """ current = _current_version() if datetime.now() - timedelta(hours=8) > store.get_last_version_check(): latest = _latest_version() if latest and latest > current: store.set_update_available(latest) store.set_last_version_check(datetime.now()) latest = store.get_update_available() if latest: if latest <= current: # an upgrade has just been done store.set_update_available(None) else: _show_update_message(current, latest)