예제 #1
0
    def test_follow_already_followed(self):
        '''It shouldn't do anything when following an already followed object'''
        user = self.login()
        to_follow = Fake.objects.create()
        FollowFake.objects.create(follower=user, following=to_follow)

        with on_follow.connected_to(self.handler):
            response = self.post(url_for('api.follow_fake', id=to_follow.id))

        self.assertStatus(response, 200)

        self.assertEqual(Follow.objects.following(to_follow).count(), 0)
        self.assertEqual(Follow.objects.followers(to_follow).count(), 1)
        self.assertEqual(Follow.objects.following(user).count(), 1)
        self.assertEqual(Follow.objects.followers(user).count(), 0)
        self.assertFalse(self.signal_emitted)
예제 #2
0
    def test_follow_already_followed(self):
        '''It should do nothing when following an already followed object'''
        user = self.login()
        to_follow = Fake.objects.create()
        FollowFake.objects.create(follower=user, following=to_follow)

        with on_follow.connected_to(self.handler):
            response = self.post(url_for('api.follow_fake', id=to_follow.id))

        self.assertStatus(response, 200)

        self.assertEqual(Follow.objects.following(to_follow).count(), 0)
        self.assertEqual(Follow.objects.followers(to_follow).count(), 1)
        self.assertEqual(Follow.objects.following(user).count(), 1)
        self.assertEqual(Follow.objects.followers(user).count(), 0)
        self.assertFalse(self.signal_emitted)
예제 #3
0
    def test_follow(self):
        '''It should follow on POST'''
        user = self.login()
        to_follow = Fake.objects.create()

        with on_follow.connected_to(self.handler):
            response = self.post(url_for('api.follow_fake', id=to_follow.id))

        self.assertStatus(response, 201)

        nb_followers = Follow.objects.followers(to_follow).count()

        self.assertEqual(response.json['followers'], nb_followers)
        self.assertEqual(Follow.objects.following(to_follow).count(), 0)
        self.assertEqual(nb_followers, 1)
        self.assertIsInstance(
            Follow.objects.followers(to_follow).first(), Follow)
        self.assertEqual(Follow.objects.following(user).count(), 1)
        self.assertEqual(Follow.objects.followers(user).count(), 0)
        self.assertTrue(self.signal_emitted)
예제 #4
0
    def test_follow(self):
        '''It should follow on POST'''
        user = self.login()
        to_follow = Fake.objects.create()

        with on_follow.connected_to(self.handler):
            response = self.post(url_for('api.follow_fake', id=to_follow.id))

        self.assertStatus(response, 201)

        nb_followers = Follow.objects.followers(to_follow).count()

        self.assertEqual(response.json['followers'], nb_followers)
        self.assertEqual(Follow.objects.following(to_follow).count(), 0)
        self.assertEqual(nb_followers, 1)
        self.assertIsInstance(Follow.objects.followers(to_follow).first(),
                              Follow)
        self.assertEqual(Follow.objects.following(user).count(), 1)
        self.assertEqual(Follow.objects.followers(user).count(), 0)
        self.assertTrue(self.signal_emitted)