Hi Russ,
Thank you very much for your advice.
I'll look into debugging and see how to resolve it:)
Many thanks,
Kim
Kim
On 2014年6月23日 at 11:54:39, Russell Keith-Magee (russell@keith-magee.com) wrote:
Hi Kim,--It seems to me that the error messages you're getting are pretty clear - you're asserting that certain content exists, and it doesn't.I can think of any number of reasons that this might be happening, ranging from a broken template, a mistake in URL resolution, a failed login, to unexpected interactions with the template escaping system. However, without the full code for your system under test, it's impossible to say for certain.However, it shouldn't be that hard to debug on your own. The test is failing because the content you expect isn't what you expected -- so what content *is* being returned? You can, for example, just print the content of response.content. Pick one of the tests, output response.content, and see what you're getting. That will tell you what the web server is doing, and will give you an indication of what is going wrong.YoursRuss Magee %-)
On Mon, Jun 23, 2014 at 9:28 AM, Kim <kimitaka01@gmail.com> wrote:
Anyone? Help!
2014年6月21日土曜日 19時29分26秒 UTC+9 Kim:To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/26606444-5c92-456a-8975-709b9bae3751%40googlegroups.com.--Hi everyone,I am making my blog from this tutorial: http://matthewdaly.co.uk/blog/2013/12/28/django-blog-tutorial-the-next-generation-part-1/.But I am continuously getting the AssertionError messages:-------$ python manage.py testCreating test database for alias 'default'.....FFFFF======================================================================FAIL: test_delete_post (blogengine.tests.AdminTest)----------------------------------------------------------------------Traceback (most recent call last):File "/Users/Desktop/Python/1.7/src/blogengine/tests.py", line 157, in test_delete_postself.assertTrue('deleted successfully' in response.content)AssertionError: False is not true======================================================================FAIL: test_edit_post (blogengine.tests.AdminTest)----------------------------------------------------------------------Traceback (most recent call last):File "/Users/Desktop/Python/1.7/src/blogengine/tests.py", line 126, in test_edit_postself.assertTrue('changed successfully' in response.content)AssertionError: False is not true======================================================================FAIL: test_login (blogengine.tests.AdminTest)----------------------------------------------------------------------Traceback (most recent call last):File "/Users/Desktop/Python/1.7/src/blogengine/tests.py", line 44, in test_loginself.assertTrue('Log in' in response.content)AssertionError: False is not true======================================================================FAIL: test_logout (blogengine.tests.AdminTest)----------------------------------------------------------------------Traceback (most recent call last):File "/Users/Desktop/Python/1.7/src/blogengine/tests.py", line 65, in test_logoutself.assertTrue('Log out' in response.content)AssertionError: False is not true======================================================================FAIL: test_index (blogengine.tests.PostViewTest)----------------------------------------------------------------------Traceback (most recent call last):File "/Users/Desktop/Python/1.7/src/blogengine/tests.py", line 184, in test_indexself.assertTrue(post.title in response.content)AssertionError: False is not true----------------------------------------------------------------------Ran 7 tests in 1.011sFAILED (failures=5)Destroying test database for alias 'default'...-----My test.py code is below:----from django.test import TestCase, LiveServerTestCase, Clientfrom django.utils import timezonefrom .models import Postclass PostTest(TestCase):def test_create_post(self):# Create the postpost = Post()post.title = 'My first post'post.text = 'This is my first blog post'post.pub_date = timezone.now()post.save()all_posts = Post.objects.all()self.assertEquals(len(all_posts), 1)only_post = all_posts[0]self.assertEquals(only_post, post)self.assertEquals(only_post.title, 'My first post')self.assertEquals(only_post.text, 'This is my first blog post')self.assertEquals(only_post.pub_date.day, post.pub_date.day)self.assertEquals(only_post.pub_date.month, post.pub_date.month)self.assertEquals(only_post.pub_date.year, post.pub_date.year)self.assertEquals(only_post.pub_date.hour, post.pub_date.hour)self.assertEquals(only_post.pub_date.minute, post.pub_date.minute)self.assertEquals(only_post.pub_date.second, post.pub_date.second)class AdminTest(LiveServerTestCase):fixtures = ['users.json']def setUp(self):self.client = Client()def test_login(self):# Get login pageresponse = self.client.get('/admin/')# Check response codeself.assertEquals(response.status_code, 302)# Check 'Log in' in responseself.assertTrue('Log in' in response.content)# Log the user inself.client.login(username='bobsmith', password="password")# Check response coderesponse = self.client.get('/admin/')self.assertEquals(response.status_code, 200)# Check 'Log out' in responseself.assertTrue('Log out' in response.content)def test_logout(self):# Log inself.client.login(username='bobsmith', password="password")# Check response coderesponse = self.client.get('/admin/')self.assertEquals(response.status_code, 302)# Check 'Log out' in responseself.assertTrue('Log out' in response.content)# Log outself.client.logout()# Check response coderesponse = self.client.get('/admin/')self.assertEquals(response.status_code, 200)# Check 'Log in' in responseself.assertTrue('Log in' in response.content)def test_create_post(self):# Log inself.client.login(username='bobsmith', password="password")# Check response coderesponse = self.client.get('/admin/blogengine/post/add/')self.assertEquals(response.status_code, 200)# Create the new postresponse = self.client.post('/admin/blogengine/post/add/', {'title': 'My first post','text': 'This is my first post','pub_date_0': '2013-12-28','pub_date_1': '22:00:04'},follow=True)self.assertEquals(response.status_code, 200)# Check added successfullyself.assertTrue('added successfully' in response.content)# Check new post now in databaseall_posts = Post.objects.all()self.assertEquals(len(all_posts), 1)def test_edit_post(self):# Create the postpost = Post()post.title = 'My first post'post.text = 'This is my first blog post'post.pub_date = timezone.now()post.save()# Log inself.client.login(username='bobsmith', password="password")# Edit the postresponse = self.client.post('/admin/blogengine/post/1/', {'title': 'My second post','text': 'This is my second blog post','pub_date_0': '2013-12-28','pub_date_1': '22:00:04'},follow=True)self.assertEquals(response.status_code, 200)# Check changed successfullyself.assertTrue('changed successfully' in response.content)# Check post amendedall_posts = Post.objects.all()self.assertEquals(len(all_posts), 1)only_post = all_posts[0]self.assertEquals(only_post.title, 'My second post')self.assertEquals(only_post.text, 'This is my second blog post')def test_delete_post(self):# Create the postpost = Post()post.title = 'My first post'post.text = 'This is my first blog post'post.pub_date = timezone.now()post.save()# Check new post savedall_posts = Post.objects.all()self.assertEquals(len(all_posts), 1)# Log inself.client.login(username='bobsmith', password="password")# Delete the postresponse = self.client.post('/admin/blogengine/post/1/delete/', {'post': 'yes'}, follow=True)self.assertEquals(response.status_code, 200)# Check deleted successfullyself.assertTrue('deleted successfully' in response.content)# Check post amendedall_posts = Post.objects.all()self.assertEquals(len(all_posts), 0)class PostViewTest(LiveServerTestCase):def setUp(self):self.client = Client()def test_index(self):# Create the postpost = Post()post.title = 'My first post'post.text = 'This is my first blog post'post.pub_date = timezone.now()post.save()# Check new post savedall_posts = Post.objects.all()self.assertEquals(len(all_posts), 1)# Fetch the indexresponse = self.client.get('/')self.assertEquals(response.status_code, 200)# Check the post title is in the responseself.assertTrue(post.title in response.content)# Check the post text is in the responseself.assertTrue(post.text in response.content)# Check the post date is in the responseself.assertTrue(str(post.pub_date.year) in response.content)self.assertTrue(post.pub_date.strftime('%b') in response.content)self.assertTrue(str(post.pub_date.day) in response.content)-----Could anyone know what's wrong?Thanks,Kim
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJxq84-k%3D17FzrgJr9TQ3Zvfi19DEvVv3Q6odM5ZgOtvrk-%3Dsw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment