Skip to content

Commit

Permalink
Added some sanity checks to tests #1714
Browse files Browse the repository at this point in the history
  • Loading branch information
dennissiemensma committed Sep 29, 2022
1 parent f8af61a commit 79a87d7
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions dsmr_mqtt/tests/services/test_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ def test_run_cleanup(self, publish_mock, loop_mock):
self.assertEqual(publish_mock.call_count, MAX)

# We assert that the LAST X messages were sent, rest is deleted.
for x in range(MAX + 1, MAX * 2 + 1):
LOWEST_PAYLOAD = MAX + 1
HIGHEST_PAYLOAD = MAX * 2

for x in range(LOWEST_PAYLOAD, HIGHEST_PAYLOAD + 1):
publish_mock.assert_any_call(topic="z", payload=str(x), qos=2, retain=True)

self.assertFalse(queue.Message.objects.exists())
Expand All @@ -179,9 +182,13 @@ def test_run_cleanup(self, publish_mock, loop_mock):

for current_call in publish_mock.call_args_list:
current_call_payload = int(current_call[1]["payload"])
self.assertGreater(
current_call_payload, previous_payload
) # Possible issues with queue order

# For our sanity and to ensure the right ones are deleted.
self.assertGreaterEqual(current_call_payload, LOWEST_PAYLOAD)
self.assertLessEqual(current_call_payload, HIGHEST_PAYLOAD)

# Fails? Possible issues with queue order.
self.assertGreater(current_call_payload, previous_payload)
previous_payload = current_call_payload

@mock.patch("paho.mqtt.client.Client.publish")
Expand Down

0 comments on commit 79a87d7

Please sign in to comment.