-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from fga-eps-mds/103/TestesUnitarios
103/testes unitarios
- Loading branch information
Showing
22 changed files
with
302 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
POSTGRES_HOST=db | ||
POSTGRES_DB=postgres | ||
POSTGRES_USER=postgres | ||
POSTGRES_PORT=5432 | ||
POSTGRES_PASSWORD=postgres |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
FROM python:3 | ||
|
||
ENV PYTHONUNBUFFERED 1 | ||
EXPOSE 8000 | ||
|
||
RUN mkdir /src | ||
|
||
WORKDIR /src | ||
|
||
RUN mkdir /code | ||
WORKDIR /code | ||
ADD requirements.txt /code/ | ||
RUN pip install -r requirements.txt | ||
ADD . /code/ | ||
COPY src /src | ||
|
||
RUN pip3 install --upgrade pip && \ | ||
pip3 install -r requirements.txt | ||
|
||
ENV PYTHONUNBUFFERED 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
from .models import Paciente | ||
from rest_framework import serializers | ||
from users.serializers import PsicologoSerializer | ||
|
||
class PacienteSerializer(serializers.ModelSerializer): | ||
class Meta(): | ||
model = Paciente | ||
fields = ['nome', 'cpf', 'data_nascimento', 'psicologo', 'genero', 'regiao', 'situacao', 'descricao'] | ||
fields = ['nome', 'cpf', 'data_nascimento', 'genero', 'regiao', | ||
'situacao', 'descricao'] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
from .views import PacienteViewSet | ||
from rest_framework import routers | ||
from .views import PacienteViewSet, PacienteRegistrationAPIView ,PacienteDelete, PacienteUpdate | ||
from rest_framework_nested import routers | ||
|
||
# from .views import PacienteViewSet, PacienteRegistrationAPIView ,PacienteDelete, PacienteUpdate | ||
|
||
app_name = 'paciente' | ||
|
||
# router = routers.DefaultRouter() | ||
# router.register(r'create', PacienteRegistrationAPIView) | ||
# router.register(r'delete', PacienteDelete) | ||
# router.register(r'update', PacienteUpdate) | ||
|
||
|
||
|
||
|
||
|
||
|
||
router = routers.DefaultRouter() | ||
router.register(r'paciente', PacienteViewSet) | ||
router.register(r'create', PacienteRegistrationAPIView) | ||
router.register(r'delete', PacienteDelete) | ||
router.register(r'update', PacienteUpdate) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,44 @@ | ||
from django.shortcuts import render | ||
from rest_framework import viewsets, generics | ||
from rest_framework.views import APIView | ||
from rest_framework import viewsets | ||
|
||
from users.models import Psicologo | ||
from .models import Paciente | ||
from .serializers import PacienteSerializer | ||
from rest_framework.viewsets import GenericViewSet | ||
from rest_framework import mixins, permissions | ||
from rest_framework.decorators import api_view, permission_classes | ||
|
||
class PacienteViewSet(GenericViewSet, mixins.ListModelMixin, mixins.RetrieveModelMixin): | ||
|
||
queryset = Paciente.objects.all() | ||
serializer_class = PacienteSerializer | ||
|
||
class PacienteRegistrationAPIView(GenericViewSet, mixins.CreateModelMixin): | ||
# class PacienteViewSet(GenericViewSet, mixins.ListModelMixin, mixins.RetrieveModelMixin): | ||
|
||
serializer_class = PacienteSerializer | ||
queryset = Paciente.objects.all() | ||
# queryset = Paciente.objects.all() | ||
# serializer_class = PacienteSerializer | ||
|
||
class PacienteDelete(GenericViewSet, mixins.DestroyModelMixin): | ||
# class PacienteRegistrationAPIView(GenericViewSet, mixins.CreateModelMixin): | ||
# serializer_class = PacienteSerializer | ||
# queryset = Paciente.objects.all() | ||
|
||
serializer_class = PacienteSerializer | ||
queryset = Paciente.objects.all() | ||
lookup_field = 'cpf' | ||
# class PacienteDelete(GenericViewSet, mixins.DestroyModelMixin): | ||
|
||
class PacienteUpdate(GenericViewSet, mixins.UpdateModelMixin): | ||
# serializer_class = PacienteSerializer | ||
# queryset = Paciente.objects.all() | ||
# lookup_field = 'cpf' | ||
|
||
serializer_class = PacienteSerializer | ||
# class PacienteUpdate(GenericViewSet, mixins.UpdateModelMixin): | ||
|
||
# serializer_class = PacienteSerializer | ||
# queryset = Paciente.objects.all() | ||
# lookup_field = 'cpf' | ||
|
||
|
||
class PacienteModelViewSet(viewsets.ModelViewSet): | ||
queryset = Paciente.objects.all() | ||
serializer_class = PacienteSerializer | ||
lookup_field = 'cpf' | ||
|
||
|
||
|
||
def get_psicologo(self): | ||
return Psicologo.objects.get(nCRP=self.kwargs['psicologo_nCRP']) | ||
|
||
def get_queryset(self): | ||
psicologo = self.get_psicologo() | ||
return Paciente.objects.filter(psicologo=psicologo) | ||
|
||
def perform_create(self, serializer): | ||
psicologo = self.get_psicologo() | ||
paciente = serializer.save(psicologo=psicologo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash | ||
|
||
# Exporting all environment variables to use in crontab | ||
env | sed 's/^\(.*\)$/ \1/g' > /root/env | ||
|
||
function_postgres_ready() { | ||
python << END | ||
import socket | ||
import time | ||
import os | ||
port = int(os.environ["POSTGRES_PORT"]) | ||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
s.connect(('db', port)) | ||
s.close() | ||
END | ||
} | ||
|
||
echo '======= CHECKING FOR UNINSTALLED PKGs AND INSTALLING' | ||
pip freeze || pip install -r requirements.txt | ||
|
||
until function_postgres_ready; do | ||
>&2 echo "======= POSTGRES IS UNAVAILABLE, WAITING" | ||
sleep 1 | ||
done | ||
echo "======= POSTGRES IS UP, CONNECTING" | ||
|
||
echo '======= MAKING MIGRATIONS' | ||
python3 manage.py makemigrations | ||
|
||
echo '======= RUNNING MIGRATIONS' | ||
python3 manage.py migrate | ||
|
||
echo '======= RUNNING SERVER' | ||
python3 manage.py runserver 0.0.0.0:8000 |
Oops, something went wrong.