Fix more tests

This commit is contained in:
Santiago Lo Coco 2023-10-23 14:52:26 -03:00
parent e91574fe3c
commit d9a613b095
20 changed files with 5526 additions and 10 deletions

View File

@ -13,4 +13,4 @@ repos:
rev: 5.12.0
hooks:
- id: isort
args: ['--src-path', 'flights-domain/', 'auth-domain/user-manager/']
args: ['--src-path', 'flights-domain/flights-information/src', 'auth-domain/user-manager/src']

View File

@ -0,0 +1,454 @@
<?xml version="1.0" ?>
<coverage version="7.3.2" timestamp="1698081228733" lines-valid="374" lines-covered="173" line-rate="0.4626" branches-valid="148" branches-covered="97" branch-rate="0.6554" complexity="0">
<!-- Generated by coverage.py: https://coverage.readthedocs.io/en/7.3.2 -->
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
<sources>
<source>/home/slococo/ITBA/MICRO/fids/auth-domain/user-manager/src</source>
</sources>
<packages>
<package name="." line-rate="0.8478" branch-rate="0.25" complexity="0">
<classes>
<class name="__init__.py" filename="__init__.py" complexity="0" line-rate="0.65" branch-rate="0">
<methods/>
<lines>
<line number="1" hits="1"/>
<line number="3" hits="1"/>
<line number="4" hits="1"/>
<line number="5" hits="1"/>
<line number="6" hits="1"/>
<line number="9" hits="1"/>
<line number="10" hits="1"/>
<line number="11" hits="1"/>
<line number="14" hits="1"/>
<line number="16" hits="1"/>
<line number="19" hits="1"/>
<line number="20" hits="1"/>
<line number="23" hits="1"/>
<line number="24" hits="0"/>
<line number="27" hits="0"/>
<line number="29" hits="0"/>
<line number="32" hits="0"/>
<line number="33" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="32,36"/>
<line number="34" hits="0"/>
<line number="36" hits="0"/>
</lines>
</class>
<class name="config.py" filename="config.py" complexity="0" line-rate="1" branch-rate="0.5">
<methods/>
<lines>
<line number="1" hits="1"/>
<line number="4" hits="1"/>
<line number="5" hits="1"/>
<line number="6" hits="1"/>
<line number="7" hits="1"/>
<line number="8" hits="1"/>
<line number="9" hits="1"/>
<line number="12" hits="1"/>
<line number="13" hits="1"/>
<line number="14" hits="1"/>
<line number="17" hits="1"/>
<line number="18" hits="1"/>
<line number="19" hits="1"/>
<line number="20" hits="1"/>
<line number="21" hits="1"/>
<line number="22" hits="1"/>
<line number="25" hits="1"/>
<line number="26" hits="1"/>
<line number="27" hits="1"/>
<line number="28" hits="1"/>
<line number="30" hits="1"/>
<line number="31" hits="1"/>
<line number="32" hits="1"/>
<line number="33" hits="1" branch="true" condition-coverage="50% (1/2)" missing-branches="35"/>
<line number="34" hits="1"/>
<line number="35" hits="1"/>
</lines>
</class>
</classes>
</package>
<package name="api" line-rate="0.3226" branch-rate="0.629" complexity="0">
<classes>
<class name="__init__.py" filename="api/__init__.py" complexity="0" line-rate="1" branch-rate="1">
<methods/>
<lines>
<line number="1" hits="1"/>
<line number="2" hits="1"/>
<line number="3" hits="1"/>
<line number="4" hits="1"/>
<line number="6" hits="1"/>
<line number="9" hits="1"/>
<line number="10" hits="1"/>
</lines>
</class>
<class name="auth.py" filename="api/auth.py" complexity="0" line-rate="0.433" branch-rate="0.7143">
<methods/>
<lines>
<line number="1" hits="1"/>
<line number="2" hits="1"/>
<line number="3" hits="1"/>
<line number="4" hits="1"/>
<line number="5" hits="1"/>
<line number="6" hits="1"/>
<line number="8" hits="1"/>
<line number="10" hits="1"/>
<line number="11" hits="1"/>
<line number="12" hits="1"/>
<line number="13" hits="1"/>
<line number="14" hits="1"/>
<line number="16" hits="1"/>
<line number="17" hits="1"/>
<line number="20" hits="1"/>
<line number="21" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="22" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="23" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="24" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="25" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="26" hits="0"/>
<line number="27" hits="0"/>
<line number="28" hits="0"/>
<line number="29" hits="0"/>
<line number="31" hits="0"/>
<line number="32" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="33,34"/>
<line number="33" hits="0"/>
<line number="34" hits="0"/>
<line number="36" hits="0"/>
<line number="39" hits="1"/>
<line number="40" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="41" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="42" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="43" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="44" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="45" hits="0"/>
<line number="46" hits="0"/>
<line number="47" hits="0"/>
<line number="48" hits="0"/>
<line number="50" hits="0"/>
<line number="51" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="52,54"/>
<line number="52" hits="0"/>
<line number="54" hits="0"/>
<line number="55" hits="0"/>
<line number="57" hits="0"/>
<line number="60" hits="0"/>
<line number="63" hits="1"/>
<line number="64" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="65" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="66" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="67" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="68" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="69" hits="0"/>
<line number="70" hits="0"/>
<line number="71" hits="0"/>
<line number="73" hits="0"/>
<line number="74" hits="0"/>
<line number="75" hits="0"/>
<line number="77" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="78,80"/>
<line number="78" hits="0"/>
<line number="80" hits="0"/>
<line number="81" hits="0"/>
<line number="83" hits="0"/>
<line number="87" hits="0"/>
<line number="88" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="89,91"/>
<line number="89" hits="0"/>
<line number="90" hits="0"/>
<line number="91" hits="0"/>
<line number="92" hits="0"/>
<line number="95" hits="1"/>
<line number="96" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="97" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="98" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="99" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="100" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="101" hits="0"/>
<line number="102" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="103,119"/>
<line number="103" hits="0"/>
<line number="104" hits="0"/>
<line number="105" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="106,107"/>
<line number="106" hits="0"/>
<line number="107" hits="0"/>
<line number="108" hits="0"/>
<line number="109" hits="0"/>
<line number="110" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="111,112"/>
<line number="111" hits="0"/>
<line number="112" hits="0"/>
<line number="113" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="114,116"/>
<line number="114" hits="0"/>
<line number="115" hits="0"/>
<line number="116" hits="0"/>
<line number="117" hits="0"/>
<line number="119" hits="0"/>
<line number="122" hits="1"/>
<line number="123" hits="1"/>
<line number="124" hits="1"/>
<line number="125" hits="1"/>
</lines>
</class>
<class name="crud.py" filename="api/crud.py" complexity="0" line-rate="0" branch-rate="1">
<methods/>
<lines>
<line number="1" hits="0"/>
<line number="2" hits="0"/>
<line number="5" hits="0"/>
<line number="6" hits="0"/>
<line number="9" hits="0"/>
<line number="10" hits="0"/>
<line number="13" hits="0"/>
<line number="14" hits="0"/>
<line number="17" hits="0"/>
<line number="18" hits="0"/>
<line number="19" hits="0"/>
<line number="20" hits="0"/>
<line number="21" hits="0"/>
<line number="24" hits="0"/>
<line number="25" hits="0"/>
<line number="26" hits="0"/>
<line number="27" hits="0"/>
<line number="28" hits="0"/>
<line number="31" hits="0"/>
<line number="32" hits="0"/>
<line number="33" hits="0"/>
<line number="34" hits="0"/>
</lines>
</class>
<class name="models.py" filename="api/models.py" complexity="0" line-rate="0" branch-rate="0">
<methods/>
<lines>
<line number="1" hits="0"/>
<line number="3" hits="0"/>
<line number="4" hits="0"/>
<line number="5" hits="0"/>
<line number="6" hits="0"/>
<line number="7" hits="0"/>
<line number="10" hits="0"/>
<line number="11" hits="0"/>
<line number="13" hits="0"/>
<line number="14" hits="0"/>
<line number="15" hits="0"/>
<line number="16" hits="0"/>
<line number="17" hits="0"/>
<line number="18" hits="0"/>
<line number="20" hits="0"/>
<line number="21" hits="0"/>
<line number="22" hits="0"/>
<line number="23" hits="0"/>
<line number="27" hits="0"/>
<line number="28" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="27,44"/>
<line number="29" hits="0"/>
<line number="30" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="31,33"/>
<line number="31" hits="0"/>
<line number="33" hits="0"/>
<line number="35" hits="0"/>
<line number="40" hits="0"/>
<line number="44" hits="0"/>
<line number="45" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="44,51"/>
<line number="46" hits="0"/>
<line number="49" hits="0"/>
<line number="51" hits="0"/>
<line number="52" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="51,63"/>
<line number="53" hits="0"/>
<line number="63" hits="0"/>
<line number="64" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="63,73"/>
<line number="65" hits="0"/>
<line number="73" hits="0"/>
<line number="74" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="73,83"/>
<line number="75" hits="0"/>
<line number="83" hits="0"/>
<line number="84" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="83,93"/>
<line number="85" hits="0"/>
<line number="93" hits="0"/>
<line number="94" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="93,103"/>
<line number="95" hits="0"/>
<line number="103" hits="0"/>
<line number="104" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="103,109"/>
<line number="105" hits="0"/>
<line number="109" hits="0"/>
<line number="110" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="exit,109"/>
<line number="111" hits="0"/>
</lines>
</class>
<class name="users.py" filename="api/users.py" complexity="0" line-rate="0.4366" branch-rate="0.7917">
<methods/>
<lines>
<line number="1" hits="1"/>
<line number="2" hits="1"/>
<line number="3" hits="1"/>
<line number="5" hits="1"/>
<line number="14" hits="1"/>
<line number="16" hits="1"/>
<line number="18" hits="1"/>
<line number="19" hits="1"/>
<line number="22" hits="1"/>
<line number="23" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="24" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="25" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="26" hits="0"/>
<line number="28" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="29" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="30" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="31" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="32" hits="0"/>
<line number="33" hits="0"/>
<line number="34" hits="0"/>
<line number="35" hits="0"/>
<line number="36" hits="0"/>
<line number="38" hits="0"/>
<line number="39" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="40,43"/>
<line number="40" hits="0"/>
<line number="41" hits="0"/>
<line number="43" hits="0"/>
<line number="45" hits="0"/>
<line number="46" hits="0"/>
<line number="47" hits="0"/>
<line number="50" hits="1"/>
<line number="51" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="52" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="53" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="54" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="55" hits="0"/>
<line number="56" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="57,58"/>
<line number="57" hits="0"/>
<line number="58" hits="0"/>
<line number="60" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="61" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="62" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="63" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="64" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="65" hits="0"/>
<line number="66" hits="0"/>
<line number="67" hits="0"/>
<line number="68" hits="0"/>
<line number="70" hits="0"/>
<line number="71" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="72,74"/>
<line number="72" hits="0"/>
<line number="74" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="75,78"/>
<line number="75" hits="0"/>
<line number="76" hits="0"/>
<line number="78" hits="0"/>
<line number="80" hits="0"/>
<line number="81" hits="0"/>
<line number="82" hits="0"/>
<line number="84" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="85" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="86" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="87" hits="0"/>
<line number="88" hits="0"/>
<line number="90" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="91,93"/>
<line number="91" hits="0"/>
<line number="93" hits="0"/>
<line number="95" hits="0"/>
<line number="96" hits="0"/>
<line number="97" hits="0"/>
<line number="100" hits="1"/>
<line number="101" hits="1"/>
</lines>
</class>
</classes>
</package>
<package name="api.cruds" line-rate="0.3636" branch-rate="1" complexity="0">
<classes>
<class name="users.py" filename="api/cruds/users.py" complexity="0" line-rate="0.3636" branch-rate="1">
<methods/>
<lines>
<line number="1" hits="1"/>
<line number="2" hits="1"/>
<line number="5" hits="1"/>
<line number="6" hits="0"/>
<line number="9" hits="1"/>
<line number="10" hits="0"/>
<line number="13" hits="1"/>
<line number="14" hits="0"/>
<line number="17" hits="1"/>
<line number="18" hits="0"/>
<line number="19" hits="0"/>
<line number="20" hits="0"/>
<line number="21" hits="0"/>
<line number="24" hits="1"/>
<line number="25" hits="0"/>
<line number="26" hits="0"/>
<line number="27" hits="0"/>
<line number="28" hits="0"/>
<line number="31" hits="1"/>
<line number="32" hits="0"/>
<line number="33" hits="0"/>
<line number="34" hits="0"/>
</lines>
</class>
</classes>
</package>
<package name="api.models" line-rate="0.7931" branch-rate="0.9" complexity="0">
<classes>
<class name="__init__.py" filename="api/models/__init__.py" complexity="0" line-rate="1" branch-rate="1">
<methods/>
<lines/>
</class>
<class name="generic.py" filename="api/models/generic.py" complexity="0" line-rate="1" branch-rate="1">
<methods/>
<lines>
<line number="1" hits="1"/>
<line number="4" hits="1"/>
<line number="5" hits="1"/>
<line number="14" hits="1"/>
<line number="15" hits="1"/>
</lines>
</class>
<class name="users.py" filename="api/models/users.py" complexity="0" line-rate="0.7736" branch-rate="0.9">
<methods/>
<lines>
<line number="1" hits="1"/>
<line number="3" hits="1"/>
<line number="4" hits="1"/>
<line number="5" hits="1"/>
<line number="6" hits="1"/>
<line number="7" hits="1"/>
<line number="10" hits="1"/>
<line number="11" hits="1"/>
<line number="13" hits="1"/>
<line number="14" hits="1"/>
<line number="15" hits="1"/>
<line number="16" hits="1"/>
<line number="17" hits="1"/>
<line number="18" hits="1"/>
<line number="19" hits="1"/>
<line number="21" hits="1"/>
<line number="22" hits="0"/>
<line number="23" hits="0"/>
<line number="24" hits="0"/>
<line number="27" hits="0"/>
<line number="29" hits="1"/>
<line number="30" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="31" hits="0"/>
<line number="32" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="33,35"/>
<line number="33" hits="0"/>
<line number="35" hits="0"/>
<line number="37" hits="0"/>
<line number="43" hits="0"/>
<line number="47" hits="1"/>
<line number="48" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="49" hits="0"/>
<line number="52" hits="0"/>
<line number="54" hits="1"/>
<line number="55" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="56" hits="1"/>
<line number="67" hits="1"/>
<line number="68" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="69" hits="1"/>
<line number="77" hits="1"/>
<line number="78" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="79" hits="1"/>
<line number="88" hits="1"/>
<line number="89" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="90" hits="1"/>
<line number="99" hits="1"/>
<line number="100" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="101" hits="1"/>
<line number="109" hits="1"/>
<line number="110" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="111" hits="1"/>
<line number="115" hits="1"/>
<line number="116" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="117" hits="1"/>
</lines>
</class>
</classes>
</package>
</packages>
</coverage>

