Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
0985be6
feat: add github-actions demo
matheus-dev-fullstack May 12, 2024
6ca601a
Removendo autenticações desnecessárias
matheus-dev-fullstack May 12, 2024
51f4f95
Atualizando credenciais e renomeando variáveis
matheus-dev-fullstack May 12, 2024
cdd98af
Revisando test_viewsets
matheus-dev-fullstack May 14, 2024
f840407
Configurando build para github actions
matheus-dev-fullstack May 19, 2024
d525c71
Ajustando build para github actions
matheus-dev-fullstack May 19, 2024
a3ec982
Github Actions - Atualizando poetry para corrigir importação\
matheus-dev-fullstack May 19, 2024
1a4c9f4
Github Actions - Teste de alteração de versão do poetry
matheus-dev-fullstack May 19, 2024
9266ee0
Github Actions - Teste de alteração de versão do poetry
matheus-dev-fullstack May 19, 2024
b0827da
Github Actions - Teste de alteração de versão do poetry
matheus-dev-fullstack May 19, 2024
8097022
Github Actions - Teste de alteração de versão do poetry
matheus-dev-fullstack May 19, 2024
2606d6d
Github Actions - Teste de alteração de versão do poetry
matheus-dev-fullstack May 19, 2024
e6858b8
Github Actions - Alterando versão das dependencias no pyproject.toml
matheus-dev-fullstack May 19, 2024
2e57690
Congiurando ALLOWED_HOSTS em settings.py
matheus-dev-fullstack May 19, 2024
976aed2
Corrigindo Viewsets, e testes
matheus-dev-fullstack May 20, 2024
d85e7a4
Sinalizando requirements.txt para exercício EBAC
matheus-dev-fullstack May 22, 2024
3ba5c53
Teste de automação de Code Review
matheus-dev-fullstack May 23, 2024
d7335af
Exercício EBAC Integração Contínua
matheus-dev-fullstack May 23, 2024
62f7736
Ajustando README.md
matheus-dev-fullstack May 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Python application

on: [push]

jobs:
build:
strategy:
fail-fast: false
matrix:
python-version: [3.8, 3.9]
poetry-version: [1.1.4]

runs-on: ubuntu-latest

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 poetry ${{ matrix.poetry-version }}
run: |
curl -sSL https://install.python-poetry.org | python3 -
echo "$HOME/.local/bin" >> $GITHUB_PATH


- name: View poetry --help
run: poetry --help

- name: Install dependencies
run: poetry install

- name: Test
run: |
poetry run python manage.py test
17 changes: 17 additions & 0 deletions .github/workflows/github-actions-demo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: GitHub Actions Demo
on: [push]
jobs:
Explore-GitHub-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v2
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."
38 changes: 38 additions & 0 deletions .github/workflows/workflow-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Exercício EBAC - Github Actions and Code Review Automation
name: Python Pull Request Workflow
on: [pull_request]
jobs:
qa:
name: Quality check
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v1
- name: Set up Python
uses: actions/setup-python@master
with:
python-version: 3.8
- name: Install poetry
run: |
pip install -U pip
pip install poetry
poetry install
env:
POETRY_VIRTUALENVS_CREATE: false

- name: View poetry --help
run: poetry --help

- name: Install dependencies
shell: bash
run: python -m poetry install

- name: Test
run: |
poetry run python manage.py test
- name: Wemake Python Stylguide
uses: wemake-services/wemake-python-styleguide@0.16.0
continue-on-error: true
with:
reporter: 'github-pr-review'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Bookstore

Bookstore APP from Backend Python course from EBAC

## Prerequisites

```
Python 3.5>
Poetry
Docker && docker-compose
```

## Quickstart

1. Clone this project

```shell
git clone git@github.com:drsantos20/bookstore.git
```

2. Install dependencies:

```shell
cd bookstore
poetry install
```

3. Run local dev server:

```shell
poetry run manage.py migrate
poetry run python manage.py runserver
```

4. Run docker dev server environment:

```shell
docker-compose up -d --build
docker-compose exec web python manage.py migrate
```

5. Run tests inside of docker:

