Esempio n. 1
0
    def test_retrieve_board_list(self):
        """Test retrieving a list of board"""
        board = sample_board(title='Test board', description='Test board description')
        sample_topic(self.user.profile, board)
        sample_board(title='Another test board', description='Another test board description')

        res = self.client.get(BOARDS_URL)

        boards = Board.objects.all().order_by('id')
        serializer = BoardSerializer(boards, many=True, context={'request': RequestFactory().get(BOARDS_URL)})

        self.assertEqual(res.status_code, status.HTTP_200_OK)
        self.assertEqual(res.data, serializer.data)
        self.assertEqual(len(res.data), 2)
        self.assertAllIn(('id', 'title', 'description', 'topics', 'created_at'), res.data[0].keys())
        self.assertAllIn(('href', 'title'), res.data[0]['topics'][0].keys())
Esempio n. 2
0
 def setUp(self):
     self.board = sample_board()
     self.user = sample_user()
     self.topic = sample_topic(starter=self.user.profile, board=self.board)
     self.post = Post.objects.create(author=self.user.profile,
                                     message='Test post message',
                                     topic=self.topic)
Esempio n. 3
0
    def test_retrieve_board_details(self):
        """Test retrieving a board's details"""
        board = sample_board()
        topic = sample_topic(self.user.profile, board)
        url = detail_board_url(board)

        res = self.client.get(url)

        serializer = BoardSerializer(board, context={'request': RequestFactory().get(url)})
        self.assertEqual(res.status_code, status.HTTP_200_OK)
        self.assertEqual(res.data, serializer.data)
        self.assertEqual(res.data['topics'][0]['title'], topic.title)
        self.assertAllIn(('id', 'title', 'description', 'topics', 'created_at'), res.data.keys())
Esempio n. 4
0
    def test_update_board_fails_for_basic_user(self):
        """Test that basic users cannot update a board"""
        old_description = 'Old desciption'
        board = sample_board(description=old_description)
        self.client.force_authenticate(self.user)

        payload = {
            'description': 'New description'
        }

        res = self.client.patch(detail_board_url(board), payload)
        self.assertEqual(res.status_code, status.HTTP_403_FORBIDDEN)
        board.refresh_from_db()
        self.assertEqual(board.description, old_description)
Esempio n. 5
0
    def test_updating_board(self):
        """Test updating a board"""
        board = sample_board(description='Old description')
        superuser = sample_user(superuser=True, email='*****@*****.**')
        self.client.force_authenticate(superuser)

        payload = {
            'description': 'New description'
        }

        res = self.client.patch(detail_board_url(board), payload)

        self.assertEqual(res.status_code, status.HTTP_200_OK)
        board.refresh_from_db()
        self.assertEqual(board.description, payload['description'])
Esempio n. 6
0
 def setUp(self):
     self.board = sample_board()
Esempio n. 7
0
 def setUp(self):
     self.user = sample_user()
     self.board = sample_board()
     self.topic = sample_topic(self.user.profile, self.board)