|
| 1 | +from datetime import datetime, timezone |
1 | 2 | from pathlib import Path |
2 | 3 |
|
3 | 4 | import pytest |
4 | 5 | import respx |
| 6 | +import time_machine |
5 | 7 | from httpx import Response |
6 | 8 | from typer.testing import CliRunner |
7 | 9 |
|
|
14 | 16 | assets_path = Path(__file__).parent / "assets" |
15 | 17 |
|
16 | 18 |
|
| 19 | +def _normalize_output(output: str) -> str: |
| 20 | + return "\n".join(line.rstrip() for line in output.strip("\n").splitlines()) |
| 21 | + |
| 22 | + |
17 | 23 | def test_shows_a_message_if_not_logged_in(logged_out_cli: None) -> None: |
18 | 24 | result = runner.invoke(app, ["env", "list"]) |
19 | 25 |
|
@@ -85,6 +91,83 @@ def test_shows_environment_variables_names( |
85 | 91 | assert "API_KEY" in result.output |
86 | 92 |
|
87 | 93 |
|
| 94 | +@pytest.mark.respx |
| 95 | +@time_machine.travel(datetime(2026, 5, 22, 12, 0, tzinfo=timezone.utc), tick=False) |
| 96 | +def test_shows_environment_variables_in_compact_table( |
| 97 | + logged_in_cli: None, respx_mock: respx.MockRouter, configured_app: ConfiguredApp |
| 98 | +) -> None: |
| 99 | + respx_mock.get(f"/apps/{configured_app.app_id}/environment-variables/").mock( |
| 100 | + return_value=Response( |
| 101 | + 200, |
| 102 | + json={ |
| 103 | + "data": [ |
| 104 | + { |
| 105 | + "name": "APP_URL", |
| 106 | + "value": "https://tryshot.app", |
| 107 | + "updated_at": "2026-05-10T12:00:00Z", |
| 108 | + }, |
| 109 | + { |
| 110 | + "name": "SENTRY_ENVIRONMENT", |
| 111 | + "value": "production", |
| 112 | + "updated_at": "2026-03-22T12:00:00Z", |
| 113 | + }, |
| 114 | + ] |
| 115 | + }, |
| 116 | + ) |
| 117 | + ) |
| 118 | + |
| 119 | + with changing_dir(configured_app.path): |
| 120 | + result = runner.invoke(app, ["env", "list"]) |
| 121 | + |
| 122 | + assert result.exit_code == 0 |
| 123 | + assert _normalize_output(result.output) == ( |
| 124 | + "Key Value Last updated\n" |
| 125 | + "───────────────────────────────────────────────────────\n" |
| 126 | + "APP_URL https://tryshot.app 12 days ago\n" |
| 127 | + "SENTRY_ENVIRONMENT production 2 months ago" |
| 128 | + ) |
| 129 | + |
| 130 | + |
| 131 | +@pytest.mark.respx |
| 132 | +@time_machine.travel(datetime(2026, 5, 22, 12, 0, tzinfo=timezone.utc), tick=False) |
| 133 | +def test_truncates_values_and_marks_secrets_in_compact_table( |
| 134 | + logged_in_cli: None, respx_mock: respx.MockRouter, configured_app: ConfiguredApp |
| 135 | +) -> None: |
| 136 | + long_value = "12345678901234567890123456789012345678901234567890" |
| 137 | + |
| 138 | + respx_mock.get(f"/apps/{configured_app.app_id}/environment-variables/").mock( |
| 139 | + return_value=Response( |
| 140 | + 200, |
| 141 | + json={ |
| 142 | + "data": [ |
| 143 | + { |
| 144 | + "name": "LONG_VALUE", |
| 145 | + "value": long_value, |
| 146 | + "updated_at": "2026-03-22T12:00:00Z", |
| 147 | + }, |
| 148 | + { |
| 149 | + "name": "SECRET_KEY", |
| 150 | + "is_secret": True, |
| 151 | + "updated_at": "2026-04-22T12:00:00Z", |
| 152 | + }, |
| 153 | + ] |
| 154 | + }, |
| 155 | + ) |
| 156 | + ) |
| 157 | + |
| 158 | + with changing_dir(configured_app.path): |
| 159 | + result = runner.invoke(app, ["env", "list"]) |
| 160 | + |
| 161 | + assert result.exit_code == 0 |
| 162 | + assert _normalize_output(result.output) == ( |
| 163 | + "Key Value Last updated\n" |
| 164 | + "────────────────────────────────────────────────────────────────────\n" |
| 165 | + "LONG_VALUE 1234567890123456789012345678901234567... 2 months ago\n" |
| 166 | + "SECRET_KEY [secret] 1 month ago" |
| 167 | + ) |
| 168 | + assert long_value not in result.output |
| 169 | + |
| 170 | + |
88 | 171 | @pytest.mark.respx |
89 | 172 | def test_shows_secret_environment_variables_without_value( |
90 | 173 | logged_in_cli: None, respx_mock: respx.MockRouter, configured_app: ConfiguredApp |
|
0 commit comments