Skip to content

Commit

Permalink
Setup (#9)
Browse files Browse the repository at this point in the history
* reorganized the folders, created the initial setup, and created the base html

* added the make live command

* fixed missing the command in PHONY

* Created pipeline for CI, fixed the requirements of the project and make a new test for testing CI

* Created pipeline for CI, fixed the requirements of the project and make a new test for testing CI

* Fixed the error of requirements.test.txt and removed livereload untill find a way to use it with tests

* Fixed the error of missing pflake on requirements

* Fixed the test, removed --forked from test

* Update views.py
  • Loading branch information
vmagueta authored Jan 6, 2025
1 parent bcd83c0 commit 7ecb568
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 16 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: CI

on:
push:
branches:
- "main"
pull_request:
branches:
- "main"
workflow_dispatch:

jobs:
lint:
strategy:
fail-fast: true
matrix:
python-version: ['3.12']
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}-
- name: Install Project
run: pip install '.[test]'
- name: Look for style errors
run: flake8 app --ignore=F401,F821,E501
- name: Checking for importing style
run: isort --profile=black --check --diff app
- name: Look for auto format errors
run: black --check --diff app

tests:
needs: lint
strategy:
fail-fast: false
matrix:
python-version: ['3.10', '3.12']
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}-
- name: Install Project
run: pip install '.[test]'
- name: Run tests
run: pytest -v --junitxml=test-result.xml
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2.16.1
if: always()
with:
files: test-result.xml
check_name: Test Result (Python ${{ matrix.python-version }})
permissions:
contents: read
issues: read
checks: write
pull-requests: write

4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ ipython:
@.venv/bin/ipython


test:
@.venv/bin/pytest -vs -s


lint:
@.venv/bin/pflake8 app kamila_project

Expand Down
12 changes: 11 additions & 1 deletion app/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import pytest
from django.test import TestCase
from django.urls import reverse

# Create your tests here.

@pytest.mark.unit
def test_acess_index_true(client):
"""
Test if the index view returns a 200 status code when accesseds
"""
url = reverse("index")
response = client.get(url)
assert response.status_code == 200
4 changes: 4 additions & 0 deletions app/views.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
from django.shortcuts import render

from .models import Post


def base(request):
return render(request, "app/base.html")


def index(request):
return render(request, "app/index.html")


def blog(request):
posts = Post.objects.all().order_by("-created_at")
return render(request, "app/blog.html", {"posts": posts})


def post(request):
return render(request, "app/post.html")
24 changes: 11 additions & 13 deletions kamila_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"django.contrib.messages",
"django.contrib.staticfiles",
"app",
"livereload",
# "livereload",
]

MIDDLEWARE = [
Expand All @@ -51,30 +51,28 @@
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"livereload.middleware.LiveReloadScript",
# "livereload.middleware.LiveReloadScript",
]

ROOT_URLCONF = "kamila_project.urls"

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]




WSGI_APPLICATION = "kamila_project.wsgi.application"

# Database
Expand Down
10 changes: 8 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[project]
name = "Terapeuta Kamila Rodrigues"
name = "terapeuta_kamila_rodrigues"
version = "0.1.0"
description = " Official website of Kamila Rodrigues, a professional therapist."
readme = "README.md"
Expand All @@ -8,15 +8,21 @@ authors = [
{ name = "Viana Labs", email = "contacto@vianalabs.pt" }
]
dependencies = [
"flask",
"django",
]

[tool.setuptools.packages]
find = { where = ["app", "kamila_project"] }


[project.optional-dependencies]
test = [
"flake8",
"black",
"isort",
"pytest",
"pytest-django",
# "livereload",
]

[tool.flake8]
Expand Down
7 changes: 7 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[pytest]
DJANGO_SETTINGS_MODULE = kamila_project.settings
python_files = tests.py test_*.py

markers =
unit: marks tests as unit tests.
integration: marks tests as integration tests.
7 changes: 7 additions & 0 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@
ipython
ipdb
pudb
pytest
pytest-watch


# auto reload
# django-livereload
# django-livereload-server


# Code Quality
flake8
pyproject-flake8
Expand Down
7 changes: 7 additions & 0 deletions requirements.test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pytest
pytest-django
flake8
pyproject-flake8
black
isort
mypy

0 comments on commit 7ecb568

Please # to comment.