def setUp(self):
   self.stmgr_client = MockSTStmgrClient()
Exemplo n.º 2
0
 def setUp(self):
   self.stmgr_client = MockSTStmgrClient()
class STStmgrClientTest(unittest.TestCase):
  def setUp(self):
    self.stmgr_client = MockSTStmgrClient()

  def tearDown(self):
    self.stmgr_client = None

  def test_on_connect_ok(self):
    self.stmgr_client.on_connect(StatusCode.OK)
    self.assertTrue(self.stmgr_client.register_msg_called)
    # timeout_task should be included in timer_tasks
    self.assertEqual(len(self.stmgr_client.looper.timer_tasks), 1)

  def test_on_connect_error(self):
    self.stmgr_client.on_connect(StatusCode.CONNECT_ERROR)
    self.assertEqual(len(self.stmgr_client.looper.timer_tasks), 1)
    self.assertEqual(self.stmgr_client.looper.timer_tasks[0][1].__name__, 'start_connect')

  def test_on_response(self):
    with self.assertRaises(RuntimeError):
      self.stmgr_client.on_response(StatusCode.INVALID_PACKET, None, None)

    with self.assertRaises(RuntimeError):
      self.stmgr_client.on_response(StatusCode.OK, None, mock_protobuf.get_mock_instance())

    self.stmgr_client.on_response(StatusCode.OK, None, mock_protobuf.get_mock_register_response())
    self.assertTrue(self.stmgr_client.handle_register_response_called)

  def test_on_error(self):
    self.stmgr_client.on_error()
    self.assertEqual(len(self.stmgr_client.looper.timer_tasks), 1)
    self.assertEqual(self.stmgr_client.looper.timer_tasks[0][1].__name__, 'start_connect')
Exemplo n.º 4
0
class STStmgrClientTest(unittest.TestCase):
  def setUp(self):
    self.stmgr_client = MockSTStmgrClient()

  def tearDown(self):
    self.stmgr_client = None

  def test_on_connect_ok(self):
    self.stmgr_client.on_connect(StatusCode.OK)
    self.assertTrue(self.stmgr_client.register_msg_called)
    # timeout_task should be included in timer_tasks
    self.assertEqual(len(self.stmgr_client.looper.timer_tasks), 1)

  def test_on_connect_error(self):
    self.stmgr_client.on_connect(StatusCode.CONNECT_ERROR)
    self.assertEqual(len(self.stmgr_client.looper.timer_tasks), 1)
    self.assertEqual(self.stmgr_client.looper.timer_tasks[0][1].__name__, 'start_connect')

  def test_on_response(self):
    with self.assertRaises(RuntimeError):
      self.stmgr_client.on_response(StatusCode.INVALID_PACKET, None, None)

    with self.assertRaises(RuntimeError):
      self.stmgr_client.on_response(StatusCode.OK, None, mock_protobuf.get_mock_instance())

    self.stmgr_client.on_response(StatusCode.OK, None, mock_protobuf.get_mock_register_response())
    self.assertTrue(self.stmgr_client.handle_register_response_called)

  def test_on_error(self):
    self.stmgr_client.on_error()
    self.assertEqual(len(self.stmgr_client.looper.timer_tasks), 1)
    self.assertEqual(self.stmgr_client.looper.timer_tasks[0][1].__name__, 'start_connect')