Beispiel #1
0
    def test_games_names(self):
        game.join(self.r, 'the hills', 'foo')
        game.join(self.r, 'the valleys', 'bar')

        games = game.games(self.r)

        self.assertItemsEqual(['the hills', 'the valleys'],
                              [g['name'] for g in games.next()['games']])
Beispiel #2
0
    def test_games_in_reverse_order(self):
        """
        Most recent games come first.
        """
        game.join(self.r, 'thesis', 'foo')
        game.join(self.r, 'antithesis', 'bar')
        game.join(self.r, 'synthesis', 'baz')

        games = game.games(self.r)

        self.assertEqual(['synthesis', 'antithesis', 'thesis'],
                         [g['name'] for g in games.next()['games']])
Beispiel #3
0
    def test_games_waits_for_id(self):
        """
        The ID passed to games should cause it to hold on a response
        until there are more than that number of games.
        """
        games = game.games(self.r, 3)

        t = Thread(target=games.next)
        t.start()

        game.join(self.r, 'one', 'player')
        game.join(self.r, 'two', 'player')
        game.join(self.r, 'three', 'player')
        self.assertTrue(t.is_alive())
        game.join(self.r, 'four', 'player')

        t.join(1)
        self.assertFalse(t.is_alive())
Beispiel #4
0
    def test_games_advances(self):
        """
        .games() should return a generator that only advances when a
        new game is made.
        """
        games = game.games(self.r)
        games.next()  # pull out the empty array

        t = Thread(target=games.next)
        t.start()

        self.assertTrue(t.is_alive())
        time.sleep(0.5)
        self.assertTrue(t.is_alive())

        game.join(self.r, 'unblocked', 'some dude') # create a game

        t.join(1)
        self.assertFalse(t.is_alive())
Beispiel #5
0
 def test_no_games_zero_id(self):
     """
     .games() should initially return an empty array if there were no games.
     """
     games = game.games(self.r)
     self.assertEquals(0, games.next()['id'])