jeudi 17 septembre 2020

Django model testing

I have a problem in trying to print information of a model while testing. This is my code:

from django.test import TestCase
from .models import User, Followed, Following, Post
# Create your tests here.
class User_test(TestCase):
    def setUp(self):
        a = User.objects.create(username="a", password="a", email='a@a')
        f = User.objects.create(username="f", password="f", email='f@f')

        Followed.objects.create(user=a)
        Following.objects.create(user=f)

        Followed.objects.create(user=f)
        Following.objects.create(user=a)



    def test_a(self):
        userA = User.objects.get(username='a')
        userF = User.objects.get(username='f')

        peopleFollowingF = Followed.objects.get(user=userF)
        peopleFollowingA = Followed.objects.get(user=userA)

        Afollowing = Following.objects.get(user=userA)
        Ffollowing = Following.objects.get(user=userF)
        userA.save()
        Ffollowing.follower.add(User.objects.get(username='a'))
     
        Ffollowing.save()
        print(Ffollowing.follower)

when I run the test i get print network.User.None
Someone can help me to print add succesfully the userA?

Aucun commentaire:

Enregistrer un commentaire