Skip to content

Commit

Permalink
Merge pull request #2422 from prefeiturasp/release/8.11.0
Browse files Browse the repository at this point in the history
Release/8.11.0
  • Loading branch information
Lucas-Santos-Rocha-dev authored Oct 19, 2023
2 parents 82ee063 + dfd6f5c commit 1491407
Show file tree
Hide file tree
Showing 90 changed files with 3,091 additions and 857 deletions.
13 changes: 5 additions & 8 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,7 @@
# -------------------------------------------------------------------------------
REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": (
"rest_framework_jwt.authentication.JSONWebTokenAuthentication",
# "rest_framework.authentication.TokenAuthentication",
"rest_framework_simplejwt.authentication.JWTAuthentication",
),
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
}
Expand All @@ -300,13 +299,11 @@
'WARNINGS': False,
}

# JWT settings
# SIMPLE JWT settings
# ------------------------------------------------------------------------------
JWT_AUTH = {
# TODO: rever a configuração...
'JWT_EXPIRATION_DELTA': datetime.timedelta(hours=100),
'JWT_REFRESH_EXPIRATION_DELTA': datetime.timedelta(hours=100),
'JWT_ALLOW_REFRESH': True,
SIMPLE_JWT = {
'AUTH_HEADER_TYPES': ('JWT',),
'ACCESS_TOKEN_LIFETIME': datetime.timedelta(hours=100),
}

# CORS SETTINGS
Expand Down
107 changes: 36 additions & 71 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,92 +1,57 @@
# DEPENDENCIAS JÁ REVISTAS

# Django
# ------------------------------------------------------------------------------
django==3.2.21
django-auditlog==2.0.0

# Dependências do Django Rest Framework
# ------------------------------------------------------------------------------
drf-spectacular==0.26.2 # Auto-generate OpenAPI 3.0 schemas from Django Rest Framework code

# Django Admin Interface
# Para melhoria da aparência do Django Admin
# ------------------------------------------------------------------------------
django-admin-interface==0.26.1

# Celery
# ------------------------------------------------------------------------------
celery==5.2.1
flower==1.2.0 # https://github.com/mher/flower

# Solução para features flags
# ------------------------------------------------------------------------------
django-waffle==4.0.0

# Outras dependências
# ------------------------------------------------------------------------------
Pillow==9.5.0
python-slugify==8.0.1
django-admin-rangefilter==0.5.4
django-allauth==0.56.1
django-auditlog==2.0.0
django-ckeditor==6.7.0
django-compressor==4.4
rcssmin==1.1.1
django-cors-headers
django-crispy-forms==1.9.0
django-environ==0.4.5
django-filter==2.4.0
django-mathfilters==1.0.0
django-model-utils==4.0.0
django-waffle==4.0.0 # Solução para features flags

# Django DES - EmailBackend that allows email configuration to be changed while the server is running.
# Fork do django-des para suportar o Django 4
git+https://github.com/prefeiturasp/django-des-fork.git#egg=django-des


# DEPENDENCIAS AINDA NÃO REVISTAS

pytz==2019.3 # https://github.com/stub42/pytz

argon2-cffi==19.2.0 # https://github.com/hynek/argon2_cffi
whitenoise==5.0.1 # https://github.com/evansd/whitenoise
redis==3.4.1 # https://github.com/andymccurdy/redis-py

django-celery-beat==2.1.0 # https://github.com/celery/django-celery-beat
openpyxl==3.0.3

# Django
# Django Rest Framework
# ------------------------------------------------------------------------------
django-environ==0.4.5 # https://github.com/joke2k/django-environ
django-model-utils==4.0.0 # https://github.com/jazzband/django-model-utils
django-crispy-forms==1.9.0 # https://github.com/django-crispy-forms/django-crispy-forms

django-redis==4.11.0 # https://github.com/niwinz/django-redis
django-admin-rangefilter==0.5.4 # https://github.com/silentsokolov/django-admin-rangefilter

# Django REST Framework
djangorestframework==3.11.0 # https://github.com/encode/django-rest-framework

# Para filtros no DRF
# https://django-filter.readthedocs.io/en/master/#
django-filter==2.4.0

djangorestframework-jwt==1.11.0 # https://getblimp.github.io/django-rest-framework-jwt/
djangorestframework==3.11.0
djangorestframework-simplejwt==5.3.0 # JWT authentication for DRF
drf-spectacular==0.26.2 # Auto-generate OpenAPI 3.0 schemas from Django Rest Framework code

django-cors-headers # https://github.com/adamchainz/django-cors-headers
# Celery e Redis
# ------------------------------------------------------------------------------
celery==5.2.1
flower==1.2.0
django-celery-beat==2.1.0
redis==3.4.1
django-redis==4.11.0

# Integração com Kibana
# ------------------------------------------------------------------------------
elastic-apm==6.15.1
psutil==5.9.4

# Para validação e formatação de CNPJ e CPF
# https://github.com/poliquin/brazilnum
# Outras libs e utilitários
# ------------------------------------------------------------------------------
Babel==2.12.1
Pillow==9.5.0
argon2-cffi==19.2.0
brazilnum==0.8.8

sentry-sdk==0.14.2 # https://github.com/getsentry/sentry-python
openpyxl==3.0.3
python-slugify==8.0.1
pytz==2019.3
rcssmin==1.1.1
sentry-sdk==0.14.2
whitenoise==5.0.1

# Gerador de PDF
# ------------------------------------------------------------------------------
WeasyPrint==52.2
django-weasyprint==1.0.2

# Para somar valores nos templates (incluindo floats)
django-mathfilters==1.0.0

# Integração com Kibana
elastic-apm==6.15.1
psutil==5.9.4

# Formatação de números
# https://github.com/python-babel/babel

Babel==2.12.1
59 changes: 27 additions & 32 deletions requirements/local.txt
Original file line number Diff line number Diff line change
@@ -1,40 +1,35 @@
-r ./base.txt

# Dependencias revisadas
# Banco de dados
# ------------------------------------------------------------------------------
psycopg2-binary==2.9.5

django-extensions==3.2.3


# Dependencias não revisadas

Werkzeug==1.0.0 # https://github.com/pallets/werkzeug
ipdb==0.13.1 # https://github.com/gotcha/ipdb
Sphinx==2.4.3 # https://github.com/sphinx-doc/sphinx

# Testing
# Django
# ------------------------------------------------------------------------------
mypy==1.3.0 # https://github.com/python/mypy
django-stubs==4.2.1 # https://github.com/typeddjango/django-stubs
pytest==7.3.2 # https://github.com/pytest-dev/pytest
pytest-django==4.5.2 # https://github.com/pytest-dev/pytest-django
pytest-sugar==0.9.7 # https://github.com/Frozenball/pytest-sugar

model-bakery==1.1.0 # https://model-bakery.readthedocs.io/en/latest/index.html
freezegun==0.3.12 # https://github.com/spulec/freezegun
Sphinx==2.4.3
Werkzeug==1.0.0
django-coverage-plugin==1.8.0
django-debug-toolbar==2.2
django-extensions==3.2.3
ipdb==0.13.1

# Code quality
# Testes Unitários
# ------------------------------------------------------------------------------
flake8==3.7.9 # https://github.com/PyCQA/flake8
coverage==5.0.3 # https://github.com/nedbat/coveragepy
black==19.10b0 # https://github.com/ambv/black
pylint-django==2.0.14 # https://github.com/PyCQA/pylint-django
pylint-celery==0.3 # https://github.com/PyCQA/pylint-celery
pre-commit==2.1.1 # https://github.com/pre-commit/pre-commit

# Django
django-stubs==4.2.1
factory-boy==2.12.0
pytest-factoryboy==2.5.1
freezegun==0.3.12
model-bakery==1.1.0
mypy==1.3.0
pytest-django==4.5.2
pytest-sugar==0.9.7
pytest==7.3.2

# Qualidade de Código
# ------------------------------------------------------------------------------
factory-boy==2.12.0 # https://github.com/FactoryBoy/factory_boy

django-debug-toolbar==2.2 # https://github.com/jazzband/django-debug-toolbar
django-coverage-plugin==1.8.0 # https://github.com/nedbat/django_coverage_plugin
black==23.9.1
coverage==5.0.3
flake8==3.7.9
pre-commit==2.1.1
pylint-celery==0.3
pylint-django==2.0.14
10 changes: 4 additions & 6 deletions requirements/production.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

-r ./base.txt

# Dependencias revisadas
# Banco de dados
# ------------------------------------------------------------------------------
psycopg2==2.9.5 --no-binary psycopg2

# Dependencias não revisadas

gunicorn==20.0.4 # https://github.com/benoitc/gunicorn

# Django
# ------------------------------------------------------------------------------
django-anymail[mailgun]==7.0.0 # https://github.com/anymail/django-anymail
django-anymail[mailgun]==7.0.0
gunicorn==20.0.4
2 changes: 1 addition & 1 deletion sme_ptrf_apps/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "8.10.3"
__version__ = "8.11.0"

__version_info__ = tuple(
[
Expand Down
50 changes: 21 additions & 29 deletions sme_ptrf_apps/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@
from sme_ptrf_apps.dre.models import ConsolidadoDRE
import datetime

from pytest_factoryboy import register
from sme_ptrf_apps.core.fixtures.factories.unidade_factory import DreFactory, UnidadeFactory
from sme_ptrf_apps.core.fixtures.factories.associacao_factory import AssociacaoFactory
from sme_ptrf_apps.core.fixtures.factories.conta_associacao_factory import ContaAssociacaoFactory
from sme_ptrf_apps.core.fixtures.factories.periodo_factory import PeriodoFactory
from sme_ptrf_apps.core.fixtures.factories.tipo_conta_factory import TipoContaFactory
from sme_ptrf_apps.core.fixtures.factories.observacao_conciliacao_factory import ObservacaoConciliacaoFactory
from sme_ptrf_apps.core.fixtures.factories.prestacao_conta_factory import PrestacaoContaFactory

from sme_ptrf_apps.fixtures import *

register(DreFactory)
register(UnidadeFactory)
register(AssociacaoFactory)
register(ContaAssociacaoFactory)
register(PeriodoFactory)
register(TipoContaFactory)
register(ObservacaoConciliacaoFactory)
register(PrestacaoContaFactory)

@pytest.fixture
def fake_user(client, django_user_model, unidade):
Expand Down Expand Up @@ -58,21 +77,8 @@ def usuario(unidade):

@pytest.fixture
def jwt_authenticated_client(client, usuario):
from unittest.mock import patch
api_client = APIClient()
with patch('sme_ptrf_apps.users.api.views.login.AutenticacaoService.autentica') as mock_post:
data = {
"nome": "LUCIA HELENA",
"cpf": "62085077072",
"email": "[email protected]",
"login": "7210418"
}
mock_post.return_value.ok = True
mock_post.return_value.status_code = 200
mock_post.return_value.json.return_value = data
resp = api_client.post('/api/login', {'login': usuario.username, 'senha': usuario.password}, format='json')
resp_data = resp.json()
api_client.credentials(HTTP_AUTHORIZATION='JWT {0}'.format(resp_data['token']))
api_client.force_authenticate(user=usuario)
return api_client


Expand Down Expand Up @@ -2984,22 +2990,8 @@ def usuario_permissao_sme(unidade, grupo_sme):

@pytest.fixture
def jwt_authenticated_client_sme(client, usuario_permissao_sme):
from unittest.mock import patch
from rest_framework.test import APIClient
api_client = APIClient()
with patch('sme_ptrf_apps.users.api.views.login.AutenticacaoService.autentica') as mock_post:
data = {
"nome": "Usuario SME",
"cpf": "12345678910",
"email": "[email protected]",
"login": "1235678"
}
mock_post.return_value.ok = True
mock_post.return_value.status_code = 200
mock_post.return_value.json.return_value = data
resp = api_client.post('/api/login', {'login': usuario_permissao_sme.username, 'senha': usuario_permissao_sme.password}, format='json')
resp_data = resp.json()
api_client.credentials(HTTP_AUTHORIZATION='JWT {0}'.format(resp_data['token']))
api_client.force_authenticate(user=usuario_permissao_sme)
return api_client


Expand Down
Empty file.
19 changes: 19 additions & 0 deletions sme_ptrf_apps/core/fixtures/factories/associacao_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from factory import DjangoModelFactory, SubFactory, Sequence, LazyAttribute
from faker import Faker
from sme_ptrf_apps.core.models.associacao import Associacao
from sme_ptrf_apps.core.fixtures.factories.unidade_factory import UnidadeFactory

fake = Faker("pt_BR")

class AssociacaoFactory(DjangoModelFactory):
class Meta:
model = Associacao

unidade = SubFactory(UnidadeFactory)
cnpj = Sequence(lambda n: fake.unique.cnpj())


@LazyAttribute
def nome(self):
return f"APM {self.unidade.nome}"

18 changes: 18 additions & 0 deletions sme_ptrf_apps/core/fixtures/factories/conta_associacao_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from factory import DjangoModelFactory, SubFactory, Sequence
from faker import Faker
from sme_ptrf_apps.core.models.conta_associacao import ContaAssociacao
from sme_ptrf_apps.core.fixtures.factories.associacao_factory import AssociacaoFactory
from sme_ptrf_apps.core.fixtures.factories.tipo_conta_factory import TipoContaFactory

fake = Faker("pt_BR")

class ContaAssociacaoFactory(DjangoModelFactory):
class Meta:
model = ContaAssociacao

associacao = SubFactory(AssociacaoFactory)
tipo_conta = SubFactory(TipoContaFactory)
banco_nome = Sequence(lambda n: f"Banco {fake.unique.name()}")
agencia = Sequence(lambda n: f"{str(fake.unique.random_int(min=1000, max=9999))}-{fake.random_number(digits=1)}")
numero_conta = Sequence(lambda n: f"{str(fake.unique.random_int(min=10, max=99))}.{str(fake.unique.random_int(min=100, max=999))}-{fake.random_number(digits=1)}")
data_inicio = Sequence(lambda n: fake.date(pattern="%Y-%m-%d"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from factory import DjangoModelFactory, SubFactory, Sequence
from faker import Faker
from sme_ptrf_apps.core.fixtures.factories.associacao_factory import AssociacaoFactory
from sme_ptrf_apps.core.fixtures.factories.periodo_factory import PeriodoFactory
from sme_ptrf_apps.core.fixtures.factories.conta_associacao_factory import ContaAssociacaoFactory
from sme_ptrf_apps.core.models.observacao_conciliacao import ObservacaoConciliacao

fake = Faker("pt_BR")

class ObservacaoConciliacaoFactory(DjangoModelFactory):
class Meta:
model = ObservacaoConciliacao

periodo = SubFactory(PeriodoFactory)
associacao = SubFactory(AssociacaoFactory)
conta_associacao = SubFactory(ContaAssociacaoFactory)
texto = Sequence(lambda n:fake.sentences(5))
data_extrato = Sequence(lambda n: fake.date(pattern="%Y-%m-%d"))
saldo_extrato = Sequence(lambda n: fake.random_number(digits=6))
14 changes: 14 additions & 0 deletions sme_ptrf_apps/core/fixtures/factories/periodo_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from factory import DjangoModelFactory, Sequence, LazyAttribute
from datetime import datetime, timedelta, date
from faker import Faker
from sme_ptrf_apps.core.models.periodo import Periodo

fake = Faker("pt_BR")

class PeriodoFactory(DjangoModelFactory):
class Meta:
model = Periodo

data_inicio_realizacao_despesas = Sequence(lambda n: fake.date_between_dates(date_start=datetime(2019, 1, 1), date_end=datetime.today()))
data_fim_realizacao_despesas = LazyAttribute(lambda obj: obj.data_inicio_realizacao_despesas + timedelta(days=120))
referencia = LazyAttribute(lambda obj: obj.data_inicio_realizacao_despesas.strftime("%Y.1"))
Loading

0 comments on commit 1491407

Please sign in to comment.