Пример #1
0
 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
     })
Пример #2
0
    def test_get_zero_tournament_homepage_200_OK(self):
        player = PlayerFactory()

        token = Token.objects.get(user__username=player.username)
        self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key)

        url = reverse('tournamentHomepageList')
        response = self.client.get(url)

        self.assertEqual(len(response.data), 0)
Пример #3
0
 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)
Пример #4
0
    def test_get_all_news_active_200_OK(self):
        NewsFactory()
        NewsFactory(active=False)

        player = PlayerFactory()

        token = Token.objects.get(user__username=player.username)
        self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key)

        url = reverse('newsList')
        response = self.client.get(url)
        self.assertEqual(len(response.data), 1)
Пример #5
0
 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: "
         }]
     })
Пример #6
0
    def test_creation_contact_201_CREATED(self):
        """ 
          Nico creates a Contact
        """
        nico = PlayerFactory()
        token = Token.objects.get(user__username = nico.username)
        self.client.credentials(HTTP_AUTHORIZATION = 'Token ' + token.key)

        data  = {'subject': 'Subject', 'text': 'text' }
        url = reverse('contactCreate')
        response = self.client.post(url, data,  format='json')

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Пример #7
0
    def test_update_notification_404_NOT_FOUND_D(self):
        """ 
            Fede tries to update Nico's Game Notification
        """
        fede = PlayerFactory()
        nico = PlayerFactory()
        notification = NotificationGameFactory(player=nico, sender=fede)
        self.assertTrue(
            NotificationGame.objects.get(pk=notification.pk).active)

        token = Token.objects.get(user__username=fede.username)
        self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key)

        url = reverse('notificationUpdate',
                      kwargs={
                          'pk': notification.pk,
                          'notification_type': 'game'
                      })
        response = self.client.put(url, format='json')

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
        self.assertTrue(
            NotificationGame.objects.get(pk=notification.pk).active)
        self.assertEqual(NotificationGame.objects.all().count(), 1)
Пример #8
0
    def test_update_401_UNAUTHORIZED(self):
        """ 
            Anon tries to update Nico Notification
        """
        nico = PlayerFactory()
        notification = NotificationFriendFactory(player=nico)
        self.assertTrue(
            NotificationFriend.objects.get(pk=notification.pk).active)

        url = reverse('notificationUpdate',
                      kwargs={
                          'pk': notification.pk,
                          'notification_type': 'friend'
                      })
        response = self.client.put(url, format='json')

        self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
        self.assertTrue(
            NotificationFriend.objects.get(pk=notification.pk).active)
        self.assertEqual(NotificationFriend.objects.all().count(), 1)
Пример #9
0
    def test_update_notification_202_ACCEPTED_B(self):
        """ 
          Nico updates Friend Notification 
        """
        nico = PlayerFactory()
        notification = NotificationFriendFactory(player=nico)
        self.assertTrue(
            NotificationFriend.objects.get(pk=notification.pk).active)

        token = Token.objects.get(user__username=nico.username)
        self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key)

        url = reverse('notificationUpdate',
                      kwargs={
                          'pk': notification.pk,
                          'notification_type': 'friend'
                      })
        response = self.client.put(url, format='json')

        self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
        self.assertFalse(
            NotificationFriend.objects.get(pk=notification.pk).active)
        self.assertEqual(NotificationFriend.objects.all().count(), 1)
Пример #10
0
class NotificationGameFactory(factory.Factory):
    player = factory.LazyAttribute(lambda a: PlayerFactory())
    sender = factory.LazyAttribute(lambda a: PlayerFactory())
    game = factory.LazyAttribute(lambda a: GameFactory())
    active = True
    notification_type = '1'