Skip to content

Commit

Permalink
Merge pull request #231 from prefeiturasp/feature/20467-tecnicos-dre-2
Browse files Browse the repository at this point in the history
Feature/20467 técnicos DRE validações
  • Loading branch information
alcfernandes authored Aug 19, 2020
2 parents e229833 + 827720d commit 71cfd40
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 2 deletions.
4 changes: 3 additions & 1 deletion sme_ptrf_apps/dre/api/views/tecnicos_dre_viewset.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django_filters import rest_framework as filters
from rest_framework import viewsets
from rest_framework.permissions import AllowAny

Expand All @@ -10,7 +11,8 @@ class TecnicosDreViewSet(viewsets.ModelViewSet):
lookup_field = 'uuid'
queryset = TecnicoDre.objects.all()
serializer_class = TecnicoDreSerializer

filter_backends = (filters.DjangoFilterBackend,)
filter_fields = ('dre__uuid', 'rf')
def get_serializer_class(self):
if self.action in ['retrieve', 'list']:
return TecnicoDreSerializer
Expand Down
18 changes: 18 additions & 0 deletions sme_ptrf_apps/dre/migrations/0006_auto_20200819_0720.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.10 on 2020-08-19 07:20

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('dre', '0005_tecnicodre'),
]

operations = [
migrations.AlterField(
model_name='tecnicodre',
name='rf',
field=models.CharField(blank=True, default='', max_length=10, null=True, unique=True, verbose_name='RF'),
),
]
2 changes: 1 addition & 1 deletion sme_ptrf_apps/dre/models/tecnico_diretoria.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TecnicoDre(ModeloBase):

nome = models.CharField('Nome', max_length=160)

rf = models.CharField('RF', max_length=10, blank=True, null=True, default="")
rf = models.CharField('RF', max_length=10, blank=True, null=True, default="", unique=True)

class Meta:
verbose_name = "Técnico de DRE"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

pytestmark = pytest.mark.django_db


@pytest.fixture
def payload_tecnico_dre(dre_butantan):
payload = {
Expand All @@ -26,3 +27,25 @@ def test_create_tecnico_dre(jwt_authenticated_client, dre, payload_tecnico_dre):
result = json.loads(response.content)

assert TecnicoDre.objects.filter(uuid=result['uuid']).exists()


@pytest.fixture
def payload_tecnico_dre_rf_ja_existente(dre_butantan, tecnico_maria_dre_butantan):
payload = {
'dre': f'{dre_butantan.uuid}',
'rf': tecnico_maria_dre_butantan.rf,
'nome': 'Pedro Antunes'
}
return payload


def test_create_tecnico_dre_repetido(jwt_authenticated_client, dre, tecnico_maria_dre_butantan,
payload_tecnico_dre_rf_ja_existente):
response = jwt_authenticated_client.post(
'/api/tecnicos-dre/', data=json.dumps(payload_tecnico_dre_rf_ja_existente), content_type='application/json')

assert response.status_code == status.HTTP_400_BAD_REQUEST

result = json.loads(response.content)

assert result == {'rf': ['Técnico de DRE with this RF already exists.']}
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,51 @@ def test_api_list_tecnicos_dre_todos(client, tecnico_jose_dre_ipiranga, tecnico_

assert response.status_code == status.HTTP_200_OK
assert result == result_esperado


def test_api_list_tecnicos_dre_ipiranga(client, tecnico_jose_dre_ipiranga, tecnico_maria_dre_butantan, dre_ipiranga):
response = client.get(f'/api/tecnicos-dre/?dre__uuid={dre_ipiranga.uuid}', content_type='application/json')
result = json.loads(response.content)

result_esperado = [
{
"uuid": f'{tecnico_jose_dre_ipiranga.uuid}',
"nome": tecnico_jose_dre_ipiranga.nome,
"rf": tecnico_jose_dre_ipiranga.rf,
"dre": {
'uuid': f'{tecnico_jose_dre_ipiranga.dre.uuid}',
'codigo_eol': f'{tecnico_jose_dre_ipiranga.dre.codigo_eol}',
'tipo_unidade': f'{tecnico_jose_dre_ipiranga.dre.tipo_unidade}',
'nome': f'{tecnico_jose_dre_ipiranga.dre.nome}',
'sigla': f'{tecnico_jose_dre_ipiranga.dre.sigla}',
},
}

]

assert response.status_code == status.HTTP_200_OK
assert result == result_esperado


def test_api_list_tecnicos_dre_por_rf(client, tecnico_jose_dre_ipiranga, tecnico_maria_dre_butantan, dre_ipiranga):
response = client.get(f'/api/tecnicos-dre/?rf={tecnico_jose_dre_ipiranga.rf}', content_type='application/json')
result = json.loads(response.content)

result_esperado = [
{
"uuid": f'{tecnico_jose_dre_ipiranga.uuid}',
"nome": tecnico_jose_dre_ipiranga.nome,
"rf": tecnico_jose_dre_ipiranga.rf,
"dre": {
'uuid': f'{tecnico_jose_dre_ipiranga.dre.uuid}',
'codigo_eol': f'{tecnico_jose_dre_ipiranga.dre.codigo_eol}',
'tipo_unidade': f'{tecnico_jose_dre_ipiranga.dre.tipo_unidade}',
'nome': f'{tecnico_jose_dre_ipiranga.dre.nome}',
'sigla': f'{tecnico_jose_dre_ipiranga.dre.sigla}',
},
}

]

assert response.status_code == status.HTTP_200_OK
assert result == result_esperado

0 comments on commit 71cfd40

Please sign in to comment.