Exemplo n.º 1
0
 def setUp(self):
     self.variant = factories.VariantFactory()
     self.user = factories.UserFactory()
     self.game = models.Game.objects.create(
         name='Test game',
         variant=self.variant,
         num_players=7,
         created_by=self.user,
     )
     self.game.participants.add(self.user)
     self.turn = models.Turn.objects.create(
         game=self.game,
         phase=Phase.BUILD,
         season=Season.FALL,
         year=1901,
     )
     self.nation = models.Nation.objects.create(
         variant=self.variant,
         name='France',
     )
     self.nation_state = models.NationState.objects.create(
         nation=self.nation,
         turn=self.turn,
         user=self.user,
     )
Exemplo n.º 2
0
    def test_post_valid_game(self):
        """
        Posting valid game data creates a game instance and redirects to
        `user-games` view. The user is automatically added as a participant of
        the game.
        """
        user = factories.UserFactory()
        self.client.force_authenticate(user=user)
        variant = factories.VariantFactory()

        data = {
            'name': 'Test Game',
        }
        url = reverse('create-game')
        response = self.client.post(url, data, format='json')

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertTrue(
            models.Game.objects.get(
                name='Test Game',
                created_by=user,
                variant=variant,
                participants=user,
            )
        )
Exemplo n.º 3
0
    def setUp(self):
        self.user = factories.UserFactory()
        self.client.force_authenticate(user=self.user)

        self.variant = factories.VariantFactory()
        self.game = models.Game.objects.create(
            status=GameStatus.ACTIVE,
            variant=self.variant,
            name='Test Game',
            created_by=self.user,
            num_players=7
        )
        self.game.participants.add(self.user)
        self.turn = models.Turn.objects.create(
            game=self.game,
            year=1901,
            phase=Phase.ORDER,
            season=Season.SPRING,
        )
        self.nation = models.Nation.objects.create(
            variant=self.variant,
            name='Test Nation',
        )
        self.nation_state = models.NationState.objects.create(
            nation=self.nation,
            turn=self.turn,
            user=self.user,
        )
        self.territory = models.Territory.objects.create(
            variant=self.variant,
            name='Paris',
            nationality=self.nation,
            supply_center=True,
        )
        self.territory_state = models.TerritoryState.objects.create(
            territory=self.territory,
            turn=self.turn,
            controlled_by=self.nation_state.nation,
        )
        self.territory = self.territory_state.territory
        self.piece = models.Piece.objects.create(
            game=self.game,
            nation=self.nation_state.nation,
            type=PieceType.ARMY,
        )
        self.piece_state = models.PieceState.objects.create(
            turn=self.turn,
            piece=self.piece,
            territory=self.territory,
        )
        self.order = models.Order.objects.create(
            turn=self.turn,
            source=self.territory,
            nation=self.nation
        )
        self.url = reverse('order', args=[self.game.id, self.order.id])
Exemplo n.º 4
0
 def setUp(self):
     self.variant = factories.VariantFactory()
     self.user = factories.UserFactory()
     self.game = models.Game.objects.create(
         name='Test game',
         variant=self.variant,
         num_players=7,
         created_by=self.user,
     )
     self.game.participants.add(self.user)
Exemplo n.º 5
0
 def setUp(self):
     self.data = {}
     self.user = factories.UserFactory()
     self.variant = factories.VariantFactory()
     self.game = models.Game.objects.create(
         status=GameStatus.PENDING,
         variant=self.variant,
         name='Test Game',
         created_by=self.user,
         num_players=7
     )
     self.url = reverse('toggle-join-game', args=[self.game.id])
Exemplo n.º 6
0
 def setUp(self):
     self.user = factories.UserFactory()
     self.variant = factories.VariantFactory()
     self.game = models.Game.objects.create(
         status=GameStatus.ACTIVE,
         variant=self.variant,
         name='Test Game',
         created_by=self.user,
         num_players=7
     )
     self.game.participants.add(self.user)
     turn = models.Turn.objects.create(
         game=self.game,
         year=1901,
         phase=Phase.ORDER,
         season=Season.SPRING,
     )
     nation = models.Nation.objects.create(
         variant=self.game.variant,
         name='France',
     )
     self.nation_state = models.NationState.objects.create(
         nation=nation,
         turn=turn,
         user=self.user,
         orders_finalized=True,
     )
     territory_state = factories.TerritoryStateFactory(
         turn=self.game.get_current_turn(),
         controlled_by=self.nation_state.nation,
     )
     self.territory = territory_state.territory
     self.url = reverse(
         'toggle-finalize-orders',
         args=[self.nation_state.id]
     )
     self.data = {}