Ejemplo n.º 1
0
    def test_app_on_disconnect(self, mocked_flask):
        for test in self.test_on_disconnect_params:
            session = UnifiedAlchemyMagicMock()
            mocked_flask.request.sid = test[KEY_INPUT][KEY_SID]
            with mock.patch('models.DB.session', session):
                session.add(
                    models.CurrentConnections(test[KEY_INPUT][KEY_SID], 1))
                session.add(
                    models.AuthUser(models.AuthUserType.GOOGLE, 'nrw41',
                                    'meail', 'pciina'))
                session.commit()
                #with mock.patch('app.print', self.mock_print):
                #    with mock.patch('app.emit_all_users', self.mock_emit_all_users):
                with mock.patch('app.get_room', self.mock_get_room):
                    app.on_disconnect()

            self.assertEqual(len(self.emit_list) + 1, len(test[KEY_EXPECTED]))
            for i in range(len(self.emit_list)):
                self.assertEqual(self.emit_list[i]['opp'],
                                 test[KEY_EXPECTED][i]['opp'])
Ejemplo n.º 2
0
    def test_success2(self):
        #print("Testing")
        for test in self.success_test_params:
            print("buffer1")
            actual_result = on_disconnect()
            print("buffer2")
            print(actual_result)
            print("buffer3")
            expected_result = test[KEY_EXPECTED]
            print("buffer4")
            print(expected_result)
            print("buffer5")

            #self.assertEqual(len(actual_result), len(expected_result))
            self.assertEqual(actual_result, expected_result)
Ejemplo n.º 3
0
    def test_disconnect(self):
        """test disconnect function"""
        MOCKCLIENTS = TESTCLIENTS.copy()
        with mock.patch("app.socketio.emit", mock_emit):
            with mock.patch("app.clients", MOCKCLIENTS):

                response = on_disconnect()
                self.assertTrue(response[RESPONSE] == 'who is here')
                self.assertEqual(MOCKCLIENTS["003"]["online"], False)
                self.assertEqual(MOCKCLIENTS["004"]["online"], False)

                on_rollcall('001')
                on_rollcall('004')
                response = on_rollcall('002')

                self.assertTrue(response[RESPONSE] == 'current userlist')

                self.assertEqual(MOCKCLIENTS["003"]["online"], False)
                self.assertEqual(MOCKCLIENTS["004"]["online"], True)
Ejemplo n.º 4
0
def socketio_test():
    """ Tests the server """
    # log the user in through Flask test client
    flask_test_client = APP.test_client()
    # connect to Socket.IO without being logged in
    socketio_test_client = SOCKETIO.test_client(
        APP, flask_test_client=flask_test_client)
    # makes a connection to the client
    assert socketio_test_client.is_connected()
    #test connect function
    connect = on_connect()
    assert connect == 'connected'
    # logged in test username just a test
    data = {'joined': 'test'}
    #assuming that the user left the server
    #client disconnect
    assert not socketio_test_client.disconnect()
    #test the function
    disconnect = on_disconnect()
    assert disconnect == 'disconnected'
 def test_on_disconnect(self):
     app.on_disconnect()
Ejemplo n.º 6
0
 def test_on_disconnect(self, mock_print):
     app.on_disconnect()
     mock_print.assert_called_with("Someone disconnected!")
Ejemplo n.º 7
0
 def test_on_disconnect(self, mock_print):
     """ Mocked socket disconnect print response """
     app.on_disconnect()
     mock_print.assert_called_with("Someone disconnected!")