Skip to content

Commit

Permalink
По рез. ревью 2
Browse files Browse the repository at this point in the history
  • Loading branch information
esaviv committed Jan 15, 2023
1 parent fd022eb commit 907e7ba
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 19 deletions.
5 changes: 5 additions & 0 deletions yatube/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ def page_not_found(request, exception):

def csrf_failure(request, reason=''):
return render(request, 'core/403csrf.html')


def server_error(request):
return render(request, "core/500.html",
status=HTTPStatus.INTERNAL_SERVER_ERROR)
36 changes: 22 additions & 14 deletions yatube/posts/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.test import Client, TestCase, override_settings
from django.urls import reverse
from posts.forms import CommentForm, PostForm
from posts.models import Comment, Group, Post
from posts.models import Comment, Group, Post, Follow

User = get_user_model()

Expand Down Expand Up @@ -226,8 +226,10 @@ def test_index_cache(self):

def test_post_exists_at_followed(self):
"""Пост появляется у тех, кто подписан."""
self.authorized_client.get(
reverse("posts:profile_follow", kwargs={"username": self.auth}))
Follow.objects.create(
user=self.user,
author=self.auth
)
response = self.authorized_client.get(reverse("posts:follow_index"))
posts = response.context["page_obj"]
self.assertEqual(len(posts), 1)
Expand All @@ -240,28 +242,34 @@ def test_post_not_exists_at_no_followed(self):

def test_authorized_client_can_follow(self):
"""Авторизованной пользователь может подписаться."""
self.authorized_client.get(
reverse("posts:profile_follow", kwargs={"username": self.auth}))
Follow.objects.create(
user=self.user,
author=self.auth
)

count_follows = self.auth.following.count()
count_follows = Follow.objects.count()
self.assertEqual(count_follows, 1)

follow = self.auth.following.get()
follow = Follow.objects.first()
follow_attributes = {
follow.user: follow.user,
follow.author: follow.author,
follow.user: self.user,
follow.author: self.auth,
}
for attribute, value in follow_attributes.items():
with self.subTest(attribute=attribute):
self.assertEqual(attribute, value)

def test_authorized_client_can_unfollow(self):
"""Авторизованный пользователь может отписаться."""
self.authorized_client.get(
reverse("posts:profile_follow", kwargs={"username": self.auth}))
Follow.objects.create(
user=self.user,
author=self.auth
)

self.authorized_client.get(
reverse("posts:profile_unfollow", kwargs={"username": self.auth}))
Follow.objects.get(
user=self.user,
author=self.auth
).delete()

count_follows = self.auth.following.count()
count_follows = Follow.objects.count()
self.assertEqual(count_follows, 0)
4 changes: 2 additions & 2 deletions yatube/templates/core/403csrf.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "base.html" %}
{% block title %}Ошибка 403{% endblock %}
{% block content %}
<h1>Доступ к запрошенному ресурсу запрещен</h1>
<p>У Вас недостаточно прав для этого действия...</p>
<h1>О-о! Запрещено</h1>
<p>У Вас недостаточно прав для этого действия</p>
<a href="{% url 'posts:index' %}">Идите на главную</a>
{% endblock %}
2 changes: 1 addition & 1 deletion yatube/templates/core/404.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "base.html" %}
{% block title %}Ошибка 404{% endblock %}
{% block content %}
<h1>O-o! Страница не найдена</h1>
<h1>O-o! Не найдено</h1>
<p>Страницы с адресом {{ path }} не существует</p>
<a href="{% url 'posts:index' %}">Идите на главную</a>
{% endblock %}
7 changes: 7 additions & 0 deletions yatube/templates/core/500.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends "base.html" %}
{% block title %}Ошибка 500{% endblock %}
{% block content %}
<h1>O-o! Внутренняя ошибка сервера</h1>
<p>Дело не в Вас, просто серверу сейчас необходимо побыть одному</p>
<a href="{% url 'posts:index' %}">Попробуйте пойти на главную</a>
{% endblock %}
2 changes: 1 addition & 1 deletion yatube/yatube/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
SECRET_KEY = '9r3gd+c92^d0j3tq5@2mi!$wug05!+tu_xvs6d!=(c57e6wd!f'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = False

ALLOWED_HOSTS = [
'localhost',
Expand Down
3 changes: 2 additions & 1 deletion yatube/yatube/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from django.urls import include, path

handler404 = "core.views.page_not_found"
handler403 = 'core.views.csrf_failure'
handler403 = "core.views.csrf_failure"
handler500 = "core.views.server_error"

urlpatterns = [
path("admin/", admin.site.urls),
Expand Down

0 comments on commit 907e7ba

Please sign in to comment.