Exemple #1
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)
Exemple #2
0
    def test_set_username_already_taken(self):
        """Test setting a new username with name already taken"""
        other_user = sample_user(email='*****@*****.**')
        other_user.profile.username = '******'
        other_user.profile.save()

        current_username = self.user.profile.username
        result = self.user.profile.set_username(other_user.profile.username)

        self.assertFalse(result)
        self.assertNotEqual(self.user.profile.username,
                            other_user.profile.username)
        self.assertEqual(self.user.profile.username, current_username)
        self.assertFalse(self.user.profile.is_username_chosen)
Exemple #3
0
    def test_update_topic_requires_ownership(self):
        """Test that updating a topic requires the ownership"""
        new_user = sample_user(email='*****@*****.**')
        new_topic = sample_topic(board=self.board,
                                 starter=new_user.profile,
                                 title='Topic from another user')

        url = get_topic_url(self.board, new_topic)
        payload = {'title': 'Modified topic title'}
        res = self.client.patch(url, payload)

        self.assertEqual(res.status_code, status.HTTP_403_FORBIDDEN)
        new_topic.refresh_from_db()
        self.assertNotEqual(new_topic.title, payload['title'])
    def test_update_post_requires_ownership(self):
        """Test that owning a post is required to update it"""
        new_user = sample_user(email='*****@*****.**')
        new_post = Post.objects.create(author=new_user.profile,
                                       message='Post from another user',
                                       topic=self.topic)

        url = get_post_url(self.board, self.topic, new_post)
        payload = {'message': 'Modified post message'}
        res = self.client.patch(url, payload)

        self.assertEqual(res.status_code, status.HTTP_403_FORBIDDEN)
        new_post.refresh_from_db()
        self.assertNotEqual(new_post.message, payload['message'])
    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'])
    def test_create_board(self):
        """Test creating a board"""
        superuser = sample_user(superuser=True, email='*****@*****.**')
        self.client.force_authenticate(superuser)
        payload = {
            'title': 'New board',
            'description': 'New board description'
        }
        res = self.client.post(BOARDS_URL, payload)

        self.assertEqual(res.status_code, status.HTTP_201_CREATED)
        self.assertAllIn(('id', 'title', 'description', 'topics', 'created_at'), res.data.keys())

        board = Board.objects.get(id=res.data['id'])
        self.assertDictMatchesAttrs(payload, board)
 def setUp(self):
     self.client = APIClient()
     self.user = sample_user()
     self.user.profile.username = '******'
     self.client.force_authenticate(self.user)
 def setUp(self):
     self.client = APIClient()
     self.user = sample_user()
     self.user.profile.username = '******'
 def setUp(self):
     self.user = sample_user()
 def setUp(self):
     self.client = APIClient()
     self.user = sample_user()
     self.client.force_authenticate(self.user)
Exemple #11
0
 def setUp(self):
     self.admin_user = sample_user(superuser=True)
     self.client.force_login(self.admin_user)
     self.user = sample_user(email='*****@*****.**')
Exemple #12
0
 def setUp(self):
     self.user = sample_user()
     self.board = sample_board()
     self.topic = sample_topic(self.user.profile, self.board)