Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rezi100r committed Feb 15, 2022
0 parents commit 1857742
Show file tree
Hide file tree
Showing 20 changed files with 1,403 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Build and Test

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest
if: ${{ github.repository == 'yandex-praktikum/hw05_final' }}
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Git Clone Action
uses: actions/checkout@v2
with:
repository: ${{ secrets.repository }}
ssh-key: ${{ secrets.ACCESS_TOKEN }}
path: yatube/
- name: Lint with flake8 author
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 yatube --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings
flake8 yatube --count --exit-zero --max-complexity=10 --max-line-length=79 --statistics --config=setup.cfg
- name: Lint with flake8 tests
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 tests --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings
flake8 tests --count --exit-zero --max-complexity=10 --max-line-length=79 --statistics
- name: Test with pytest
env:
SECRET_KEY: "5UP3R-53CR3T-K3Y-FR0M-TurboKach"
DJANGO_SETTINGS_MODULE: yatube.settings
DEBUG: 1
ALLOWED_HOSTS: "*"
run: |
py.test
152 changes: 152 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# Папки, создаваемые средой разработки
.idea
.DS_Store
.AppleDouble
.LSOverride

*.sublime-project
*.sublime-workspace

.vscode/
*.code-workspace

# Local History for Visual Studio Code
.history/

.mypy_cache

# папки со статикой и медиа
static/
yatube/posts/static/
yatube/media/

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# hw05_final

[![CI](https://github.com/yandex-praktikum/hw05_final/actions/workflows/python-app.yml/badge.svg?branch=master)](https://github.com/yandex-praktikum/hw05_final/actions/workflows/python-app.yml)
7 changes: 7 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[pytest]
python_paths = yatube/
DJANGO_SETTINGS_MODULE = yatube.settings
norecursedirs = env/*
addopts = -vv -p no:cacheprovider
testpaths = tests/
python_files = test_*.py
10 changes: 10 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Django==2.2.16
mixer==7.1.2
Pillow==8.3.1
pytest==6.2.4
pytest-django==4.4.0
pytest-pythonpath==0.7.3
requests==2.26.0
six==1.16.0
sorl-thumbnail==12.7.0
Faker==12.0.1
12 changes: 12 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[flake8]
ignore =
W503,
F811
exclude =
tests/,
*/migrations/,
venv/,
env/
per-file-ignores =
*/settings.py:E501
max-complexity = 10
Empty file added tests/__init__.py
Empty file.
39 changes: 39 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
root_dir_content = os.listdir(BASE_DIR)
PROJECT_DIR_NAME = 'yatube'
MANAGE_PATH = os.path.join(BASE_DIR, PROJECT_DIR_NAME)
# проверяем, что в корне репозитория лежит папка с проектом
if (
PROJECT_DIR_NAME not in root_dir_content
or not os.path.isdir(MANAGE_PATH)
):
assert False, (
f'В директории `{BASE_DIR}` не найдена папка c проектом `{PROJECT_DIR_NAME}`. '
f'Убедитесь, что у вас верная структура проекта.'
)

project_dir_content = os.listdir(MANAGE_PATH)
FILENAME = 'manage.py'
# проверяем, что структура проекта верная, и manage.py на месте
if FILENAME not in project_dir_content:
assert False, (
f'В директории `{MANAGE_PATH}` не найден файл `{FILENAME}`. '
f'Убедитесь, что у вас верная структура проекта.'
)

from django.utils.version import get_version

assert get_version() < '3.0.0', 'Пожалуйста, используйте версию Django < 3.0.0'

from yatube.settings import INSTALLED_APPS

assert any(app in INSTALLED_APPS for app in ['posts.apps.PostsConfig', 'posts']), (
'Пожалуйста зарегистрируйте приложение в `settings.INSTALLED_APPS`'
)

pytest_plugins = [
'tests.fixtures.fixture_user',
'tests.fixtures.fixture_data',
]
47 changes: 47 additions & 0 deletions tests/fixtures/fixture_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import tempfile

import pytest
from mixer.backend.django import mixer as _mixer
from posts.models import Post, Group


@pytest.fixture()
def mock_media(settings):
with tempfile.TemporaryDirectory() as temp_directory:
settings.MEDIA_ROOT = temp_directory
yield temp_directory


@pytest.fixture
def mixer():
return _mixer


@pytest.fixture
def post(user):
image = tempfile.NamedTemporaryFile(suffix=".jpg").name
return Post.objects.create(text='Тестовый пост 1', author=user, image=image)


@pytest.fixture
def group():
return Group.objects.create(title='Тестовая группа 1', slug='test-link', description='Тестовое описание группы')


@pytest.fixture
def post_with_group(user, group):
image = tempfile.NamedTemporaryFile(suffix=".jpg").name
return Post.objects.create(text='Тестовый пост 2', author=user, group=group, image=image)


@pytest.fixture
def few_posts_with_group(mixer, user, group):
"""Return one record with the same author and group."""
posts = mixer.cycle(20).blend(Post, author=user, group=group)
return posts[0]


@pytest.fixture
def another_few_posts_with_group_with_follower(mixer, user, another_user, group):
mixer.blend('posts.Follow', user=user, author=another_user)
mixer.cycle(20).blend(Post, author=another_user, group=group)
18 changes: 18 additions & 0 deletions tests/fixtures/fixture_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import pytest


@pytest.fixture
def user(django_user_model):
return django_user_model.objects.create_user(username='TestUser', password='1234567')


@pytest.fixture
def user_client(user, client):
client.force_login(user)
return client


@pytest.fixture
def another_user(mixer):
from django.contrib.auth.models import User
return mixer.blend(User, username='AnotherUser')
17 changes: 17 additions & 0 deletions tests/test_about.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest


class TestTemplateView:

@pytest.mark.django_db(transaction=True)
def test_about_author_tech(self, client):
urls = ['/about/author/', '/about/tech/']
for url in urls:
try:
response = client.get(url)
except Exception as e:
assert False, f'''Страница `{url}` работает неправильно. Ошибка: `{e}`'''
assert response.status_code != 404, f'Страница `{url}` не найдена, проверьте этот адрес в *urls.py*'
assert response.status_code == 200, (
f'Ошибка {response.status_code} при открытиии `{url}`. Проверьте ее view-функцию'
)
17 changes: 17 additions & 0 deletions tests/test_auth_urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest


class TestAuthUrls:

@pytest.mark.django_db(transaction=True)
def test_auth_urls(self, client):
urls = ['/auth/login/', '/auth/logout/', '/auth/signup/']
for url in urls:
try:
response = client.get(url)
except Exception as e:
assert False, f'''Страница `{url}` работает неправильно. Ошибка: `{e}`'''
assert response.status_code != 404, f'Страница `{url}` не найдена, проверьте этот адрес в *urls.py*'
assert response.status_code == 200, (
f'Ошибка {response.status_code} при открытиии `{url}`. Проверьте ее view-функцию'
)
Loading

0 comments on commit 1857742

Please sign in to comment.