def test_app_on_connect(self):
        for test in self.app_on_connect_test_params:
            global initialNumUsers
            initialNumUsers = test[KEY_INPUT][KEY_NUM_USERS]
            with mock.patch('app.socketio.emit', self.mock_emit):
                try:
                    app.on_connect()
                    self.assertEqual("no mocked emit sent", "")
                except NameError as response_str:
                    response = json.loads(str(response_str))
                    expected = test[KEY_EXPECTED]

                    self.assertEqual(response[KEY_CHANNEL],
                                     expected[KEY_CHANNEL])
                    self.assertEqual(response[KEY_DATA], expected[KEY_DATA])
    def test_on_connect(self):
        """ Test who successfully connected """
        for test in self.success_test_connect:
            with mock.patch("app.on_connect", self.mocked_socket):
                response = app.on_connect()
                expected = test[KEY_EXPECTED]

            self.assertNotEqual(response, expected[KEY_COUNT])
Example #3
0
 def test_success(self):
     #print("Testing")
     for test in self.success_test_params:
         actual_result = on_connect()
         print(actual_result)
         expected_result = test[KEY_EXPECTED]
         print(expected_result)
         #self.assertEqual(len(actual_result), len(expected_result))
         self.assertEqual(actual_result, expected_result)
Example #4
0
    def test_app_on_connect(self, mocked_flask):
        session = mockDBsession.MockSession()
        for test in self.test_on_connect_params:
            mockModels.CurrentConnections.reset_mock_database()
            load_current_connections_table(
                test[KEY_INPUT][KEY_CURRENT_CONNECTIONS_DB])
            mocked_flask.request.sid = test[KEY_INPUT][KEY_SID]
            with mock.patch('models.DB.session', session):
                with mock.patch('models.CurrentConnections',
                                mockModels.CurrentConnections):
                    app.on_connect()

            createdTable = export_current_connections_table()
            expectedTable = test[KEY_EXPECTED][KEY_CURRENT_CONNECTIONS_DB]
            self.assertEqual(len(createdTable), len(expectedTable))
            for row_num in range(len(createdTable)):
                self.assertEqual(len(createdTable[row_num]),
                                 len(expectedTable[row_num]))
                for key in createdTable[row_num]:
                    self.assertTrue(key in expectedTable[row_num])
                    self.assertEqual(createdTable[row_num][key],
                                     expectedTable[row_num][key])
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_connect(self):
        """test connect funtion"""
        MOCKCLIENTS = TESTCLIENTS.copy()
        EXPECTEDCLIENTS = {
            "001":MOCKCLIENTS["001"],
            "002":MOCKCLIENTS["002"],
            "003":MOCKCLIENTS["003"],
            "004":MOCKCLIENTS["004"],
            "005": {
                NAME: DEFAULT_NAME,
                ONLINE: False,
                EMAIL: DEFAULT_EMAIL,
                PICTURE: DEFAULT_PICTURE,
            }
        }

        mock_clientID = '005'
        with mock.patch("app.socketio.emit", mock_emit):
            with mock.patch("app.clients", MOCKCLIENTS):
                response = on_connect()
                self.assertTrue(response[RESPONSE] == 'connected')
                response = on_rollcall(mock_clientID)
                self.assertEqual(response[DATA], EXPECTEDCLIENTS)
 def test_on_connect(self, mock_flask):
     mock_flask.request.sid = "mock_sid"
     app.on_connect()
Example #8
0
 def test_on_connect(self, mock_print):
     app.on_connect()
     mock_print.assert_called_with("Someone connected!")
Example #9
0
 def test_on_connect(self, mock_print):
     """ Mocked socket connection print response """
     app.on_connect()
     mock_print.assert_called_with("Someone connected!")