def test_tictac_invalid_move(self): game = GameFactory.create(channel='C98765') game.state = { 'last_move': 'O', 'board': [[0,'X',0],[0,'X',0],[0,0,0]] } game.save() player1 = PlayerFactory.create( game=game, name='Stewart', is_current=True, ) player2 = PlayerFactory.create(game=game, name='cal') request = self.make_command_request('tictac move 5', 'Stewart', 'C98765') response = views.slash_command(request) self.assertJSONEqual(str(response.content, encoding='utf8'), { 'text': views.INVALID_MOVE })
def test_tictac_forfeit(self): game = GameFactory.create(channel='C98765') game.state = { 'last_move': 'O', 'board': [['X',0,0],[0,'X',0],[0,0,'O']] } game.save() player1 = PlayerFactory.create( game=game, name='Stewart', is_current=True, ) player2 = PlayerFactory.create(game=game, name='cal') request = self.make_command_request('tictac forfeit', 'Stewart', 'C98765') response = views.slash_command(request) self.assertJSONEqual(str(response.content, encoding='utf8'), { 'response_type': 'in_channel', 'text': "Stewart forfeits! cal wins the game!", }) game = Game.objects.get(id=game.id) self.assertFalse(game.is_active)
def test_tictac_win(self): game = GameFactory.create(channel='C98765') game.state = { 'last_move': 'O', 'board': [[0,'X',0],[0,'X',0],[0,0,0]] } game.save() player1 = PlayerFactory.create( game=game, name='Stewart', is_current=True, ) player2 = PlayerFactory.create(game=game, name='cal') request = self.make_command_request('tictac move 8', 'Stewart', 'C98765') response = views.slash_command(request) self.assertJSONEqual(str(response.content, encoding='utf8'), { 'response_type': 'in_channel', 'text': 'Stewart has won the game!', 'attachments': [{ 'text': ":white_medium_square: :x: :white_medium_square: \n:white_medium_square: :x: :white_medium_square: \n:white_medium_square: :x: :white_medium_square: " }] })