Hi Russ, Thank you very much for your advice. I’ll look into debugging and see how to resolve it:)
Many thanks, Kim On 2014年6月23日 at 11:54:39, Russell Keith-Magee (russ...@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. Yours Russ Magee %-) On Mon, Jun 23, 2014 at 9:28 AM, Kim <kimitak...@gmail.com> wrote: Anyone? Help! 2014年6月21日土曜日 19時29分26秒 UTC+9 Kim: 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 test Creating 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_post self.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_post self.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_login self.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_logout self.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_index self.assertTrue(post.title in response.content) AssertionError: False is not true ---------------------------------------------------------------------- Ran 7 tests in 1.011s FAILED (failures=5) Destroying test database for alias 'default'... ----- My test.py code is below: ---- from django.test import TestCase, LiveServerTestCase, Client from django.utils import timezone from .models import Post class PostTest(TestCase): def test_create_post(self): # Create the post post = 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 page response = self.client.get('/admin/') # Check response code self.assertEquals(response.status_code, 302) # Check 'Log in' in response self.assertTrue('Log in' in response.content) # Log the user in self.client.login(username='bobsmith', password="password") # Check response code response = self.client.get('/admin/') self.assertEquals(response.status_code, 200) # Check 'Log out' in response self.assertTrue('Log out' in response.content) def test_logout(self): # Log in self.client.login(username='bobsmith', password="password") # Check response code response = self.client.get('/admin/') self.assertEquals(response.status_code, 302) # Check 'Log out' in response self.assertTrue('Log out' in response.content) # Log out self.client.logout() # Check response code response = self.client.get('/admin/') self.assertEquals(response.status_code, 200) # Check 'Log in' in response self.assertTrue('Log in' in response.content) def test_create_post(self): # Log in self.client.login(username='bobsmith', password="password") # Check response code response = self.client.get('/admin/blogengine/post/add/') self.assertEquals(response.status_code, 200) # Create the new post response = 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 successfully self.assertTrue('added successfully' in response.content) # Check new post now in database all_posts = Post.objects.all() self.assertEquals(len(all_posts), 1) def test_edit_post(self): # Create the post post = Post() post.title = 'My first post' post.text = 'This is my first blog post' post.pub_date = timezone.now() post.save() # Log in self.client.login(username='bobsmith', password="password") # Edit the post response = 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 successfully self.assertTrue('changed successfully' in response.content) # Check post amended all_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 post post = Post() post.title = 'My first post' post.text = 'This is my first blog post' post.pub_date = timezone.now() post.save() # Check new post saved all_posts = Post.objects.all() self.assertEquals(len(all_posts), 1) # Log in self.client.login(username='bobsmith', password="password") # Delete the post response = self.client.post('/admin/blogengine/post/1/delete/', { 'post': 'yes' }, follow=True) self.assertEquals(response.status_code, 200) # Check deleted successfully self.assertTrue('deleted successfully' in response.content) # Check post amended all_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 post post = Post() post.title = 'My first post' post.text = 'This is my first blog post' post.pub_date = timezone.now() post.save() # Check new post saved all_posts = Post.objects.all() self.assertEquals(len(all_posts), 1) # Fetch the index response = self.client.get('/') self.assertEquals(response.status_code, 200) # Check the post title is in the response self.assertTrue(post.title in response.content) # Check the post text is in the response self.assertTrue(post.text in response.content) # Check the post date is in the response self.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+unsubscr...@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/26606444-5c92-456a-8975-709b9bae3751%40googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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+unsubscr...@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. -- 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+unsubscr...@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/etPan.53a8c693.1d4ed43b.23f%40kimitaka-nakazawa.local. For more options, visit https://groups.google.com/d/optout.