Ejemplo n.º 1
0
 def test_switch_complete_bootstrap_calls_bootstrap_completed_callbacks(self):
     s = Switch(seed_ipp=faripp)
     s.send = Mock() 
     s.bootstrap_completed_callbacks = self.four_callbacks
     s.complete_bootstrap(selfipp)
     assert s.send.call_count == 4
     assert all(map(self.has_telex_and_to, s.send.call_args_list))
Ejemplo n.º 2
0
 def test_switch_start_protocol_calls_startup_callbacks(self):
     s = Switch(ipp=selfipp)
     s.send = Mock()
     s.startup_callbacks = self.four_callbacks
     s.startProtocol()
     assert s.send.call_count == 4
     assert all(map(self.has_telex_and_to, s.send.call_args_list))
Ejemplo n.º 3
0
 def test_end_handler_sends_list_of_ends_to_original_sender(self):
     switch = Switch()
     switch.ipp = selfipp
     switch.ends.add(End(faripp))
     switch.send = Mock()
     self.t(self.seeking_far, self.from_end, switch)
     assert switch.send.called
     tel = switch.send.call_args[-1]['telex']
     assert isinstance(tel, Telex)
     assert ippstr(faripp) in tel['.see']
     assert switch.send.call_args[-1]['to'] == self.from_end
Ejemplo n.º 4
0
 def test_switch_start_protocol_sends_bootstrap_telex_under_correct_conditions(self):
     s_should_send = Switch(seed_ipp=faripp)
     s_should_send.send = Mock()
     s_should_send.startProtocol()
     assert s_should_send.send.called
     s_should_not_send = Switch()
     s_should_not_send.ipp = selfipp
     s_should_not_send.send = Mock()
     s_should_not_send.startProtocol()
     assert not s_should_not_send.send.called
Ejemplo n.º 5
0
 def test_switch_send_writes_to_transport_iff_the_telex_is_not_empty(self):
     s = Switch()
     s.ipp = selfipp
     s.transport = Mock()
     s.transport.write = Mock()
     empty_tel = Telex()
     s.send(telex=empty_tel, to=End(faripp))
     assert not s.transport.write.called
     tel = Telex(other_dict={'+foo':'bar'})
     s.send(telex=tel, to=End(faripp))
     s.transport.write.assert_called_with(tel.dumps(), faripp)
Ejemplo n.º 6
0
 def test_bootstrap_handler_adds_other_default_handlers_and_removes_itself(self):
     s = Switch()
     s.handlers = {id(self.h): self.h}
     self.h(self.telex_with_to, End(faripp), s)
     assert len(s.handlers) > 0
     assert id(self.h) not in s.handlers
Ejemplo n.º 7
0
 def test_bootstrap_handler_sets_switch_ipp(self):
     s = Switch()
     s.remove_handler = Mock()
     assert not s.ipp
     self.h(self.telex_with_to, End(faripp), s)
     assert s.ipp == ('127.0.0.1', 5555)
Ejemplo n.º 8
0
 def test_switch_add_bootstrap_completed_callback_adds_callbacks(self):
     s = Switch(ipp=selfipp)
     s.add_bootstrap_completed_callback(self.one_callback)
     assert self.one_callback in s.bootstrap_completed_callbacks
Ejemplo n.º 9
0
 def test_switch_add_start_callback_adds_start_callback(self):
     s = Switch(ipp=selfipp)
     s.add_startup_callback(self.one_callback)
     assert self.one_callback in s.startup_callbacks