def setup(self): with patch("bddbot.bank.ServerProxy") as mocked_proxy_class: self.bank = RemoteBank(CLIENT, HOST, PORT) mocked_proxy_class.assert_called_once_with("http://{}:{:d}".format(HOST, PORT)) self.mocked_proxy = mocked_proxy_class.return_value
class TestRemoteBank(object): """Test connection to a remote bank.""" def __init__(self): self.bank = None self.mocked_proxy = None def setup(self): with patch("bddbot.bank.ServerProxy") as mocked_proxy_class: self.bank = RemoteBank(CLIENT, HOST, PORT) mocked_proxy_class.assert_called_once_with("http://{}:{:d}".format(HOST, PORT)) self.mocked_proxy = mocked_proxy_class.return_value def test_access(self): self.bank.is_fresh() self.mocked_proxy.is_fresh.assert_called_once_with(CLIENT) self.bank.is_done() self.mocked_proxy.is_done.assert_called_once_with(CLIENT) _ = self.bank.output_path self.mocked_proxy.get_output_path.assert_called_once_with(CLIENT) _ = self.bank.header self.mocked_proxy.get_header.assert_called_once_with(CLIENT) _ = self.bank.feature self.mocked_proxy.get_feature.assert_called_once_with(CLIENT) self.bank.get_next_scenario() self.mocked_proxy.get_next_scenario.assert_called_once_with(CLIENT) def test_access_error(self): self.mocked_proxy.is_fresh.side_effect = socket.error() with assert_raises(ConnectionError): self.bank.is_fresh() self.mocked_proxy.is_done.side_effect = socket.error() with assert_raises(ConnectionError): self.bank.is_done() self.mocked_proxy.get_output_path.side_effect = socket.error() with assert_raises(ConnectionError): _ = self.bank.output_path self.mocked_proxy.get_header.side_effect = socket.error() with assert_raises(ConnectionError): _ = self.bank.header self.mocked_proxy.get_feature.side_effect = socket.error() with assert_raises(ConnectionError): _ = self.bank.feature self.mocked_proxy.get_next_scenario.side_effect = socket.error() with assert_raises(ConnectionError): self.bank.get_next_scenario() def test_operation_error(self): self.mocked_proxy.is_fresh.side_effect = socket.error() with assert_raises(ConnectionError) as error_context: self.bank.is_fresh() assert_in("failed on remote", error_context.exception.message.lower()) assert_equal("is_fresh", error_context.exception.operation)