def setUp(self): for i in range(4): u = User(username='******' + str(i)) u.save() c = Contacts(**update_dict) c.save() client = Client() for i in range(3): client.get(reverse('login'))
def test_more_than_one_object(self): """ should edit the first object """ contacts = Contacts(name="Myname", lastname="Mylastname", email="myemail", date_of_birth=datetime.today(), jabber_id="myjabber", skype_login="******", bio="bio!", other_contacts="blabla") contacts.save() params = update_dict.copy() params['name'] = 'Vitaliy' params['lastname'] = 'Franchook' # ensure view edits the first object self.client.post(self.url, params) self.assertEqual(Contacts.objects.get(pk=1).name, 'Vitaliy') self.assertEqual(Contacts.objects.get(pk=2).name, 'Myname')
def test_contacts_list(self): """ testing contacts list view """ response = self.client.get(self.url) # checking response's status code self.assertEqual(response.status_code, 200) # check if the proper template was used self.assertTemplateUsed(response, 'contacts.html') # check if we have correct name in content self.assertIn(self.contacts.name, response.content) # check if we have "Bio:" label in content self.assertIn("Bio:", response.content) # check if we have br tag in conent self.assertIn("br", response.content) # ensure view had only returned Contacts self.assertTrue(isinstance(response.context['contacts'], Contacts)) # check if we have admin edit link edit_url = reverse('admin:contacts_contacts_change', args=[self.contacts.id]) self.assertIn(edit_url, response.content) # if there are more than 1 contacts, should return the first contacts = \ Contacts(name="Myname", lastname="Mylastname", email="myemail", date_of_birth=datetime.today(), jabber_id="myjabber", skype_login="******", bio="bio!", other_contacts="blabla") contacts.save() response = self.client.get(self.url) self.assertEqual(response.context['contacts'].id, 1) # should render 'No contacts.' if aren't any Contacts.objects.all().delete() response = self.client.get(self.url) self.assertIn('No contacts.', response.content)