示例#1
0
    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)
示例#2
0
    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)
示例#3
0
    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')
示例#4
0
    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)
示例#5
0
    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)
示例#6
0
    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')
示例#7
0
    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)
示例#8
0
    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)
示例#9
0
    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')
示例#10
0
    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')
示例#11
0
    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)
示例#12
0
    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)
示例#13
0
    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)
示例#14
0
    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)
示例#15
0
    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')
示例#16
0
    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')
示例#17
0
    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')
示例#18
0
    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')
示例#19
0
 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
示例#20
0
 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
示例#21
0
 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)
示例#22
0
 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')
示例#23
0
 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')
示例#24
0
 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')
示例#25
0
 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')
示例#26
0
 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)
示例#27
0
 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')
示例#28
0
 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')
示例#29
0
 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')
示例#30
0
 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')