Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
- valid login
- format string favourite picture
- redirect user update template
  • Loading branch information
aapetrushkin committed Sep 18, 2023
1 parent 44276ad commit 2e15615
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ max-imports = 14
exclude = .git,__pycache__,.venv,.eggs,*.egg,frontend,landing

# Disable some pydocstyle checks:
ignore = D100, D104, D106, D401, X100, W504, RST303, RST304, DAR103, DAR203, DJ10, DJ11, DJ08
ignore = D100, D104, D106, D401, X100, W504, RST303, RST304, DAR103, DAR203, DJ10, DJ11, DJ08, WPS305

# Docs: https://github.com/snoack/flake8-per-file-ignores
# You can completely or partially disable our custom checks,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_apps/test_identity/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ def test_valid_login(
response = client.get(reverse('index'))

assert response.status_code == HTTPStatus.OK
assert 'Личный кабинет' in response.content.decode('utf-8')
assert 'Личный кабинет'.encode('utf-8') in response.content
23 changes: 23 additions & 0 deletions tests/test_apps/test_identity/test_user_update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from http import HTTPStatus
from typing import TYPE_CHECKING

import pytest
from django.urls import reverse

if TYPE_CHECKING:
from django.test import Client

from server.apps.identity.models import User


@pytest.mark.django_db()
def test_user_update_template(
client: 'Client',
create_user: 'User',
) -> None:
"""Test get template for update user."""
client.force_login(create_user)
response = client.get(reverse('identity:user_update'))

assert response.status_code == HTTPStatus.OK
assert 'Редактировать профиль'.encode('utf-8') in response.content
19 changes: 19 additions & 0 deletions tests/test_apps/test_pictures/test_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest

from server.apps.pictures.models import FavouritePicture

favourite_picture_params = [
(1234567890, 'some_test_foreign_id'),
(1234567890, None),
(None, 'some_test_foreign_id'),
(None, None),
]


@pytest.mark.parametrize(('foreign_id', 'user_id'), favourite_picture_params)
@pytest.mark.django_db()
def test_output_correct_str(foreign_id, user_id):
"""Test that string representation is correct."""
string_format = FavouritePicture(foreign_id=foreign_id, user_id=user_id)

assert str(string_format) == f'<Picture {foreign_id} by {user_id}>'

0 comments on commit 2e15615

Please sign in to comment.