Advertisement
matacoder

Untitled

Sep 5th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 32.31 KB | None | 0 0
  1. (venv) matakov@MBPD hw05_final % source venv/bin/activate
  2. (venv) matakov@MBPD hw05_final % pytest                  
  3. ================================================================== test session starts ===================================================================
  4. platform darwin -- Python 3.8.3, pytest-5.3.5, py-1.8.1, pluggy-0.13.1 -- /Users/matakov/Dev/hw05_final/venv/bin/python
  5. django: settings: yatube.settings (from ini)
  6. rootdir: /Users/matakov/Dev/hw05_final, inifile: pytest.ini, testpaths: tests/
  7. plugins: django-3.8.0
  8. collected 21 items                                                                                                                                      
  9.  
  10. tests/test_comment.py::TestComment::test_comment_add_view FAILED                                                                                   [  4%]
  11. tests/test_comment.py::TestComment::test_comment_add_auth_view PASSED                                                                              [  9%]
  12. tests/test_follow.py::TestFollow::test_follow_not_auth PASSED                                                                                      [ 14%]
  13. tests/test_follow.py::TestFollow::test_follow_auth FAILED                                                                                          [ 19%]
  14. tests/test_homework.py::TestPost::test_post_create PASSED                                                                                          [ 23%]
  15. tests/test_homework.py::TestGroup::test_group_create PASSED                                                                                        [ 28%]
  16. tests/test_homework.py::TestGroupView::test_group_view FAILED                                                                                      [ 33%]
  17. tests/test_new.py::TestNewView::test_new_view_get PASSED                                                                                           [ 38%]
  18. tests/test_new.py::TestNewView::test_new_view_post PASSED                                                                                          [ 42%]
  19. tests/test_paginator.py::TestGroupPaginatorView::test_group_paginator_view_get FAILED                                                              [ 47%]
  20. tests/test_paginator.py::TestGroupPaginatorView::test_index_paginator_view_get FAILED                                                              [ 52%]
  21. tests/test_post.py::TestPostView::test_post_view_get PASSED                                                                                        [ 57%]
  22. tests/test_post.py::TestPostEditView::test_post_edit_view_get PASSED                                                                               [ 61%]
  23. tests/test_post.py::TestPostEditView::test_post_edit_view_author_get PASSED                                                                        [ 66%]
  24. tests/test_post.py::TestPostEditView::test_post_edit_view_author_post PASSED                                                                       [ 71%]
  25. tests/test_profile.py::TestProfileView::test_profile_view_get FAILED                                                                               [ 76%]
  26. tests/test_comment.py::TestComment::test_comment_model PASSED                                                                                      [ 80%]
  27. tests/test_follow.py::TestFollow::test_follow PASSED                                                                                               [ 85%]
  28. tests/test_homework.py::TestPost::test_post_model PASSED                                                                                           [ 90%]
  29. tests/test_homework.py::TestPost::test_post_admin PASSED                                                                                           [ 95%]
  30. tests/test_homework.py::TestGroup::test_group_model PASSED                                                                                         [100%]
  31.  
  32. ======================================================================== FAILURES ========================================================================
  33. ___________________________________________________________ TestComment.test_comment_add_view ____________________________________________________________
  34.  
  35. self = <tests.test_comment.TestComment object at 0x10a7aad00>, client = <django.test.client.Client object at 0x10afcd5b0>
  36. post = <Post: Публикация от 2020-09-05 00:00 автора TestUser создана (Тестовый пост )>
  37.  
  38.     @pytest.mark.django_db(transaction=True)
  39.     def test_comment_add_view(self, client, post):
  40.         try:
  41.             response = client.get(f'/{post.author.username}/{post.id}/comment')
  42.         except Exception as e:
  43.             assert False, f'''Страница `/<username>/<post_id>/comment/` работает неправильно. Ошибка: `{e}`'''
  44.         if response.status_code in (301, 302) and response.url == f'/{post.author.username}/{post.id}/comment/':
  45.             url = f'/{post.author.username}/{post.id}/comment/'
  46.         else:
  47.             url = f'/{post.author.username}/{post.id}/comment'
  48.         assert response.status_code != 404, \
  49.             'Страница `/<username>/<post_id>/comment/` не найдена, проверьте этот адрес в *urls.py*'
  50.    
  51. >       response = client.post(url, data={'text': 'Новый коммент!'})
  52.  
  53. tests/test_comment.py:75:
  54. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  55. venv/lib/python3.8/site-packages/django/test/client.py:543: in post
  56.     response = super().post(path, data=data, content_type=content_type, secure=secure, **extra)
  57. venv/lib/python3.8/site-packages/django/test/client.py:356: in post
  58.     return self.generic('POST', path, post_data, content_type,
  59. venv/lib/python3.8/site-packages/django/test/client.py:422: in generic
  60.     return self.request(**r)
  61. venv/lib/python3.8/site-packages/django/test/client.py:503: in request
  62.     raise exc_value
  63. venv/lib/python3.8/site-packages/django/core/handlers/exception.py:34: in inner
  64.     response = get_response(request)
  65. venv/lib/python3.8/site-packages/django/core/handlers/base.py:115: in _get_response
  66.     response = self.process_exception_by_middleware(e, request)
  67. venv/lib/python3.8/site-packages/django/core/handlers/base.py:113: in _get_response
  68.     response = wrapped_callback(request, *callback_args, **callback_kwargs)
  69. posts/views.py:40: in add_comment
  70.     form.instance.author = request.user
  71. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  72.  
  73. self = <django.db.models.fields.related_descriptors.ForwardManyToOneDescriptor object at 0x10a5fc850>
  74. instance = <[AttributeError("'NoneType' object has no attribute 'date'") raised in repr()] Comment object at 0x10af3fd90>
  75. value = <SimpleLazyObject: <django.contrib.auth.models.AnonymousUser object at 0x10adef1c0>>
  76.  
  77.     def __set__(self, instance, value):
  78.         """
  79.        Set the related instance through the forward relation.
  80.    
  81.        With the example above, when setting ``child.parent = parent``:
  82.    
  83.        - ``self`` is the descriptor managing the ``parent`` attribute
  84.        - ``instance`` is the ``child`` instance
  85.        - ``value`` is the ``parent`` instance on the right of the equal sign
  86.        """
  87.         # An object must be an instance of the related class.
  88.         if value is not None and not isinstance(value, self.field.remote_field.model._meta.concrete_model):
  89. >           raise ValueError(
  90.                 'Cannot assign "%r": "%s.%s" must be a "%s" instance.' % (
  91.                     value,
  92.                     instance._meta.object_name,
  93.                     self.field.name,
  94.                     self.field.remote_field.model._meta.object_name,
  95.                 )
  96. E               ValueError: Cannot assign "<SimpleLazyObject: <django.contrib.auth.models.AnonymousUser object at 0x10adef1c0>>": "Comment.author" must be a "User" instance.
  97.  
  98. venv/lib/python3.8/site-packages/django/db/models/fields/related_descriptors.py:206: ValueError
  99. ----------------------------------------------------------------- Captured stdout setup ------------------------------------------------------------------
  100. Operations to perform:
  101.   Synchronize unmigrated apps: messages, staticfiles
  102.   Apply all migrations: admin, auth, contenttypes, flatpages, posts, sessions, sites, thumbnail
  103. Synchronizing apps without migrations:
  104.   Creating tables...
  105.     Running deferred SQL...
  106. Running migrations:
  107.   Applying contenttypes.0001_initial... OK
  108.   Applying auth.0001_initial... OK
  109.   Applying admin.0001_initial... OK
  110.   Applying admin.0002_logentry_remove_auto_add... OK
  111.   Applying admin.0003_logentry_add_action_flag_choices... OK
  112.   Applying contenttypes.0002_remove_content_type_name... OK
  113.   Applying auth.0002_alter_permission_name_max_length... OK
  114.   Applying auth.0003_alter_user_email_max_length... OK
  115.   Applying auth.0004_alter_user_username_opts... OK
  116.   Applying auth.0005_alter_user_last_login_null... OK
  117.   Applying auth.0006_require_contenttypes_0002... OK
  118.   Applying auth.0007_alter_validators_add_error_messages... OK
  119.   Applying auth.0008_alter_user_username_max_length... OK
  120.   Applying auth.0009_alter_user_last_name_max_length... OK
  121.   Applying auth.0010_alter_group_name_max_length... OK
  122.   Applying auth.0011_update_proxy_permissions... OK
  123.   Applying sites.0001_initial... OK
  124.   Applying flatpages.0001_initial... OK
  125.   Applying posts.0001_initial... OK
  126.   Applying posts.0002_auto_20200725_1848... OK
  127.   Applying posts.0003_auto_20200725_1920... OK
  128.   Applying posts.0004_auto_20200725_2002... OK
  129.   Applying posts.0005_auto_20200727_1917... OK
  130.   Applying posts.0006_auto_20200823_1505... OK
  131.   Applying posts.0007_post_image... OK
  132.   Applying posts.0008_comment... OK
  133.   Applying posts.0009_auto_20200904_1952... OK
  134.   Applying posts.0010_follow... OK
  135.   Applying posts.0011_auto_20200905_1612... OK
  136.   Applying sessions.0001_initial... OK
  137.   Applying sites.0002_alter_domain_unique... OK
  138.   Applying thumbnail.0001_initial... OK
  139. ----------------------------------------------------------------- Captured stderr setup ------------------------------------------------------------------
  140. Creating test database for alias 'default' ('file:memorydb_default?mode=memory&cache=shared')...
  141. ------------------------------------------------------------------- Captured log call --------------------------------------------------------------------
  142. ERROR    django.request:log.py:222 Internal Server Error: /TestUser/1/comment
  143. Traceback (most recent call last):
  144.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
  145.     response = get_response(request)
  146.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
  147.     response = self.process_exception_by_middleware(e, request)
  148.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
  149.     response = wrapped_callback(request, *callback_args, **callback_kwargs)
  150.   File "/Users/matakov/Dev/hw05_final/posts/views.py", line 40, in add_comment
  151.     form.instance.author = request.user
  152.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/db/models/fields/related_descriptors.py", line 206, in __set__
  153.     raise ValueError(
  154. ValueError: Cannot assign "<SimpleLazyObject: <django.contrib.auth.models.AnonymousUser object at 0x10adef1c0>>": "Comment.author" must be a "User" instance.
  155. ______________________________________________________________ TestFollow.test_follow_auth _______________________________________________________________
  156.  
  157. self = <tests.test_follow.TestFollow object at 0x10ad3eee0>, user_client = <django.test.client.Client object at 0x10adad1f0>, user = <User: TestUser>
  158. post = <Post: Публикация от 2020-09-05 00:00 автора TestUser создана (Тестовый пост )>
  159.  
  160.     @pytest.mark.django_db(transaction=True)
  161.     def test_follow_auth(self, user_client, user, post):
  162.         assert user.follower.count() == 0, 'Проверьте, что правильно считается подписки'
  163.         self.check_url(user_client, f'/{post.author.username}/follow', '/<username>/follow/')
  164.         assert user.follower.count() == 0, 'Проверьте, что нельзя подписаться на самого себя'
  165.    
  166.         user_1 = get_user_model().objects.create_user(username='TestUser_2344')
  167.         user_2 = get_user_model().objects.create_user(username='TestUser_73485')
  168.    
  169.         self.check_url(user_client, f'/{user_1.username}/follow', '/<username>/follow/')
  170.         assert user.follower.count() == 1, 'Проверьте, что вы можете подписаться на пользователя'
  171.         self.check_url(user_client, f'/{user_1.username}/follow', '/<username>/follow/')
  172.         assert user.follower.count() == 1, 'Проверьте, что вы можете подписаться на пользователя только один раз'
  173.    
  174.         image = tempfile.NamedTemporaryFile(suffix=".jpg").name
  175.         Post.objects.create(text='Тестовый пост 4564534', author=user_1, image=image)
  176.         Post.objects.create(text='Тестовый пост 354745', author=user_1, image=image)
  177.    
  178.         Post.objects.create(text='Тестовый пост 245456', author=user_2, image=image)
  179.         Post.objects.create(text='Тестовый пост 9789', author=user_2, image=image)
  180.         Post.objects.create(text='Тестовый пост 4574', author=user_2, image=image)
  181.    
  182. >       response = self.check_url(user_client, f'/follow', '/follow/')
  183.  
  184. tests/test_follow.py:111:
  185. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  186. tests/test_follow.py:68: in check_url
  187.     response = client.get(f'{url}/')
  188. venv/lib/python3.8/site-packages/django/test/client.py:535: in get
  189.     response = super().get(path, data=data, secure=secure, **extra)
  190. venv/lib/python3.8/site-packages/django/test/client.py:345: in get
  191.     return self.generic('GET', path, secure=secure, **{
  192. venv/lib/python3.8/site-packages/django/test/client.py:422: in generic
  193.     return self.request(**r)
  194. venv/lib/python3.8/site-packages/django/test/client.py:503: in request
  195.     raise exc_value
  196. venv/lib/python3.8/site-packages/django/core/handlers/exception.py:34: in inner
  197.     response = get_response(request)
  198. venv/lib/python3.8/site-packages/django/core/handlers/base.py:115: in _get_response
  199.     response = self.process_exception_by_middleware(e, request)
  200. venv/lib/python3.8/site-packages/django/core/handlers/base.py:113: in _get_response
  201.     response = wrapped_callback(request, *callback_args, **callback_kwargs)
  202. venv/lib/python3.8/site-packages/django/contrib/auth/decorators.py:21: in _wrapped_view
  203.     return view_func(request, *args, **kwargs)
  204. posts/views.py:206: in follow_index
  205.     return render(
  206. venv/lib/python3.8/site-packages/django/shortcuts.py:36: in render
  207.     content = loader.render_to_string(template_name, context, request, using=using)
  208. venv/lib/python3.8/site-packages/django/template/loader.py:61: in render_to_string
  209.     template = get_template(template_name, using=using)
  210. venv/lib/python3.8/site-packages/django/template/loader.py:15: in get_template
  211.     return engine.get_template(template_name)
  212. venv/lib/python3.8/site-packages/django/template/backends/django.py:34: in get_template
  213.     return Template(self.engine.get_template(template_name), self)
  214. venv/lib/python3.8/site-packages/django/template/engine.py:143: in get_template
  215.     template, origin = self.find_template(template_name)
  216. venv/lib/python3.8/site-packages/django/template/engine.py:125: in find_template
  217.     template = loader.get_template(name, skip=skip)
  218. venv/lib/python3.8/site-packages/django/template/loaders/cached.py:54: in get_template
  219.     template = super().get_template(template_name, skip)
  220. venv/lib/python3.8/site-packages/django/template/loaders/base.py:29: in get_template
  221.     return Template(
  222. venv/lib/python3.8/site-packages/django/template/base.py:156: in __init__
  223.     self.nodelist = self.compile_nodelist()
  224. venv/lib/python3.8/site-packages/django/template/base.py:194: in compile_nodelist
  225.     return parser.parse()
  226. venv/lib/python3.8/site-packages/django/template/base.py:478: in parse
  227.     raise self.error(token, e)
  228. venv/lib/python3.8/site-packages/django/template/base.py:476: in parse
  229.     compiled_result = compile_func(self, token)
  230. venv/lib/python3.8/site-packages/django/template/loader_tags.py:266: in do_extends
  231.     nodelist = parser.parse()
  232. venv/lib/python3.8/site-packages/django/template/base.py:478: in parse
  233.     raise self.error(token, e)
  234. venv/lib/python3.8/site-packages/django/template/base.py:476: in parse
  235.     compiled_result = compile_func(self, token)
  236. venv/lib/python3.8/site-packages/django/template/loader_tags.py:209: in do_block
  237.     nodelist = parser.parse(('endblock',))
  238. venv/lib/python3.8/site-packages/django/template/base.py:483: in parse
  239.     self.unclosed_block_tag(parse_until)
  240. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  241.  
  242. self = <django.template.base.Parser object at 0x10b2957f0>, parse_until = ('endblock',)
  243.  
  244.     def unclosed_block_tag(self, parse_until):
  245.         command, token = self.command_stack.pop()
  246.         msg = "Unclosed tag on line %d: '%s'. Looking for one of: %s." % (
  247.             token.lineno,
  248.             command,
  249.             ', '.join(parse_until),
  250.         )
  251. >       raise self.error(token, msg)
  252. E       django.template.exceptions.TemplateSyntaxError: Unclosed tag on line 4: 'block'. Looking for one of: endblock.
  253.  
  254. venv/lib/python3.8/site-packages/django/template/base.py:544: TemplateSyntaxError
  255. ------------------------------------------------------------------- Captured log call --------------------------------------------------------------------
  256. ERROR    django.request:log.py:222 Internal Server Error: /follow/
  257. Traceback (most recent call last):
  258.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
  259.     response = get_response(request)
  260.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
  261.     response = self.process_exception_by_middleware(e, request)
  262.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
  263.     response = wrapped_callback(request, *callback_args, **callback_kwargs)
  264.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
  265.     return view_func(request, *args, **kwargs)
  266.   File "/Users/matakov/Dev/hw05_final/posts/views.py", line 206, in follow_index
  267.     return render(
  268.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/shortcuts.py", line 36, in render
  269.     content = loader.render_to_string(template_name, context, request, using=using)
  270.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/template/loader.py", line 61, in render_to_string
  271.     template = get_template(template_name, using=using)
  272.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/template/loader.py", line 15, in get_template
  273.     return engine.get_template(template_name)
  274.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/template/backends/django.py", line 34, in get_template
  275.     return Template(self.engine.get_template(template_name), self)
  276.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/template/engine.py", line 143, in get_template
  277.     template, origin = self.find_template(template_name)
  278.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/template/engine.py", line 125, in find_template
  279.     template = loader.get_template(name, skip=skip)
  280.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/template/loaders/cached.py", line 54, in get_template
  281.     template = super().get_template(template_name, skip)
  282.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/template/loaders/base.py", line 29, in get_template
  283.     return Template(
  284.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/template/base.py", line 156, in __init__
  285.     self.nodelist = self.compile_nodelist()
  286.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/template/base.py", line 194, in compile_nodelist
  287.     return parser.parse()
  288.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/template/base.py", line 478, in parse
  289.     raise self.error(token, e)
  290.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/template/base.py", line 476, in parse
  291.     compiled_result = compile_func(self, token)
  292.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/template/loader_tags.py", line 266, in do_extends
  293.     nodelist = parser.parse()
  294.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/template/base.py", line 478, in parse
  295.     raise self.error(token, e)
  296.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/template/base.py", line 476, in parse
  297.     compiled_result = compile_func(self, token)
  298.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/template/loader_tags.py", line 209, in do_block
  299.     nodelist = parser.parse(('endblock',))
  300.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/template/base.py", line 483, in parse
  301.     self.unclosed_block_tag(parse_until)
  302.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/template/base.py", line 544, in unclosed_block_tag
  303.     raise self.error(token, msg)
  304. django.template.exceptions.TemplateSyntaxError: Unclosed tag on line 4: 'block'. Looking for one of: endblock.
  305. _____________________________________________________________ TestGroupView.test_group_view ______________________________________________________________
  306.  
  307. self = <tests.test_homework.TestGroupView object at 0x10b479580>, client = <django.test.client.Client object at 0x10b267730>
  308. post_with_group = <Post: Публикация от 2020-09-05 00:00 автора TestUser создана (Тестовый пост )>
  309.  
  310.     @pytest.mark.django_db(transaction=True)
  311.     def test_group_view(self, client, post_with_group):
  312.         try:
  313.             response = client.get(f'/group/{post_with_group.group.slug}')
  314.         except Exception as e:
  315.             assert False, f'''Страница `/group/<slug>/` работает неправильно. Ошибка: `{e}`'''
  316.         if response.status_code in (301, 302):
  317.             response = client.get(f'/group/{post_with_group.group.slug}/')
  318.         if response.status_code == 404:
  319. >           assert False, 'Страница `/group/<slug>/` не найдена, проверьте этот адрес в *urls.py*'
  320. E           AssertionError: Страница `/group/<slug>/` не найдена, проверьте этот адрес в *urls.py*
  321. E           assert False
  322.  
  323. tests/test_homework.py:170: AssertionError
  324. ------------------------------------------------------------------- Captured log call --------------------------------------------------------------------
  325. WARNING  django.request:log.py:222 Not Found: /group/test-link/
  326. __________________________________________________ TestGroupPaginatorView.test_group_paginator_view_get __________________________________________________
  327.  
  328. self = <tests.test_paginator.TestGroupPaginatorView object at 0x10b32e970>, client = <django.test.client.Client object at 0x10b519d90>
  329. post_with_group = <Post: Публикация от 2020-09-05 00:00 автора TestUser создана (Тестовый пост )>
  330.  
  331.     @pytest.mark.django_db(transaction=True)
  332.     def test_group_paginator_view_get(self, client, post_with_group):
  333.         try:
  334.             response = client.get(f'/group/{post_with_group.group.slug}')
  335.         except Exception as e:
  336.             assert False, f'''Страница `/group/<slug>/` работает неправильно. Ошибка: `{e}`'''
  337.         if response.status_code in (301, 302):
  338.             response = client.get(f'/group/{post_with_group.group.slug}/')
  339. >       assert response.status_code != 404, 'Страница `/group/<slug>/` не найдена, проверьте этот адрес в *urls.py*'
  340. E       AssertionError: Страница `/group/<slug>/` не найдена, проверьте этот адрес в *urls.py*
  341. E       assert 404 != 404
  342. E        +  where 404 = <HttpResponse status_code=404, "text/html; charset=utf-8">.status_code
  343.  
  344. tests/test_paginator.py:16: AssertionError
  345. ------------------------------------------------------------------- Captured log call --------------------------------------------------------------------
  346. WARNING  django.request:log.py:222 Not Found: /group/test-link/
  347. __________________________________________________ TestGroupPaginatorView.test_index_paginator_view_get __________________________________________________
  348.  
  349. self = <tests.test_paginator.TestGroupPaginatorView object at 0x10b52ad90>, client = <django.test.client.Client object at 0x10b523f40>
  350. post_with_group = <Post: Публикация от 2020-09-05 00:00 автора TestUser создана (Тестовый пост )>
  351.  
  352.     @pytest.mark.django_db(transaction=True)
  353.     def test_index_paginator_view_get(self, client, post_with_group):
  354.         response = client.get(f'/')
  355. >       assert response.status_code != 404, 'Страница `/` не найдена, проверьте этот адрес в *urls.py*'
  356. E       AssertionError: Страница `/` не найдена, проверьте этот адрес в *urls.py*
  357. E       assert 404 != 404
  358. E        +  where 404 = <HttpResponse status_code=404, "text/html; charset=utf-8">.status_code
  359.  
  360. tests/test_paginator.py:30: AssertionError
  361. ------------------------------------------------------------------- Captured log call --------------------------------------------------------------------
  362. WARNING  django.request:log.py:222 Not Found: /
  363. _________________________________________________________ TestProfileView.test_profile_view_get __________________________________________________________
  364.  
  365. self = <tests.test_profile.TestProfileView object at 0x10b531c70>, client = <django.test.client.Client object at 0x10b5b3910>
  366. post_with_group = <Post: Публикация от 2020-09-05 00:00 автора TestUser создана (Тестовый пост )>
  367.  
  368.     @pytest.mark.django_db(transaction=True)
  369.     def test_profile_view_get(self, client, post_with_group):
  370.         try:
  371.             response = client.get(f'/{post_with_group.author.username}')
  372.         except Exception as e:
  373.             assert False, f'''Страница `/<username>/` работает неправильно. Ошибка: `{e}`'''
  374.         if response.status_code in (301, 302):
  375. >           response = client.get(f'/{post_with_group.author.username}/')
  376.  
  377. tests/test_profile.py:23:
  378. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  379. venv/lib/python3.8/site-packages/django/test/client.py:535: in get
  380.     response = super().get(path, data=data, secure=secure, **extra)
  381. venv/lib/python3.8/site-packages/django/test/client.py:345: in get
  382.     return self.generic('GET', path, secure=secure, **{
  383. venv/lib/python3.8/site-packages/django/test/client.py:422: in generic
  384.     return self.request(**r)
  385. venv/lib/python3.8/site-packages/django/test/client.py:503: in request
  386.     raise exc_value
  387. venv/lib/python3.8/site-packages/django/core/handlers/exception.py:34: in inner
  388.     response = get_response(request)
  389. venv/lib/python3.8/site-packages/django/core/handlers/base.py:115: in _get_response
  390.     response = self.process_exception_by_middleware(e, request)
  391. venv/lib/python3.8/site-packages/django/core/handlers/base.py:113: in _get_response
  392.     response = wrapped_callback(request, *callback_args, **callback_kwargs)
  393. posts/views.py:109: in profile
  394.     if Follow.objects.filter(user=user, author=author):
  395. venv/lib/python3.8/site-packages/django/db/models/manager.py:82: in manager_method
  396.     return getattr(self.get_queryset(), name)(*args, **kwargs)
  397. venv/lib/python3.8/site-packages/django/db/models/query.py:892: in filter
  398.     return self._filter_or_exclude(False, *args, **kwargs)
  399. venv/lib/python3.8/site-packages/django/db/models/query.py:910: in _filter_or_exclude
  400.     clone.query.add_q(Q(*args, **kwargs))
  401. venv/lib/python3.8/site-packages/django/db/models/sql/query.py:1290: in add_q
  402.     clause, _ = self._add_q(q_object, self.used_aliases)
  403. venv/lib/python3.8/site-packages/django/db/models/sql/query.py:1315: in _add_q
  404.     child_clause, needed_inner = self.build_filter(
  405. venv/lib/python3.8/site-packages/django/db/models/sql/query.py:1224: in build_filter
  406.     self.check_related_objects(join_info.final_field, value, join_info.opts)
  407. venv/lib/python3.8/site-packages/django/db/models/sql/query.py:1086: in check_related_objects
  408.     for v in value:
  409. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  410.  
  411. self = <SimpleLazyObject: <django.contrib.auth.models.AnonymousUser object at 0x10b55d700>>, args = ()
  412.  
  413.     def inner(self, *args):
  414.         if self._wrapped is empty:
  415.             self._setup()
  416. >       return func(self._wrapped, *args)
  417. E       TypeError: 'AnonymousUser' object is not iterable
  418.  
  419. venv/lib/python3.8/site-packages/django/utils/functional.py:257: TypeError
  420. ------------------------------------------------------------------- Captured log call --------------------------------------------------------------------
  421. ERROR    django.request:log.py:222 Internal Server Error: /TestUser/
  422. Traceback (most recent call last):
  423.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
  424.     response = get_response(request)
  425.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
  426.     response = self.process_exception_by_middleware(e, request)
  427.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
  428.     response = wrapped_callback(request, *callback_args, **callback_kwargs)
  429.   File "/Users/matakov/Dev/hw05_final/posts/views.py", line 109, in profile
  430.     if Follow.objects.filter(user=user, author=author):
  431.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/db/models/manager.py", line 82, in manager_method
  432.     return getattr(self.get_queryset(), name)(*args, **kwargs)
  433.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/db/models/query.py", line 892, in filter
  434.     return self._filter_or_exclude(False, *args, **kwargs)
  435.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/db/models/query.py", line 910, in _filter_or_exclude
  436.     clone.query.add_q(Q(*args, **kwargs))
  437.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1290, in add_q
  438.     clause, _ = self._add_q(q_object, self.used_aliases)
  439.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1315, in _add_q
  440.     child_clause, needed_inner = self.build_filter(
  441.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1224, in build_filter
  442.     self.check_related_objects(join_info.final_field, value, join_info.opts)
  443.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1086, in check_related_objects
  444.     for v in value:
  445.   File "/Users/matakov/Dev/hw05_final/venv/lib/python3.8/site-packages/django/utils/functional.py", line 257, in inner
  446.     return func(self._wrapped, *args)
  447. TypeError: 'AnonymousUser' object is not iterable
  448. ============================================================== 6 failed, 15 passed in 5.11s ==============================================================
  449. (venv) matakov@MBPD hw05_final %
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement