-
Notifications
You must be signed in to change notification settings - Fork 0
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 #268 from fga-eps-mds/dev
Updating master
- Loading branch information
Showing
46 changed files
with
1,093 additions
and
149 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,3 @@ | ||
.vscode | ||
.env | ||
.DS_Store |
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,2 +1,33 @@ | ||
default: | ||
cd api && make | ||
|
||
run: | ||
cd api && make run | ||
cd api && make run | ||
|
||
integration-tests: | ||
docker-compose -f ${file} build | ||
docker-compose -f ${file} up -d | ||
echo "Running Integration Tests" | ||
docker exec api-gateway bash -c "ls && bash ./check-services.sh && sh run-tests.sh" | ||
docker-compose -f ${file} down | ||
docker-compose -f ${file} rm -f -s | ||
|
||
staging-integration-tests: | ||
sh remove-all-containers.sh || true | ||
make integration-tests file=dc-integration-test.staging.yml | ||
|
||
|
||
production-integration-tests: | ||
sh remove-all-containers.sh || true | ||
make integration-tests file=dc-integration-test.production.yml | ||
|
||
backend: | ||
sh remove-all-containers.sh || true | ||
docker-compose -f dc-backend-production.yml build | ||
docker-compose -f dc-backend-production.yml up | ||
|
||
build-staging: | ||
docker-compose -f dc-integration-test.staging.yml build | ||
|
||
build-production: | ||
docker-compose -f dc-integration-test.production.yml build |
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,12 @@ | ||
FROM python:3 | ||
FROM python:3.5.6-slim-stretch | ||
ENV PYTHONUNBUFFERED 1 | ||
|
||
RUN mkdir /code | ||
WORKDIR /code | ||
|
||
ADD ./api_gateway /code/ | ||
ADD . /code | ||
WORKDIR /code/api_gateway | ||
ADD VERSION /code | ||
|
||
RUN pip install --upgrade pip | ||
RUN pip install -r requirements/dev.txt | ||
RUN pip install -r requirements/dev.txt | ||
|
||
RUN apt-get update | ||
RUN apt-get install curl libcurl3 libcurl3-dev -y |
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,19 @@ | ||
default: | ||
docker build . -t docker-django:api-gateway | ||
docker run --rm -p 5000:5000 -v `pwd`:"/app" -w "/app" --name api-gateway -it docker-django:api-gateway bash | ||
docker network create api-backend || true | ||
docker-compose up | ||
|
||
run: | ||
docker build . -t docker-django:api-gateway | ||
docker run --rm -p 5000:5000 -v `pwd`:"/app" -w "/app" --net=backend --name api-gateway -d docker-django:api-gateway bash -c "sh run-django.sh" | ||
echo NEED_UPDATE | ||
|
||
build: | ||
docker-compose build | ||
|
||
enter: | ||
docker exec -ti api-gateway bash | ||
docker-compose exec web bash | ||
|
||
test: | ||
docker-compose exec web bash -c "cd api_gateway && python manage.py test" | ||
|
||
production: | ||
docker-compose -f docker-compose-production.yml build | ||
docker-compose -f docker-compose-production.yml up |
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 +1 @@ | ||
0.1 | ||
1.0 |
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,2 @@ | ||
release: python manage.py makemigrations && python manage.py migrate --noinput | ||
web: gunicorn api_gateway.wsgi --log-file - |
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,25 @@ | ||
from django.conf import settings | ||
from rest_framework.status import ( | ||
HTTP_403_FORBIDDEN, | ||
HTTP_200_OK, | ||
HTTP_400_BAD_REQUEST, | ||
HTTP_500_INTERNAL_SERVER_ERROR | ||
) | ||
from rest_framework.response import Response | ||
import requests | ||
import json | ||
|
||
def verify_token(data_request): | ||
if not 'token' in data_request: | ||
return Response({'error': 'Token vazio'}, | ||
status=HTTP_400_BAD_REQUEST) | ||
try: | ||
token = data_request['token'] | ||
response = requests.post(settings.LOGIN + '/api/token-verify/', data={'token':token}) | ||
if not 'token' in response.json(): | ||
return Response({'error': 'Falha na autenticação'}, | ||
status=HTTP_403_FORBIDDEN) #Erro de token incorreto | ||
except: | ||
return Response({'error': 'Nao foi possivel se comunicar com o servidor para autenticação'}, | ||
status=HTTP_500_INTERNAL_SERVER_ERROR) #Erro de servidor | ||
return Response({''}, HTTP_200_OK) |
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 @@ | ||
from .test_user import * | ||
from .test_login import * | ||
from .test_order import * | ||
from .test_product import * | ||
from .test_version import * |
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,30 @@ | ||
from django.conf import settings | ||
import requests | ||
|
||
default_password = "test1234" | ||
|
||
def registrate_new_user(email): | ||
|
||
data = { | ||
"username": email, | ||
"email": email, | ||
"password1": default_password, | ||
"password2": default_password | ||
} | ||
|
||
response = requests.post(settings.LOGIN + '/api/registration/', data=data) | ||
|
||
return response.json() | ||
|
||
def login_user(email): | ||
|
||
data = { | ||
"username": email, | ||
"password": default_password | ||
} | ||
|
||
response = requests.post(settings.LOGIN + '/api/login/', data=data) | ||
|
||
return response.json() | ||
|
||
|
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,16 @@ | ||
from django.conf import settings | ||
import requests | ||
|
||
def create_order(fk_product = None, fk_buyer = None, buyer_message = None, quantity = None, total_price = None, product_name = None, token = None): | ||
|
||
data = { | ||
'fk_product': fk_product, | ||
'fk_buyer': fk_buyer, | ||
'buyer_message': buyer_message, | ||
'quantity': quantity, | ||
'total_price': total_price, | ||
'product_name': product_name, | ||
'token': token | ||
} | ||
|
||
return data |
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,15 @@ | ||
from django.conf import settings | ||
import requests | ||
|
||
def create_product(name = None, fk_vendor = None, price = None, photo = None, description = None, token = None): | ||
|
||
data = { | ||
'fk_vendor': fk_vendor, | ||
'name': name, | ||
'price': price, | ||
'photo': photo, | ||
'description': description, | ||
'token': token | ||
} | ||
|
||
return data |
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,30 @@ | ||
from django.test import TestCase | ||
from .login_test_helper import registrate_new_user, login_user | ||
|
||
|
||
# Create your tests here. | ||
class LoginTest(TestCase): | ||
|
||
def test_user_registration(self): | ||
|
||
email = '[email protected]' | ||
|
||
responseJson = registrate_new_user(email) | ||
|
||
token = responseJson['token'] | ||
user = responseJson['user'] | ||
|
||
self.assertEqual(user["email"], email) | ||
|
||
def test_user_login(self): | ||
|
||
email = '[email protected]' | ||
|
||
responseJson = registrate_new_user(email) | ||
loginResponseJson = login_user(email) | ||
|
||
login_token = loginResponseJson["token"] | ||
user = loginResponseJson["user"] | ||
|
||
self.assertEqual(user["email"], email) | ||
|
Oops, something went wrong.