def test_is_open(self): url = 'test-url' sender = Sender(url) sender.connection = Mock() sender.connection.is_open.return_value = False # closed self.assertFalse(sender.is_open()) # open sender.connection = Mock() sender.connection.is_open.return_value = True self.assertTrue(sender.is_open())
def test_open_already(self): url = 'test-url' # test sender = Sender(url) sender.is_open = Mock(return_value=True) sender.open() # validation self.assertFalse(sender.connection.open.called)
def test_open(self, connection): url = 'test-url' # test sender = Sender(url) sender.is_open = Mock(return_value=False) sender.open() # validation connection.return_value.open.assert_called_once_with()
def test_close(self): connection = Mock() connection.close.side_effect = ValueError # test sender = Sender(None) sender.connection = connection sender.is_open = Mock(return_value=True) sender.close() # validation self.assertFalse(connection.close.called)