diff --git a/tests/telemetry/test_telemetry.py b/tests/telemetry/test_telemetry.py index 71971aa..1bb29bd 100644 --- a/tests/telemetry/test_telemetry.py +++ b/tests/telemetry/test_telemetry.py @@ -383,7 +383,7 @@ def test_get_version_timeout(): assert total_runtime < datetime.timedelta(milliseconds=1500) -def write_to_conf_file(tmp_directory, monkeypatch, last_check): +def write_to_conf_file(tmp_directory, monkeypatch, last_check, last_cloud_check=None): stats = Path("stats") stats.mkdir() conf_path = stats / "config.yaml" @@ -392,6 +392,9 @@ def write_to_conf_file(tmp_directory, monkeypatch, last_check): conf_path.write_text("version_check_enabled: True\n") version_path.write_text(f"last_version_check: {last_check}\n") + if last_cloud_check: + version_path.write_text(f"last_cloud_check: {last_cloud_check}\n") + # force to reset data so we load from the data we just wrote monkeypatch.setattr(telemetry, "internal", telemetry.Internal()) @@ -1031,3 +1034,43 @@ def my_function(x, y, z): } assert my_function.__wrapped__._telemetry_error is None + + +@pytest.mark.parametrize( + "last_cloud_check", + [ + None, + "2022-01-20 10:51:41.082376", + ], + ids=[ + "first-time", + "not-first-time", + ], +) +def test_check_cloud(tmp_directory, monkeypatch, capsys, last_cloud_check): + write_to_conf_file( + tmp_directory=tmp_directory, + monkeypatch=monkeypatch, + last_check="2022-01-20 10:51:41.082376", + last_cloud_check=last_cloud_check, + ) + + now = datetime.datetime.now() + fake_datetime = Mock() + fake_datetime.now.return_value = now + + with monkeypatch.context() as m: + m.setattr(telemetry.datetime, "datetime", fake_datetime) + telemetry.check_cloud() + + config = yaml.safe_load(Path("stats", "uid.yaml").read_text()) + + captured = capsys.readouterr() + + expected = ( + "Deploy AI and data apps for free on Ploomber Cloud!" + " Sign up here: https://www.platform.ploomber.io/register" + ) + + assert expected in captured.out + assert config["last_cloud_check"] == now