def test_game_ok(self): utils.create_game() r = self.client.get(path='/get_board?game=john-peter-1') d = simplejson.loads(r.content) self.assertFalse('error' in d) self.assertTrue(d['board'], INIT_BOARD)
def test_true(self): utils.create_game(start_it=True) r = self.client.get(path='/is_turn?game=john-peter-1&player=peter') d = simplejson.loads(r.content) self.assertTrue(d['status']) self.assertFalse('error' in d)
def test_game_is_returned_ok(self): utils.create_game() r = self.client.get(path='/connect?p1=john&p2=peter') d = simplejson.loads(r.content) self.assertFalse('error' in d) self.assertEqual(d['game'], 'john-peter-1')
def test_non_existing_game(self): utils.create_game() r = self.client.get(path='/is_turn?game=john-peter-2&player=john') d = simplejson.loads(r.content) self.assertEqual(d['error'], 'Game john-peter-2 not found') self.assertFalse('status' in d)
def test_ok(self): utils.create_game(start_it=True) data = {'game': 'john-peter-1', 'player': 'peter', 'move': '(3,2)'} r = self.client.post(path='/move', data=data) d = simplejson.loads(r.content) self.assertFalse('error' in d) self.assertEqual(d['status'], 'succeed')
def test_non_existing_game(self): utils.create_game() data = {'game': 'john-peter-3', 'player': 'peter', 'move': '(3,2)'} r = self.client.post(path='/move', data=data) d = simplejson.loads(r.content) self.assertEqual(d['error'], 'Game john-peter-3 not found') self.assertEqual(d['status'], 'failed')
def test_non_existing_player(self): utils.create_game(start_it=True) r = self.client.get(path='/is_turn?game=john-peter-1&player=oscar') d = simplejson.loads(r.content) self.assertEqual(d['error'], 'The player oscar is not playing in this' ' game') self.assertFalse('status' in d)
def test_game_not_started_yet(self): utils.create_game() r = self.client.get(path='/is_turn?game=john-peter-1&player=john') d = simplejson.loads(r.content) self.assertEqual(d['error'], 'The game hasn\'t started yet. Make sure' ' both players have been connected') self.assertFalse('status' in d)
def test_game_not_started_yet(self): utils.create_game() r = self.client.get(path='/is_turn?game=john-peter-1&player=john') d = simplejson.loads(r.content) self.assertEqual( d['error'], 'The game hasn\'t started yet. Make sure' ' both players have been connected') self.assertFalse('status' in d)
def test_non_existing_player(self): utils.create_game() data = {'game': 'john-peter-1', 'player': 'oscar', 'move': '(3,2)'} r = self.client.post(path='/move', data=data) d = simplejson.loads(r.content) self.assertEqual(d['error'], 'The player oscar is not playing in this' ' game') self.assertEqual(d['status'], 'failed')
def create(self, start_it=True, board=None): g = create_game() if start_it: g.start_game() if board: g.board = board g.save() return g
def test_get_piece_color(self): g = create_game() self.assertEqual(g.get_piece_color('john'), WHITE) self.assertEqual(g.get_piece_color('peter'), BLACK)
def test_get_by_id_players_in_reverse_order(self): create_game() with self.assertRaises(Exception) as ex: Game.objects.get_by_id('peter-john-1') self.assertEqual(ex.exception.message, 'Game peter-john-1 not found')
def test_get_by_id_players_do_not_match(self): create_game() with self.assertRaises(Exception) as ex: Game.objects.get_by_id('pepe-juan-1') self.assertEqual(ex.exception.message, 'Game pepe-juan-1 not found')
def test_get_by_id_existent(self): create_game() g = Game.objects.get_by_id('john-peter-1') self.assertTrue(g) self.assertEqual(g.player1.name, 'john') self.assertEqual(g.player2.name, 'peter')
def test_get_by_id_game_id_does_not_match(self): create_game() with self.assertRaises(Exception) as ex: Game.objects.get_by_id('john-peter-10') self.assertEqual(ex.exception.message, 'Game john-peter-10 not found')