Example #1
0
File: models.py Project: somnam/xo
    def test_CreateChat_AppendToGame(self):

        # Append chat to game
        game = Game.objects.get(pk=1)
        chat = Chat(game_id=game.id)
        chat.save()
        game.save()

        # Check instances
        self.assertIsInstance(chat, Chat)
        self.assertIsInstance(chat.game, Game)
        self.assertIsInstance(game.chat, Chat)
        self.assertEqual(chat.game.id, game.id)
        self.assertEqual(game.chat.game_id, game.id)

        # Check users
        self.assertEqual(chat.game.users.count(), 2)
        for i in (1,2):
            self.assertIsInstance(chat.game.users.get(id=i), User)
Example #2
0
    def test_CreateChat_AppendToGame(self):

        # Append chat to game
        game = Game.objects.get(pk=1)
        chat = Chat(game_id=game.id)
        chat.save()
        game.save()

        # Check instances
        self.assertIsInstance(chat, Chat)
        self.assertIsInstance(chat.game, Game)
        self.assertIsInstance(game.chat, Chat)
        self.assertEqual(chat.game.id, game.id)
        self.assertEqual(game.chat.game_id, game.id)

        # Check users
        self.assertEqual(chat.game.users.count(), 2)
        for i in (1, 2):
            self.assertIsInstance(chat.game.users.get(id=i), User)
Example #3
0
File: forms.py Project: somnam/xo
    def save(self):
        # Create a new Game instance for current user
        game = Game(name=self.cleaned_data['name'])
        game.save()
        # Add user to game
        game.users.add(self.user.id)
        game.save()

        # Create a new Board instance and assign it to created game
        board = Board(game_id=game.id, size=self.cleaned_data['size'])
        board.save()

        # Create black Stone instances for first player.
        # Second player will have white stones.
        board.add_stones(self.user, STONE_COLORS['black'])

        # Add chat to game
        chat = Chat(game_id=game.id)
        chat.save()

        # Add player join message
        chat.join(self.user)

        return game
Example #4
0
File: forms.py Project: somnam/xo
    def save(self):
        # Create a new Game instance for current user
        game = Game(name=self.cleaned_data['name'])
        game.save()
        # Add user to game
        game.users.add(self.user.id)
        game.save()

        # Create a new Board instance and assign it to created game
        board = Board(game_id=game.id, size=self.cleaned_data['size'])
        board.save()

        # Create black Stone instances for first player.
        # Second player will have white stones.
        board.add_stones(self.user, STONE_COLORS['black'])

        # Add chat to game
        chat = Chat(game_id=game.id)
        chat.save()

        # Add player join message
        chat.join(self.user)

        return game
Example #5
0
    def test_UserJoin_PrintMessage(self):

        game = Game.objects.get(pk=1)
        chat = Chat(game=game)
        chat.save()
Example #6
0
    def test_CreateChat_CreatesInstance(self):

        # Create chat instance
        chat = Chat()
        chat.save()
        self.assertIsInstance(chat, Chat)
Example #7
0
File: models.py Project: somnam/xo
    def test_UserJoin_PrintMessage(self):

        game = Game.objects.get(pk=1)
        chat = Chat(game=game)
        chat.save()
Example #8
0
File: models.py Project: somnam/xo
    def test_CreateChat_CreatesInstance(self):

        # Create chat instance
        chat = Chat()
        chat.save()
        self.assertIsInstance(chat, Chat)