Example #1
0
     def test_emit_all_users_success(self, mock_get_room):
        session = mockDBsession.MockSession()
        for test in self.success_test_params:
            self.hold = []
            mock_get_room.return_value = test[KEY_INPUT][KEY_GET_ROOM_RETURN]

            # Load the initial state of the tables
            mockModels.Rooms.reset_mock_database()
            load_rooms_table(test[KEY_INPUT][KEY_ROOMS_DB])

            with mock.patch("models.DB.session", session):
                with mock.patch("flask_socketio.SocketIO.emit", self.mock_emit):
                    with mock.patch("builtins.print", self.mock_print):
                        with mock.patch("models.Rooms", mockModels.Rooms):
                            app.emit_room_stats(test[KEY_INPUT][KEY_CLIENT_SID])

            # Verify that the table(s) state after execution matches what was expected
            createdTable = export_rooms_table()
            expectedTable = test[KEY_EXPECTED][KEY_ROOMS_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])

            # Verify that emits were as expected
            captured_emits = self.hold
            expected_emits = test[KEY_EXPECTED][KEY_HOLD_LIST]
            self.assertEqual(len(captured_emits), len(expected_emits))
            for i in range(len(captured_emits)):
                self.assertEqual(len(captured_emits[i]), len(expected_emits[i]))
                for key in captured_emits[i]:
                    self.assertTrue(key in expected_emits[i])
                    self.assertEqual(captured_emits[i][key], expected_emits[i][key])
Example #2
0
     def test_reset_room_password(self, mock_flask, mock_get_room, mock_generate_pin):
        session = mockDBsession.MockSession()
        for test in self.success_test_params:
            self.hold = []
            mock_flask.request.sid = test[KEY_INPUT][KEY_SID]
            mock_get_room.return_value = test[KEY_INPUT][KEY_GET_ROOM_RETURN]
            mock_generate_pin.return_value = test[KEY_INPUT][KEY_GENERATE_PIN_RETURN]

            # Load the initial state of the tables
            mockModels.Rooms.reset_mock_database()
            load_rooms_table(test[KEY_INPUT][KEY_ROOMS_DB])
            mockModels.CurrentConnections.reset_mock_database()
            load_current_connections_table(test[KEY_INPUT][KEY_CURRENT_CONNECTIONS_DB])

            with mock.patch("models.DB.session", session):
                with mock.patch("app.emit_room_stats", self.mock_emit_room_stats):
                    with mock.patch("builtins.print", self.mock_print):
                        with mock.patch("models.Rooms", mockModels.Rooms):
                            with mock.patch("models.CurrentConnections", mockModels.CurrentConnections):
                                app.reset_room_password()

            # Verify that the table(s) state ageter execution matches what was expected
            createdTable = export_rooms_table()
            expectedTable = test[KEY_EXPECTED][KEY_ROOMS_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])
            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])

            # Verify that emits were as expected
            captured_emits = self.hold
            expected_emits = test[KEY_EXPECTED][KEY_HOLD_LIST]
            self.assertEqual(len(captured_emits), len(expected_emits))
            for i in range(len(captured_emits)):
                self.assertEqual(len(captured_emits[i]), len(expected_emits[i]))
                for key in captured_emits[i]:
                    self.assertTrue(key in expected_emits[i])
                    self.assertEqual(captured_emits[i][key], expected_emits[i][key])
Example #3
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])
Example #4
0
    def test_app_on_new_message(self, mocked_flask, mocked_get_room):
        session = mockDBsession.MockSession()
        for test in self.test_params:
            mockModels.CurrentConnections.reset_mock_database()
            load_current_connections_table(
                test[KEY_INPUT][KEY_CURRENT_CONNECTIONS_DB])
            mockModels.AuthUser.reset_mock_database()
            load_users_table(test[KEY_INPUT][KEY_AUTH_USER_DB])
            mockModels.Messages.reset_mock_database()
            load_messages_table(test[KEY_INPUT][KEY_MESSAGES_DB])
            mocked_flask.request.sid = test[KEY_INPUT][KEY_SID]
            mocked_get_room.return_value = test[KEY_INPUT][KEY_GET_ROOM_RETURN]
            self.hold = []

            with mock.patch('models.DB.session', session):
                with mock.patch('models.CurrentConnections',
                                mockModels.CurrentConnections):
                    with mock.patch('models.AuthUser', mockModels.AuthUser):
                        with mock.patch('models.Messages',
                                        mockModels.Messages):
                            with mock.patch('builtins.print', self.mock_print):
                                with mock.patch('app.emit_all_messages',
                                                self.mock_emit_all_messages):
                                    app.on_new_message(
                                        test[KEY_INPUT][KEY_DATA])

            # Verify that the table(s) state after execution matches what was expected
            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])
            createdTable = export_users_table()
            expectedTable = test[KEY_EXPECTED][KEY_AUTH_USER_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])
            createdTable = export_messages_table()
            expectedTable = test[KEY_EXPECTED][KEY_MESSAGES_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])

            # Verify that emits were as expected
            captured_emits = self.hold
            expected_emits = test[KEY_EXPECTED][KEY_HOLD_LIST]
            self.assertEqual(len(captured_emits), len(expected_emits))
            for i in range(len(captured_emits)):
                self.assertEqual(len(captured_emits[i]),
                                 len(expected_emits[i]))
                for key in captured_emits[i]:
                    self.assertTrue(key in expected_emits[i])
                    self.assertEqual(captured_emits[i][key],
                                     expected_emits[i][key])