Beispiel #1
0
    def test_follow(self):
        follow = Follow.objects.create(self.lennon, self.hendrix)

        _, result = Follow.objects.get_or_create(self.lennon, self.hendrix)
        self.assertEqual(False, result)

        result = Follow.objects.is_following(self.lennon, self.hendrix)
        self.assertEqual(True, result)

        result = Follow.objects.is_following(self.hendrix, self.lennon)
        self.assertEqual(False, result)

        result = Follow.objects.get_follows(User)
        self.assertEqual(1, len(result))
        self.assertEqual(self.lennon, result[0].user)

        result = Follow.objects.get_follows(self.hendrix)
        self.assertEqual(1, len(result))
        self.assertEqual(self.lennon, result[0].user)

        result = self.hendrix.get_follows()
        self.assertEqual(1, len(result))
        self.assertEqual(self.lennon, result[0].user)

        result = self.lennon.get_follows()
        self.assertEqual(0, len(result), result)

        utils.toggle(self.lennon, self.hendrix)
        self.assertEqual(0, len(self.hendrix.get_follows()))

        utils.toggle(self.lennon, self.hendrix)
        self.assertEqual(1, len(self.hendrix.get_follows()))
Beispiel #2
0
    def test_follow(self):
        follow = Follow.objects.create(self.lennon, self.hendrix)
        
        _, result = Follow.objects.get_or_create(self.lennon, self.hendrix)
        self.assertEqual(False, result)
        
        result = Follow.objects.is_following(self.lennon, self.hendrix)
        self.assertEqual(True, result)
        
        result = Follow.objects.is_following(self.hendrix, self.lennon)
        self.assertEqual(False, result)

        result = Follow.objects.get_follows(User)
        self.assertEqual(1, len(result))
        self.assertEqual(self.lennon, result[0].user)
        
        result = Follow.objects.get_follows(self.hendrix)
        self.assertEqual(1, len(result))
        self.assertEqual(self.lennon, result[0].user)
        
        result = self.hendrix.get_follows()
        self.assertEqual(1, len(result))
        self.assertEqual(self.lennon, result[0].user)
        
        result = self.lennon.get_follows()
        self.assertEqual(0, len(result), result)
        
        utils.toggle(self.lennon, self.hendrix)
        self.assertEqual(0, len(self.hendrix.get_follows()))
        
        utils.toggle(self.lennon, self.hendrix)
        self.assertEqual(1, len(self.hendrix.get_follows()))