Exemple #1
0
 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())
Exemple #2
0
    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)
Exemple #3
0
    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()
Exemple #4
0
    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)