```shell
docker-compose exec web python manage.py test
18 changes: 0 additions & 18 deletions README.me

This file was deleted.

Binary file modified bookstore/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file modified bookstore/__pycache__/settings.cpython-312.pyc
Binary file not shown.
Binary file modified bookstore/__pycache__/urls.cpython-312.pyc
Binary file not shown.
Binary file modified bookstore/__pycache__/wsgi.cpython-312.pyc
Binary file not shown.
37 changes: 20 additions & 17 deletions bookstore/settings.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""
Django settings for bookstore project.

Generated by 'django-admin startproject' using Django 5.0.3.
Generated by 'django-admin startproject' using Django 3.2.8.

For more information on this file, see
https://docs.djangoproject.com/en/5.0/topics/settings/
https://docs.djangoproject.com/en/3.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.0/ref/settings/
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

import os
Expand All @@ -18,10 +18,10 @@


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-ytvw$u%b^9xle0&yw3*%=$s2zz@spz94k*%*88xr50s$dggo#e"
SECRET_KEY = "django-insecure-f*k@=53bc5!shef1-6w+m$-g)kspbaljz%8k4(j7iuc-u2_dyd"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
Expand All @@ -39,9 +39,9 @@
"django.contrib.messages",
"django.contrib.staticfiles",
"django_extensions",
"rest_framework",
"order",
"product",
"rest_framework",
"debug_toolbar",
"rest_framework.authtoken",
]
Expand Down Expand Up @@ -79,7 +79,7 @@


# Database
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

DATABASES = {
"default": {
Expand All @@ -92,9 +92,8 @@
}
}


# Password validation
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
Expand All @@ -113,27 +112,30 @@


# Internationalization
# https://docs.djangoproject.com/en/5.0/topics/i18n/
# https://docs.djangoproject.com/en/3.2/topics/i18n/

LANGUAGE_CODE = "en-us"

TIME_ZONE = "UTC"

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/
# https://docs.djangoproject.com/en/3.2/howto/static-files/

STATIC_URL = "static/"
STATIC_URL = "/static/"

# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"


REST_FRAMEWORK = {
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
"PAGE_SIZE": 5,
Expand All @@ -148,11 +150,12 @@
"127.0.0.1",
]

SECRET_KEY = os.environ.get("SECRET_KEY")
# SECRET_KEY = os.environ.get("SECRET_KEY")

DEBUG = int(os.environ.get("DEBUG", default=0))
# DEBUG = int(os.environ.get("DEBUG", default=0))

# 'DJANGO_ALLOWED_HOSTS' should be a single string os hosts with a space between each.
# 'DJANGO_ALLOWED_HOSTS' should be a single string of hosts with a space between each.
# For example: 'DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1]'
# ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS").split(" ")

ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS").split(" ")
ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'ebac-bookstore-api.herokuapp.com']
Binary file modified db.sqlite3
Binary file not shown.
31 changes: 13 additions & 18 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
version: '3.9'

services:
db:
image: postgres:13.0-alpine
ports:
- 5432:5432
volumes:
- postgres_data:/var/lib/postgresql/data/
environment:
- POSTGRES_USER=bookstore_dev
- POSTGRES_PASSWORD=bookstore_dev
- POSTGRES_DB=bookstore_dev_db
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/usr/src/app
- app_data:/usr/src/app/
ports:
- 8000:8000
env_file:
- ./env.dev
networks:
- backend
depends_on:
- db
db:
image: postgres:13.0-alpine
volumes:
- postgres_data:/var/lib/postgresql/data
environment:
- POSTGRES_USER=dev
- POSTGRES_PASSWORD=dev
- POSTGRES_DB=bookstore_db
networks:
- backend

networks:
backend:
driver: bridge

volumes:
postgres_data:
postgres_data:
app_data:
6 changes: 3 additions & 3 deletions env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ DEBUG=1
SECRET_KEY=foo
DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1]
SQL_ENGINE=django.db.backends.postgresql
SQL_DATABASE=bookstore_db
SQL_USER=dev
SQL_PASSWORD=dev
SQL_DATABASE=bookstore_dev_db
SQL_USER=bookstore_dev
SQL_PASSWORD=bookstore_dev
SQL_HOST=db
SQL_PORT=5432
Binary file modified order/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file modified order/__pycache__/admin.cpython-312.pyc
Binary file not shown.
Binary file modified order/__pycache__/apps.cpython-312.pyc
Binary file not shown.
Binary file modified order/__pycache__/factories.cpython-312.pyc
Binary file not shown.
Binary file modified order/__pycache__/urls.cpython-312.pyc
Binary file not shown.
9 changes: 5 additions & 4 deletions order/factories.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import factory

from django.contrib.auth.models import User
from product.factories import ProductFactory

from order.models import Order
from product.factories import ProductFactory



class UserFactory(factory.django.DjangoModelFactory):
email = factory.Faker("email")
username = factory.Faker("user_name")
email = factory.Faker("pystr")
username = factory.Faker("pystr")

class Meta:
model = User
Expand All @@ -21,6 +21,7 @@ class OrderFactory(factory.django.DjangoModelFactory):
def product(self, create, extracted, **kwargs):
if not create:
return

if extracted:
for product in extracted:
self.product.add(product)
Expand Down
Binary file modified order/migrations/__pycache__/0001_initial.cpython-312.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified order/migrations/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file modified order/models/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file modified order/models/__pycache__/order.cpython-312.pyc
Binary file not shown.
Binary file modified order/serializers/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file modified order/serializers/__pycache__/order_serializer.cpython-312.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion order/serializers/order_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def create(self, validated_data):
product_data = validated_data.pop("products_id")
user_data = validated_data.pop("user")

order = Order.objects.create(**validated_data)
order = Order.objects.create(user=user_data)
for product in product_data:
order.product.add(product)

Expand Down
Binary file modified order/tests/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
20 changes: 20 additions & 0 deletions order/tests/test_serializers/test_order_serializer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from django.test import TestCase

from order.factories import OrderFactory, ProductFactory
from order.serializers import OrderSerializer


class TestOrderSerializer(TestCase):
def setUp(self) -> None:
self.product_1 = ProductFactory()
self.product_2 = ProductFactory()

self.order = OrderFactory(product=(self.product_1, self.product_2))
self.order_serializer = OrderSerializer(self.order)

def test_order_serializer(self):
serializer_data = self.order_serializer.data
self.assertEqual(
serializer_data["product"][0]["title"], self.product_1.title)
self.assertEqual(
serializer_data["product"][1]["title"], self.product_2.title)
Binary file modified order/tests/test_viewsets/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading