Skip to content

Commit aafae99

Browse files
committed
πŸ› More bug fixes to offline Sender class tests
1 parent 0532f0c commit aafae99

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed

β€Žsimvue/api/objects/administrator/tenant.pyβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def new(
3030
max_runs: int = 0,
3131
max_data_volume: int = 0,
3232
offline: bool = False,
33+
**_,
3334
) -> Self:
3435
"""Create a new tenant on the Simvue server.
3536

β€Žsimvue/sender/actions.pyβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ def upload(
10671067
_ = simvue_monitor_run
10681068
_ = upload_status
10691069

1070-
_local_config: SimvueConfiguration = SimvueConfiguration.fetch()
1070+
_local_config: SimvueConfiguration = SimvueConfiguration.fetch(mode="online")
10711071

10721072
if not _local_config.metrics.enable_emission_metrics:
10731073
return

β€Žtests/functional/test_run_class.pyβ€Ž

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
import simvue
2222
from simvue.api.objects import Alert, Metrics
2323
from simvue.api.objects.grids import GridMetrics
24-
from simvue.eco.api_client import CO2SignalData, CO2SignalResponse
2524
from simvue.exception import ObjectNotFoundError, SimvueRunError
26-
from simvue.eco.emissions_monitor import TIME_FORMAT, CO2Monitor
2725
from simvue.sender import Sender
2826
import simvue.run as sv_run
2927
import simvue.client as sv_cl
@@ -1222,27 +1220,30 @@ def test_add_alerts_offline(monkeypatch) -> None:
12221220
rule="is inside range",
12231221
)
12241222

1225-
_id_mapping = sv_send.sender(os.environ["SIMVUE_OFFLINE_DIRECTORY"], 2, 10, throw_exceptions=True)
1226-
_online_run = RunObject(identifier=_id_mapping.get(run.id))
1223+
_sender = Sender(os.environ["SIMVUE_OFFLINE_DIRECTORY"], 2, 10, throw_exceptions=True)
1224+
_sender.upload()
1225+
_online_run = RunObject(identifier=_sender.id_mapping.get(run.id))
12271226

12281227
# Check that there is no duplication
1229-
assert sorted(_online_run.alerts) == sorted([_id_mapping.get(_id) for _id in _expected_alerts])
1228+
assert sorted(_online_run.alerts) == sorted([_sender.id_mapping.get(_id) for _id in _expected_alerts])
12301229

12311230
# Create another run without adding to run
12321231
_id = run.create_user_alert(name=f"user_alert_{_uuid}", attach_to_run=False)
1233-
_id_mapping = sv_send.sender(os.environ["SIMVUE_OFFLINE_DIRECTORY"], 2, 10, throw_exceptions=True)
1232+
_sender = Sender(os.environ["SIMVUE_OFFLINE_DIRECTORY"], 2, 10, throw_exceptions=True)
1233+
_sender.upload()
12341234

12351235
# Check alert is not added
12361236
_online_run.refresh()
1237-
assert sorted(_online_run.alerts) == sorted([_id_mapping.get(_id) for _id in _expected_alerts])
1237+
assert sorted(_online_run.alerts) == sorted([_sender.id_mapping.get(_id) for _id in _expected_alerts])
12381238

12391239
# Try adding alerts with IDs, check there is no duplication
12401240
_expected_alerts.append(_id)
12411241
run.add_alerts(ids=_expected_alerts)
1242-
_id_mapping = sv_send.sender(os.environ["SIMVUE_OFFLINE_DIRECTORY"], 2, 10, throw_exceptions=True)
1242+
_sender = Sender(os.environ["SIMVUE_OFFLINE_DIRECTORY"], 2, 10, throw_exceptions=True)
1243+
_sender.upload()
12431244

12441245
_online_run.refresh()
1245-
assert sorted(_online_run.alerts) == sorted([_id_mapping.get(_id) for _id in _expected_alerts])
1246+
assert sorted(_online_run.alerts) == sorted([_sender.id_mapping.get(_id) for _id in _expected_alerts])
12461247

12471248
run.close()
12481249

@@ -1253,7 +1254,7 @@ def test_add_alerts_offline(monkeypatch) -> None:
12531254
remove_runs=True,
12541255
recursive=True
12551256
)
1256-
for _id in [_id_mapping.get(_id) for _id in _expected_alerts]:
1257+
for _id in [_sender.id_mapping.get(_id) for _id in _expected_alerts]:
12571258
client.delete_alert(_id)
12581259

12591260

@@ -1478,7 +1479,6 @@ def test_reconnect_functionality(mode, monkeypatch: pytest.MonkeyPatch) -> None:
14781479
if mode == "offline":
14791480
_sender = Sender(cache_directory=os.environ["SIMVUE_OFFLINE_DIRECTORY"], max_workers=2, threading_threshold=10, throw_exceptions=True)
14801481
_sender.upload()
1481-
_id_mapping = _sender.id_mapping
14821482

14831483
_reconnected_run = client.get_run(run_id)
14841484
assert dict(_reconnected_run.metrics)["test_metric"]["last"] == 1

β€Žtests/unit/test_tag.pyβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_tag_modification_offline(offline_cache_setup) -> None:
7979

8080
assert _local_data.get("name") == f"test_tag_{_uuid}"
8181

82-
_sender = sender(_tag._local_staging_file.parents[1], 1, 10, throw_exceptions=True)
82+
_sender = Sender(_tag._local_staging_file.parents[1], 1, 10, throw_exceptions=True)
8383
_sender.upload(["tags"])
8484
_online_id = _sender.id_mapping.get(_tag.id)
8585
_online_tag = Tag(_online_id)

β€Žtests/unit/test_tenant.pyβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def test_create_tenant_offline(offline_cache_setup) -> None:
4040
assert _local_data.get("name") == _uuid
4141
assert _local_data.get("is_enabled") == True
4242

43-
_sender = Sender(_new_tenant._local_staging_file.parents[1], 1, 10, ["tenants"], throw_exceptions=True)
44-
_sender.upload()
43+
_sender = Sender(_new_tenant._local_staging_file.parents[1], 1, 10, throw_exceptions=True)
44+
_sender.upload(["tenants"])
4545
time.sleep(1)
4646
_online_user = Tenant(_sender.id_mapping.get(_new_tenant.id))
4747
assert _online_user.name == _uuid

0 commit comments

Comments
Β (0)