def test_no_move_without_start(self): game.join(self.r, 'game', 'max') game.join(self.r, 'game', 'jenny') game.start(self.r, 'game', 'jenny') self.assertFalse(game.move(self.r, 'game', 'jenny', 'han')) info = game.info(self.r, 'game', 'jenny').next() self.assertEquals('camp', info['you']['state'])
def test_chat(self): game.join(self.r, 'game', 'loner') self.assertTrue(game.chat(self.r, 'game', 'loner', 'just me myself and i')) info = game.info(self.r, 'game').next() self.assertDictContainsSubset({'chat': { 'speaker': 'loner', 'message': 'just me myself and i'}}, info['updates'].pop(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']])
def test_start_statuses(self): game.join(self.r, 'game', 'dave') self.assertTrue(game.start(self.r, 'game', 'dave')) info = game.info(self.r, 'game', 'dave').next() self.assertDictContainsSubset({ 'state': 'camp', 'name': 'dave' }, info['you']) self.assertEquals([{'name': 'dave', 'state': 'camp' }], info['state']['players'])
def test_move(self): game.join(self.r, 'game', 'max') game.join(self.r, 'game', 'jenny') game.start(self.r, 'game', 'max') game.start(self.r, 'game', 'jenny') self.assertTrue(game.move(self.r, 'game', 'jenny', 'han')) info = game.info(self.r, 'game', 'jenny').next() self.assertEquals([{ 'name': 'jenny', 'state': 'moved'}, { 'name': 'max', 'state': 'undecided'}], info['state']['players']) self.assertEquals('han', info['you']['state'])
def test_start_game(self): game.join(self.r, 'game', 'alpha') game.join(self.r, 'game', 'beta') game.start(self.r, 'game', 'alpha') game.start(self.r, 'game', 'beta') info = game.info(self.r, 'game').next() self.assertEquals('1', info['state']['round']) self.assertEquals([{ 'name': 'alpha', 'state': 'undecided'}, { 'name': 'beta', 'state': 'undecided'}], info['state']['players'])
def test_info_advances(self): info = game.info(self.r, 'blocked') info.next() # pull out the not_exists info t = Thread(target=info.next) t.start() self.assertTrue(t.is_alive()) time.sleep(0.5) self.assertTrue(t.is_alive()) game.join(self.r, 'blocked', 'some dude') t.join(1) self.assertFalse(t.is_alive())
def test_info_advances_beyond_id(self): info = game.info(self.r, 'game') game.join(self.r, 'game', 'thing one') t_all_info = Thread(target=info.next) t_all_info.start() t_all_info.join(1) self.assertFalse(t_all_info.is_alive()) t_partial_info = Thread(target=info.next) t_partial_info.start() self.assertTrue(t_partial_info.is_alive()) time.sleep(0.5) self.assertTrue(t_partial_info.is_alive()) self.assertTrue(game.join(self.r, 'game', 'some dude')) t_partial_info.join(1) self.assertFalse(t_partial_info.is_alive())
def test_join(self): self.assertTrue(game.join(self.r, 'game', 'dave')) info = game.info(self.r, 'game', 'dave').next() self.assertDictContainsSubset({ 'state': 'joined', 'name': 'dave' }, info['you']) self.assertEquals([{'name': 'dave', 'state': 'joined' }], info['state']['players'])
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())
def test_all_must_approve_start(self): game.join(self.r, 'game', 'alpha') game.join(self.r, 'game', 'beta') game.join(self.r, 'game', 'gaga') game.start(self.r, 'game', 'alpha') game.start(self.r, 'game', 'beta') info = game.info(self.r, 'game').next() self.assertNotIn('round', info['state'])
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())
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']])
def test_updates_most_recent_first(self): """ The first update should be the most recent, then they work backwards. """ game.join(self.r, 'game', 'first') game.join(self.r, 'game', 'second') game.join(self.r, 'game', 'third') info = game.info(self.r, 'game').next() self.assertDictContainsSubset({'join': 'third'}, info['updates'].pop(0)) self.assertDictContainsSubset({'join': 'second'}, info['updates'].pop(0)) self.assertDictContainsSubset({'join': 'first'}, info['updates'].pop(0))
def test_info_waits_for_id(self): """ The ID passed to info should cause it to hold on a response until there are more than that number of updates. """ info = game.info(self.r, 'game', start_info_id=3) t = Thread(target=info.next) t.start() game.join(self.r, 'game', 'first') game.join(self.r, 'game', 'second') game.join(self.r, 'game', 'third') self.assertTrue(t.is_alive()) game.join(self.r, 'game', 'fourth') t.join(1) self.assertFalse(t.is_alive())
def test_superuser_chat(self): game.join(self.r, 'game', 'betty') game.join(self.r, 'game', 'susie') game.join(self.r, 'game', 'martha') self.assertTrue(game.chat(self.r, 'game', 'hero', "what up gals", True)) self.assertFalse(game.chat(self.r, 'game', 'zero', "me too!")) game.chat(self.r, 'game', 'betty', "who's that dude?") game.chat(self.r, 'game', 'martha', "no clue") info = game.info(self.r, 'game').next() self.assertEquals({ 'speaker': 'martha', 'message': 'no clue'}, info['updates'].pop(0)['chat']) self.assertEquals({ 'speaker': 'betty', 'message': "who's that dude?"}, info['updates'].pop(0)['chat']) self.assertEquals({ 'speaker': 'hero', 'message': 'what up gals'}, info['updates'].pop(0)['chat'])
def test_needs_multiple_players_to_start(self): game.join(self.r, 'game', 'hermit') game.start(self.r, 'game', 'hermit') info = game.info(self.r, 'game').next() self.assertNotIn('round', info['state'])
def test_cannot_join_twice(self): game.join(self.r, 'game', 'dave') self.assertFalse(game.join(self.r, 'game', 'dave')) info = game.info(self.r, 'game', 'dave').next() self.assertEquals(1, len(info['state']['players']))
def test_single_player_starting_gets_more_players_update(self): game.join(self.r, 'game', 'hermit') game.start(self.r, 'game', 'hermit') info = game.info(self.r, 'game').next() self.assertDictContainsSubset({'more_players': True}, info['updates'].pop(0))