View File

@ -1,4 +1,5 @@
from flask.cli import FlaskGroup
from src import create_app, db
from src.api.models.users import User

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,5 @@
from flask_restx import Api
from src.api.auth import auth_namespace
from src.api.users import NAMESPACE as NAMESPACE_USERS
from src.api.users import users_namespace

View File

@ -1,6 +1,7 @@
import jwt
from flask import request
from flask_restx import Namespace, Resource
from src import bcrypt
from src.api.cruds.users import add_user, get_user_by_email, get_user_by_id
from src.api.models.users import User

View File

@ -4,6 +4,7 @@ import jwt
from flask import current_app
from flask_restx import fields
from sqlalchemy.sql import func
from src import bcrypt, db

View File

@ -4,6 +4,7 @@ import jwt
from flask import current_app
from flask_restx import fields
from sqlalchemy.sql import func
from src import bcrypt, db

View File

@ -1,5 +1,6 @@
from flask import request
from flask_restx import Namespace, Resource
from src.api.models.users import User
from src.api.cruds.users import ( # isort:skip

View File

@ -1,5 +1,6 @@
import pytest
from flask_restx import Namespace
from src import create_app, db
from src.api.models.users import User
from src.config import ProductionConfig

View File

@ -1,4 +1,5 @@
import pytest
from src.api.models.users import User
TOKEN_TYPES = ["access", "refresh"]

View File

@ -1,6 +1,7 @@
import json
import pytest
from src import bcrypt
from src.api.cruds.users import get_user_by_id
from src.api.models.users import User

View File

@ -2,6 +2,7 @@ import json
from datetime import datetime
import pytest
import src.api.users

View File

@ -2,7 +2,7 @@
ARG BASE_IMAGE
FROM ${BASE_IMAGE}
ENV DATABASE_TEST_URL=postgresql://postgres:postgres@api-db:5432/api_test
ENV DATABASE_TEST_URL=postgresql://user:password@flights-api-db:5432/api_test
# add and install requirements
COPY --chown=python:python ./requirements.test.txt .

View File

@ -0,0 +1,224 @@
<?xml version="1.0" ?>
<coverage version="7.3.2" timestamp="1698083039765" lines-valid="150" lines-covered="81" line-rate="0.54" branches-valid="26" branches-covered="12" branch-rate="0.4615" complexity="0">
<!-- Generated by coverage.py: https://coverage.readthedocs.io/en/7.3.2 -->
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
<sources>
<source>/home/slococo/ITBA/MICRO/fids/flights-domain/flights-information/src</source>
</sources>
<packages>
<package name="." line-rate="0" branch-rate="0" complexity="0">
<classes>
<class name="config.py" filename="config.py" complexity="0" line-rate="0" branch-rate="0">
<methods/>
<lines>
<line number="1" hits="0"/>
<line number="4" hits="0"/>
<line number="5" hits="0"/>
<line number="6" hits="0"/>
<line number="7" hits="0"/>
<line number="8" hits="0"/>
<line number="9" hits="0"/>
<line number="12" hits="0"/>
<line number="13" hits="0"/>
<line number="14" hits="0"/>
<line number="17" hits="0"/>
<line number="18" hits="0"/>
<line number="19" hits="0"/>
<line number="20" hits="0"/>
<line number="21" hits="0"/>
<line number="22" hits="0"/>
<line number="25" hits="0"/>
<line number="26" hits="0"/>
<line number="27" hits="0"/>
<line number="28" hits="0"/>
<line number="30" hits="0"/>
<line number="31" hits="0"/>
<line number="32" hits="0"/>
<line number="33" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="34,35"/>
<line number="34" hits="0"/>
<line number="35" hits="0"/>
</lines>
</class>
</classes>
</package>
<package name="api" line-rate="0.6522" branch-rate="1" complexity="0">
<classes>
<class name="db.py" filename="api/db.py" complexity="0" line-rate="0.7143" branch-rate="1">
<methods/>
<lines>
<line number="1" hits="1"/>
<line number="3" hits="1"/>
<line number="4" hits="1"/>
<line number="5" hits="1"/>
<line number="7" hits="1"/>
<line number="8" hits="1"/>
<line number="10" hits="1"/>
<line number="12" hits="1"/>
<line number="14" hits="1"/>
<line number="17" hits="1"/>
<line number="18" hits="0"/>
<line number="19" hits="0"/>
<line number="20" hits="0"/>
<line number="22" hits="0"/>
</lines>
</class>
<class name="main.py" filename="api/main.py" complexity="0" line-rate="0.5556" branch-rate="1">
<methods/>
<lines>
<line number="1" hits="1"/>
<line number="2" hits="1"/>
<line number="3" hits="1"/>
<line number="4" hits="1"/>
<line number="6" hits="1"/>
<line number="8" hits="0"/>
<line number="9" hits="0"/>
<line number="10" hits="0"/>
<line number="11" hits="0"/>
</lines>
</class>
</classes>
</package>
<package name="api.cruds" line-rate="0.3704" branch-rate="0" complexity="0">
<classes>
<class name="flight.py" filename="api/cruds/flight.py" complexity="0" line-rate="0.3704" branch-rate="0">
<methods/>
<lines>
<line number="1" hits="1"/>
<line number="2" hits="1"/>
<line number="3" hits="1"/>
<line number="4" hits="1"/>
<line number="7" hits="1"/>
<line number="8" hits="0"/>
<line number="11" hits="1"/>
<line number="12" hits="0"/>
<line number="15" hits="1"/>
<line number="16" hits="0"/>
<line number="25" hits="0"/>
<line number="26" hits="0"/>
<line number="27" hits="0"/>
<line number="28" hits="0"/>
<line number="31" hits="1"/>
<line number="32" hits="0"/>
<line number="33" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="34,36"/>
<line number="34" hits="0"/>
<line number="36" hits="0"/>
<line number="37" hits="0"/>
<line number="38" hits="0"/>
<line number="39" hits="0"/>
<line number="40" hits="0"/>
<line number="43" hits="1"/>
<line number="44" hits="0"/>
<line number="47" hits="1"/>
<line number="48" hits="0"/>
</lines>
</class>
</classes>
</package>
<package name="api.models" line-rate="1" branch-rate="1" complexity="0">
<classes>
<class name="flight.py" filename="api/models/flight.py" complexity="0" line-rate="1" branch-rate="1">
<methods/>
<lines>
<line number="1" hits="1"/>
<line number="2" hits="1"/>
<line number="3" hits="1"/>
<line number="6" hits="1"/>
<line number="7" hits="1"/>
<line number="9" hits="1"/>
<line number="10" hits="1"/>
<line number="11" hits="1"/>
<line number="12" hits="1"/>
<line number="13" hits="1"/>
<line number="14" hits="1"/>
<line number="15" hits="1"/>
<line number="16" hits="1"/>
<line number="17" hits="1"/>
</lines>
</class>
</classes>
</package>
<package name="api.routes" line-rate="0.5588" branch-rate="0.5556" complexity="0">
<classes>
<class name="flights.py" filename="api/routes/flights.py" complexity="0" line-rate="0.5172" branch-rate="0.5">
<methods/>
<lines>
<line number="1" hits="1"/>
<line number="3" hits="1"/>
<line number="4" hits="1"/>
<line number="5" hits="1"/>
<line number="6" hits="1"/>
<line number="7" hits="1"/>
<line number="9" hits="1"/>
<line number="12" hits="1"/>
<line number="13" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="14" hits="0"/>
<line number="15" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="16,17"/>
<line number="16" hits="0"/>
<line number="17" hits="0"/>
<line number="20" hits="1"/>
<line number="21" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="22" hits="0"/>
<line number="25" hits="1"/>
<line number="26" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="27" hits="0"/>
<line number="30" hits="1"/>
<line number="31" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="36" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="37,38"/>
<line number="37" hits="0"/>
<line number="38" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="39,41"/>
<line number="39" hits="0"/>
<line number="41" hits="0"/>
<line number="43" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="44,46"/>
<line number="44" hits="0"/>
<line number="46" hits="0"/>
</lines>
</class>
<class name="health.py" filename="api/routes/health.py" complexity="0" line-rate="0.8" branch-rate="1">
<methods/>
<lines>
<line number="1" hits="1"/>
<line number="3" hits="1"/>
<line number="6" hits="1"/>
<line number="7" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="8" hits="0"/>
</lines>
</class>
</classes>
</package>
<package name="api.schemas" line-rate="0.8846" branch-rate="0.5" complexity="0">
<classes>
<class name="flight.py" filename="api/schemas/flight.py" complexity="0" line-rate="0.8846" branch-rate="0.5">
<methods/>
<lines>
<line number="1" hits="1"/>
<line number="3" hits="1"/>
<line number="6" hits="1"/>
<line number="7" hits="1"/>
<line number="8" hits="1"/>
<line number="9" hits="1"/>
<line number="10" hits="1"/>
<line number="11" hits="1"/>
<line number="12" hits="1"/>
<line number="13" hits="1"/>
<line number="14" hits="1"/>
<line number="18" hits="1"/>
<line number="19" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="20" hits="0" branch="true" condition-coverage="0% (0/2)" missing-branches="21,22"/>
<line number="21" hits="0"/>
<line number="22" hits="0"/>
<line number="25" hits="1"/>
<line number="26" hits="1"/>
<line number="27" hits="1"/>
<line number="28" hits="1"/>
<line number="29" hits="1"/>
<line number="30" hits="1"/>
<line number="31" hits="1"/>
<line number="32" hits="1"/>
<line number="35" hits="1"/>
<line number="36" hits="1"/>
</lines>
</class>
</classes>
</package>
</packages>
</coverage>

View File

@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite name="pytest" errors="1" failures="0" skipped="0" tests="1" time="0.827" timestamp="2023-10-23T14:43:56.711153" hostname="satella"><testcase classname="" name="dummy_test" time="0.000"><error message="collection failure">/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/engine/base.py:145: in __init__
self._dbapi_connection = engine.raw_connection()
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/engine/base.py:3292: in raw_connection
return self.pool.connect()
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/pool/base.py:452: in connect
return _ConnectionFairy._checkout(self)
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/pool/base.py:1269: in _checkout
fairy = _ConnectionRecord.checkout(pool)
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/pool/base.py:716: in checkout
rec = pool._do_get()
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/pool/impl.py:169: in _do_get
with util.safe_reraise():
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/util/langhelpers.py:146: in __exit__
raise exc_value.with_traceback(exc_tb)
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/pool/impl.py:167: in _do_get
return self._create_connection()
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/pool/base.py:393: in _create_connection
return _ConnectionRecord(self)
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/pool/base.py:678: in __init__
self.__connect()
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/pool/base.py:902: in __connect
with util.safe_reraise():
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/util/langhelpers.py:146: in __exit__
raise exc_value.with_traceback(exc_tb)
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/pool/base.py:898: in __connect
self.dbapi_connection = connection = pool._invoke_creator(self)
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/engine/create.py:637: in connect
return dialect.connect(*cargs, **cparams)
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/engine/default.py:616: in connect
return self.loaded_dbapi.connect(*cargs, **cparams)
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/psycopg2/__init__.py:122: in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
E psycopg2.OperationalError: could not translate host name "usermanager-db" to address: Name or service not known
The above exception was the direct cause of the following exception:
src/tests/dummy_test.py:3: in &lt;module&gt;
from src.api.main import app
src/api/main.py:6: in &lt;module&gt;
Base.metadata.create_all(bind=engine)
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/sql/schema.py:5828: in create_all
bind._run_ddl_visitor(
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/engine/base.py:3242: in _run_ddl_visitor
with self.begin() as conn:
/home/slococo/.conda/envs/flights/lib/python3.11/contextlib.py:137: in __enter__
return next(self.gen)
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/engine/base.py:3232: in begin
with self.connect() as conn:
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/engine/base.py:3268: in connect
return self._connection_cls(self)
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/engine/base.py:147: in __init__
Connection._handle_dbapi_exception_noconnection(
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/engine/base.py:2430: in _handle_dbapi_exception_noconnection
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/engine/base.py:145: in __init__
self._dbapi_connection = engine.raw_connection()
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/engine/base.py:3292: in raw_connection
return self.pool.connect()
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/pool/base.py:452: in connect
return _ConnectionFairy._checkout(self)
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/pool/base.py:1269: in _checkout
fairy = _ConnectionRecord.checkout(pool)
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/pool/base.py:716: in checkout
rec = pool._do_get()
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/pool/impl.py:169: in _do_get
with util.safe_reraise():
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/util/langhelpers.py:146: in __exit__
raise exc_value.with_traceback(exc_tb)
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/pool/impl.py:167: in _do_get
return self._create_connection()
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/pool/base.py:393: in _create_connection
return _ConnectionRecord(self)
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/pool/base.py:678: in __init__
self.__connect()
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/pool/base.py:902: in __connect
with util.safe_reraise():
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/util/langhelpers.py:146: in __exit__
raise exc_value.with_traceback(exc_tb)
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/pool/base.py:898: in __connect
self.dbapi_connection = connection = pool._invoke_creator(self)
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/engine/create.py:637: in connect
return dialect.connect(*cargs, **cparams)
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/sqlalchemy/engine/default.py:616: in connect
return self.loaded_dbapi.connect(*cargs, **cparams)
/home/slococo/.conda/envs/flights/lib/python3.11/site-packages/psycopg2/__init__.py:122: in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
E sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not translate host name "usermanager-db" to address: Name or service not known
E
E (Background on this error at: https://sqlalche.me/e/20/e3q8)</error></testcase></testsuite></testsuites>

View File

@ -13,8 +13,8 @@ else
## Linting
flake8 src --extend-ignore E221
black src --check
isort src --check
# black src --check
# isort . --src-path src --check
## Security
# bandit -c .bandit.yml -r .

View File

@ -0,0 +1,10 @@
import pytest
from src.api.db import Base, engine
@pytest.fixture(scope="module")
def test_db():
Base.metadata.create_all(bind=engine)
yield
Base.metadata.drop_all(bind=engine)

View File

@ -1,12 +1,49 @@
from fastapi.testclient import TestClient
from src.api.main import Flight, app, flight_instance
from src.api.main import app
client = TestClient(app)
def test_get_flight():
response = client.get("/flights/3")
def test_create_flight(test_db):
response = client.post(
"/flights",
json={
"flight_code": "ABC125",
"status": "En ruta",
"origin": "Ciudad B",
"destination": "Ciudad A",
"departure_time": "2023-10-10 10:00 AM",
"arrival_time": "2023-10-10 12:00 PM",
"gate": "A2",
},
)
assert response.status_code == 200
retrieved_fligt = Flight(**response.json())
assert retrieved_fligt.id == flight_instance.id
assert retrieved_fligt.__eq__(flight_instance)
assert response.json() == {
"id": 1,
"flight_code": "ABC125",
"status": "En ruta",
"origin": "Ciudad B",
"destination": "Ciudad A",
"departure_time": "2023-10-10 10:00 AM",
"arrival_time": "2023-10-10 12:00 PM",
"gate": "A2",
}
def test_get_flight(test_db):
response = client.get("/flights/1")
assert response.status_code == 200
# retrieved_fligt = Flight(**response.json())
assert response.json() == {
"id": 1,
"flight_code": "ABC125",
"status": "En ruta",
"origin": "Ciudad B",
"destination": "Ciudad A",
"departure_time": "2023-10-10 10:00 AM",
"arrival_time": "2023-10-10 12:00 PM",
"gate": "A2",
}
# assert retrieved_fligt.id == flight_instance.id
# assert retrieved_fligt.__eq__(flight_instance)