Skip to content
This repository has been archived by the owner on Jul 9, 2019. It is now read-only.

Commit

Permalink
Add assertions and remove unneeded test
Browse files Browse the repository at this point in the history
  • Loading branch information
Rick van den Hof committed Feb 22, 2019
1 parent 53eb2e2 commit b4a22e8
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions tests/helpers/TestHeartBeatListener.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ def test_succeeded(self):
heartbeat_event_mock.connection_id = "host-1", "27017"

heartbeat_logger.succeeded(event=heartbeat_event_mock)
self.assertFalse(self._onAllHostsReadyCallback.called)

heartbeat_event_mock.connection_id = "host-2", "27017"
heartbeat_logger.succeeded(event=heartbeat_event_mock)
self.assertFalse(self._onAllHostsReadyCallback.called)

heartbeat_event_mock.connection_id = "host-3", "27017"
heartbeat_logger.succeeded(event=heartbeat_event_mock)
self.assertFalse(self._onAllHostsReadyCallback.called)

heartbeat_event_mock.reply.document = {"info": ""}
heartbeat_event_mock.connection_id = "host-1", "27017"
Expand All @@ -45,26 +49,16 @@ def test_succeeded(self):

self._onAllHostsReadyCallback.assert_called_once_with(self.cluster_object)

def test_succeeded_invalid_replicaSet(self):
heartbeat_logger = HeartbeatListener(self.cluster_object,
all_hosts_ready_callback=self._onAllHostsReadyCallback)

# Fake two already successful hosts
heartbeat_logger._hosts_status = {"foo": 1, "bar": 1}

# Call it with invalid replicaSet configuration
heartbeat_event_mock = MagicMock(spec=ServerHeartbeatSucceededEvent)
heartbeat_event_mock.reply.document = {"info": "Does not have a valid replica set config"}
heartbeat_logger.succeeded(event=heartbeat_event_mock)

def test_succeeded_already_called(self):
heartbeat_logger = HeartbeatListener(self.cluster_object,
all_hosts_ready_callback=self._onAllHostsReadyCallback)

heartbeat_logger._callback_executed = True
heartbeat_logger.succeeded(event=MagicMock())
self.assertFalse(self._onAllHostsReadyCallback.called)

def test_failed(self):
heartbeat_logger = HeartbeatListener(self.cluster_object,
all_hosts_ready_callback=self._onAllHostsReadyCallback)
heartbeat_logger.failed(event=Mock(spec=ServerHeartbeatFailedEvent))
self.assertFalse(self._onAllHostsReadyCallback.called)

0 comments on commit b4a22e8

Please sign in to comment.