Exemple #1
0
    def test_playerRegistration(self):
        ALL_GAMES.clear()
        ALL_PLAYERS.clear()

        options = {
            'difficulty': 'NORMAL',
            'nation': 'ENGLAND',
        }
        result = ALL_GAMES.createGame(options)
        gameId = result['gameId']
        ownerId = result['owner']['id']
        ownerName = result['owner']['name']

        player, game, reg = locatePlayerAndGame(ownerName, ownerId, gameId)
        self.assertEqual(game.id, gameId)
        self.assertEqual(ownerName, player.name)
        self.assertEqual(reg.playerConnection.id, ownerId)

        player2, game2, reg2 = locatePlayerAndGame(ownerName, ownerId, gameId)
        self.assertEqual(game2.id, gameId)
        self.assertEqual(ownerName, player2.name)
        self.assertEqual(reg2.playerConnection.id, ownerId)

        self.assertRaises(NoSuchGameError, locatePlayerAndGame, ownerName,
                          ownerId, '50')
        self.assertRaises(NoSuchPlayerInGameError, locatePlayerAndGame,
                          'Player 9', None, gameId)
        self.assertRaises(RegistrationMismatch, locatePlayerAndGame,
                          'Player 2', ownerId, gameId)
Exemple #2
0
    def test_replaceRegistration(self):
        ALL_GAMES.clear()
        ALL_PLAYERS.clear()

        options = {
            'difficulty': 'NORMAL',
            'nation': 'ENGLAND',
        }

        result = ALL_GAMES.createGame(options)
        gameId = result['gameId']
        ownerId = result['owner']['id']
        ownerName = result['owner']['name']

        player, game, reg = locatePlayerAndGame(ownerName, None, gameId)
        self.assertEqual(game.id, gameId)
        self.assertEqual(player.name, ownerName)
        self.assertNotEqual(reg.playerConnection.id, ownerId)
        self.assertEqual(reg.game.id, gameId)

        player2, game2, reg2 = locatePlayerAndGame(player.name,
                                                   reg.playerConnection.id,
                                                   gameId)
        self.assertEqual(game.id, game2.id)
        self.assertEqual(player.name, player2.name)
        self.assertEqual(reg.playerConnection.id, reg2.playerConnection.id)

        regIds = ALL_PLAYERS.getRegistrationIdsBy(player.name, gameId)
        self.assertEqual(len(regIds), 1)
        self.assertEqual(set(regIds), set([reg2.playerConnection.id]))
Exemple #3
0
    def test_gameCreationWithOptions(self):
        ALL_GAMES.clear()
        ALL_PLAYERS.clear()

        options = {
            'difficulty': 'NORMAL',
            'nation': 'FRANCE',
        }
        result = ALL_GAMES.createGame(options)
        gameId = result['gameId']
        ownerName = result['owner']['name']

        game = ALL_GAMES.findGame(result['gameId'])
        player = game.findPlayer(ownerName)

        self.assertEqual(player.controlledNation, 'FRANCE')
        self.assertEqual(game.numPlayers, 6)
Exemple #4
0
def setUpSimpleGame(testCase):
    ALL_GAMES.clear()
    ALL_PLAYERS.clear()
    ALL_CONNECTIONS.suppressConnectionWarnings = True

    options = {
        'difficulty': 'NORMAL',
        'nation': 'ENGLAND',
        'playableNations': testPlayableNations,
        'mapData': testingMapData,
    }
    result = ALL_GAMES.createGame(options)
    testCase.gameInfo = result
    testCase.game = ALL_GAMES.findGame(result['gameId'])
    testCase.player = testCase.game.findPlayer(result['owner']['name'])

    pub.subscribe(nextState, TOPIC_GAME_NEXT_STAGE_READY)
Exemple #5
0
    def test_basicNotifications(self):
        ALL_GAMES.clear()
        ALL_PLAYERS.clear()
        ALL_CONNECTIONS.clear()

        options = {
            'difficulty': 'NORMAL',
            'nation': 'ENGLAND',
        }

        result = ALL_GAMES.createGame(options)
        gameId = result['gameId']
        ownerId = result['owner']['id']
        ownerName = result['owner']['name']

        conn = DummyConnection(gameId=gameId, connectionId=ownerId)
        ALL_CONNECTIONS.add(conn)

        player, game, reg = locatePlayerAndGame(ownerName, ownerId, gameId)

        ALL_NOTIFICATIONS.message([player], game, {'msg': 'sup dude'})

        self.assertEqual(len(conn.outbox), 1)

        player2, game, reg2 = locatePlayerAndGame('Player 2', None, gameId)

        conn2 = DummyConnection(gameId=gameId,
                                connectionId=reg2.playerConnection.id)
        ALL_CONNECTIONS.add(conn2)
        ALL_NOTIFICATIONS.message([player], game, {'msg': 'sup dude'})

        self.assertEqual(len(conn.outbox), 2)
        self.assertEqual(len(conn2.outbox), 0)

        ALL_NOTIFICATIONS.message([player2], game, {'msg': 'sup dude'})

        self.assertEqual(len(conn.outbox), 2)
        self.assertEqual(len(conn2.outbox), 1)

        ALL_NOTIFICATIONS.message([player, player2], game, {'msg': 'sup dude'})

        self.assertEqual(len(conn.outbox), 3)
        self.assertEqual(len(conn2.outbox), 2)
Exemple #6
0
    def test_gameCreation(self):
        ALL_GAMES.clear()
        ALL_PLAYERS.clear()

        options = {
            'difficulty': 'NORMAL',
            'nation': 'ENGLAND',
        }
        result1 = ALL_GAMES.createGame(options)
        result2 = ALL_GAMES.createGame(options)
        result3 = ALL_GAMES.createGame(options)

        #self.assertEqual(result1['gameId'], '1')
        #self.assertEqual(result2['gameId'], '2')
        #self.assertEqual(result3['gameId'], '3')

        game = ALL_GAMES.findGame(result1['gameId'])
        self.assertEqual(game.id, result1['gameId'])

        self.assertRaises(NoSuchGameError, ALL_GAMES.findGame, '50')
Exemple #7
0
    def test_pubsub(self):
        ALL_GAMES.clear()
        ALL_PLAYERS.clear()
        ALL_CONNECTIONS.clear()

        options = {
            'difficulty': 'NORMAL',
            'nation': 'ENGLAND',
        }

        result = ALL_GAMES.createGame(options)
        gameId = result['gameId']
        ownerId = result['owner']['id']
        ownerName = result['owner']['name']

        conn = DummyConnection(gameId=gameId, connectionId=ownerId)
        ALL_CONNECTIONS.add(conn)

        player, game, reg = locatePlayerAndGame(ownerName, ownerId, gameId)
        pub.sendMessage(TOPIC_NOTIFICATION,
                        players=[player],
                        game=game,
                        message={'msg': 'sup duude'})
        self.assertEqual(len(conn.outbox), 1)
Exemple #8
0
 def setUp(self):
     ALL_GAMES.clear()
     ALL_PLAYERS.clear()
Exemple #9
0
def tearDownSimpleGame(testCase):
    ALL_GAMES.clear()
    ALL_PLAYERS.clear()
    testCase.game = None
    ALL_CONNECTIONS.suppressConnectionWarnings = False
Exemple #10
0
 def on_close(self):
     #ALL_CONNECTIONS.remove(self)
     if hasattr(self, 'connectionId') and self.connectionId:
         ALL_PLAYERS.deleteRegistrationById(self.connectionId)
     else:
         ALL_CONNECTIONS.remove(self)