def testCheckDraw(client1Moves, client2Moves): testClient = config.socketio.test_client(config.app, namespace) testClient2 = config.socketio.test_client(config.app, namespace) roomName = 'roomname' advancedMode = False playTime = 0 testClient.emit('createRoom', { 'roomName': 'roomname', 'advancedMode': False, 'playTime': 0, }) resp = testClient.get_received(namespace) roomId = resp[len(resp) - 1]['args'][0][u'roomId'] room = evh.getRoomById(roomId) testClient2.emit('joinRoom', { 'roomId': roomId, 'advancedMode': '', 'playTime': '', 'status': '' }) data = { 'id': '' } for i in range(len(client2Moves)): data['id'] = client1Moves[i] testClient.emit('clickedField', data) data['id'] = client2Moves[i] testClient2.emit('clickedField', data) data['id'] = client1Moves[len(client1Moves) - 1] testClient.emit('clickedField', data) assert room.game.playerSymbol[room.game.checkLocalWin()].upper() == 'NONE' assert room.game.isBoardNotPlayable(int(client1Moves[0][0])) resp = testClient2.get_received(namespace) testClient.disconnect() testClient2.disconnect()
def testCheckGlobalWin(client1Moves, client2Moves): testClient = config.socketio.test_client(config.app, namespace) testClient2 = config.socketio.test_client(config.app, namespace) roomName = 'roomname' advancedMode = False playTime = 0 testClient.emit('createRoom', { 'roomName': 'roomname', 'advancedMode': False, 'playTime': 0, }) resp = testClient.get_received(namespace) roomId = resp[len(resp) - 1]['args'][0][u'roomId'] room = evh.getRoomById(roomId) testClient2.emit('joinRoom', { 'roomId': roomId, 'advancedMode': '', 'playTime': '', 'status': '' }) data = { 'id': '' } for i in range(len(client1Moves)): data['id'] = client1Moves[i] testClient.emit('clickedField', data) data['id'] = client2Moves[i] testClient2.emit('clickedField', data) assert room.game.scoreTable['O'] == 1 resp = testClient2.get_received(namespace) testClient.disconnect() testClient2.disconnect()
def testThirdConnectedPlayerIsNotPresentInSocketsDictionary(): testClient = config.socketio.test_client(config.app, namespace) testClient2 = config.socketio.test_client(config.app, namespace) testClient3 = config.socketio.test_client(config.app, namespace) roomName = 'roomname' advancedMode = False playTime = 0 testClient.emit('createRoom', { 'roomName': 'roomname', 'advancedMode': False, 'playTime': 0, }) resp = testClient.get_received(namespace) roomId = resp[len(resp) - 1]['args'][0][u'roomId'] testClient2.emit('joinRoom', { 'roomId': roomId, 'advancedMode': '', 'playTime': '', 'status': '' }) testClient3.emit('joinRoom', { 'roomId': roomId, 'advancedMode': '', 'playTime': '', 'status': '' }) room = evh.getRoomById(roomId) assert room.whoseSocket.get(testClient3.sid) is None testClient.disconnect() testClient2.disconnect() testClient3.disconnect()
def testSecondlyJoinedPlayerBecomesPlayer1AfterFirstLeaves(): testClient = config.socketio.test_client(config.app, namespace) testClient2 = config.socketio.test_client(config.app, namespace) roomName = 'roomname' advancedMode = False playTime = 0 testClient.emit('createRoom', { 'roomName': 'roomname', 'advancedMode': False, 'playTime': 0, }) resp = testClient.get_received(namespace) roomId = resp[len(resp) - 1]['args'][0][u'roomId'] testClient2.emit('joinRoom', { 'roomId': roomId, 'advancedMode': '', 'playTime': '', 'status': '' }) room = evh.getRoomById(roomId) testClient.disconnect() assert room.whoseSocket[testClient2.sid] == 1 testClient2.disconnect()
def testGameIsNotActiveWhenOneOfTwoPlayersLeavesRoom(): testClient = config.socketio.test_client(config.app, namespace) testClient2 = config.socketio.test_client(config.app, namespace) roomName = 'roomname' advancedMode = False playTime = 0 testClient.emit('createRoom', { 'roomName': 'roomname', 'advancedMode': False, 'playTime': 0, }) resp = testClient.get_received(namespace) roomId = resp[len(resp) - 1]['args'][0][u'roomId'] testClient2.emit('joinRoom', { 'roomId': roomId, 'advancedMode': '', 'playTime': '', 'status': '' }) room = evh.getRoomById(roomId) testClient.disconnect() assert not room.isGameActive testClient2.disconnect()
def testJoinRoom(): testClient = config.socketio.test_client(config.app, namespace) testClient2 = config.socketio.test_client(config.app, namespace) roomName = 'roomname' advancedMode = False playTime = 0 testClient.emit('createRoom', { 'roomName': 'roomname', 'advancedMode': False, 'playTime': 0, }) resp = testClient.get_received(namespace) roomId = resp[len(resp) - 1]['args'][0][u'roomId'] testClient2.emit('joinRoom', { 'roomId': roomId, }) resp = testClient2.get_received(namespace) room = evh.getRoomById(roomId) assert resp[len(resp) - 2]['args'][0][u'roomId'] == roomId assert resp[len(resp) - 2]['args'][0][u'advancedMode'] == advancedMode assert resp[len(resp) - 2]['args'][0][u'playTime'] == playTime assert room.numberOfConnectedClients == 2 testClient.disconnect() testClient2.disconnect()