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 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_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.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.
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.
No comments:
Post a Comment