I wrote this code for testing views in django when I run it i get the following error
response = self.clinet.get(self.inform_list_url)
AttributeError: 'TestInformLogin' object has no attribute 'clinet'
from django.test import TestCase,Client
from django.urls import reverse
from KnowledgeManagement.models import Members , TblInform
class TestInformLogin(TestCase):
def set_up_create_user(self):
self.user = Members.objects.create(username='testuser',nationalCode = '1235' , mobileNumber = '094562', date_joined = '2021-11-22')
self.user.set_password('12345')
self.user.save()
self.clinet = Client()
self.clinet.login(username='testuser', password='12345')
self.inform_list_url = reverse('inform_list')
self.edit_inform_url = reverse('edit_inform', args= [1])
def test_inform_list_GET(self):
response = self.clinet.get(self.inform_list_url)
self.assertEquals(response.status_code,200)
self.assertTemplateUsed(response , 'inform_list.html')
def test_edit_inform_GET(self):
response = self.clinet.get(self.edit_inform_url)
self.assertEquals(response.status_code,200)
self.assertTemplateUsed(response , 'inform.html')
CodePudding user response:
self.clinet is defined in the set_up_create_user method, but I don't think you ever call this method. That is why it is not defined. This should fix it...
def test_inform_list_GET(self):
self.set_up_create_user()
response = self.clinet.get(self.inform_list_url)
self.assertEquals(response.status_code,200)
self.assertTemplateUsed(response , 'inform_list.html')
def test_edit_inform_GET(self):
self.set_up_create_user()
response = self.clinet.get(self.edit_inform_url)
self.assertEquals(response.status_code,200)
self.assertTemplateUsed(response , 'inform.html')
CodePudding user response:
Here your data is not set up when test_inform_list_GET() is called.
you can either change set_up_create_user() to setUp() or call set_up_create_user() inside test_inform_list_GET() and test_edit_inform_GET()