Exemplo n.º 1
0
def on_join_whiteboard(data):
    my_leader = 1
    any_leader = (models.DB.session.query(
        models.WhiteboardConnections).filter_by(whiteboard=data["id"],
                                                leader=1).first())
    if any_leader:
        my_leader = 0
        socketio.emit("force to save", room=any_leader.sid)
        print("make leader save", any_leader.sid)
    else:
        print("LOAD DEFAULT")
        save_num = (models.DB.session.query(
            models.Whiteboards).filter_by(id=data["id"]).first().save_num)
        socketio.emit(
            "load board",
            {
                "address":
                "https://ourstudybucket.s3.amazonaws.com/w{}s{}.png".format(
                    data["id"], save_num)
            },
            room=flask.request.sid,
        )
    models.DB.session.add(
        models.WhiteboardConnections(data["id"], flask.request.sid, my_leader))
    models.DB.session.commit()
    flask_socketio.join_room("w{}".format((data["id"])))
Exemplo n.º 2
0
 def test_app_get_board(self, mocked_flask):
     session = UnifiedAlchemyMagicMock()
     for test in self.test_get_board_params:
         mocked_flask.request.sid = test[KEY_INPUT][KEY_SID]
         with mock.patch("flask_socketio.SocketIO.emit", self.mock_emit):
             with mock.patch("models.DB.session", session):
                 session.add(
                     models.WhiteboardConnections(
                         *test[KEY_INPUT][KEY_CONNECTION]))
                 session.commit()
                 self.assertEqual(app.get_board(test[KEY_INPUT][KEY_SID]),
                                  test[KEY_EXPECTED])
Exemplo n.º 3
0
 def test_app_on_forced_save(self, mocked_flask):
     session = UnifiedAlchemyMagicMock()
     for test in self.test_on_forced_save_params:
         mocked_flask.request.sid = test[KEY_INPUT][KEY_SID]
         with mock.patch("flask_socketio.SocketIO.emit", self.mock_emit):
             with mock.patch("models.DB.session", session):
                 temp_row=models.Whiteboards(*test[KEY_INPUT][KEY_BOARD][:2])
                 temp_row.save_num = test[KEY_INPUT][KEY_BOARD][2]
                 session.add(temp_row)
                 session.add(models.WhiteboardConnections(*test[KEY_INPUT][KEY_CONNECTION]))
                 session.commit()
                 app.on_forced_save({"blob":bytes([1,5,2,5,3,2,1])})
             self.assertDictEqual(self.hold, test[KEY_EXPECTED])
Exemplo n.º 4
0
 def test_on_disconnect_whiteboard_board(self, mocked_print, mocked_flask):
     session = UnifiedAlchemyMagicMock()
     for test in self.test_on_disconnect_whiteboard_params:
         mocked_flask.request.sid = test[KEY_INPUT][KEY_SID]
         with mock.patch("flask_socketio.leave_room",
                         self.mock_leave_group):
             with mock.patch("models.DB.session", session):
                 for connect in test[KEY_INPUT][KEY_CONNECTION]:
                     temp_row = models.WhiteboardConnections(*connect)
                     temp_row.id = 1
                     session.add(temp_row)
                     session.commit()
                 app.on_disconnect_whiteboard()
                 mocked_print.assert_called_with(test[KEY_EXPECTED])
Exemplo n.º 5
0
    def test_on_join_whiteboard_other(self, mocked_flask):
        session = UnifiedAlchemyMagicMock()
        for test in self.test_on_join_whiteboard_other:
            mocked_flask.request.sid = test[KEY_INPUT][KEY_SID]
            with mock.patch("flask_socketio.SocketIO.emit", self.mock_emit):
                with mock.patch("flask_socketio.join_room", self.mock_join_room):  
                    with mock.patch("models.DB.session", session):
                        temp_row=models.WhiteboardConnections(*test[KEY_INPUT][BOARD_DATA])
                        temp_row.id = 1
                        session.add(temp_row)
                        
                        session.commit()
                        app.on_join_whiteboard(test[KEY_INPUT][KEY_DATA])

            self.assertDictEqual(self.hold, test[KEY_EXPECTED])