コード例 #1
0
def create_demo_user(
    client,
    cpf="00000000000",
    email="*****@*****.**",
    password="******",
    super_user=True,
    use_shared_secret=True,
) -> Response:
    """
    Creates a user for testing purposes
    """

    headers = {}
    if use_shared_secret:
        headers["authorization"] = get_settings().upload_secret

    payload = {
        "cpf": cpf,
        "name": "Teste",
        "email": email,
        "password": password,
        "is_superuser": super_user,
    }

    response = client.post("/users/", json=payload, headers=headers)
    return response
コード例 #2
0
ファイル: test_users.py プロジェクト: fbidu/api_foot
    def test_create_superuser_with_token(self):
        """
        Usando o shared secret, uma pessoa pode criar um superuser
        """
        headers = {"authorization": get_settings().upload_secret}

        payload = {
            "cpf": "12345678900",
            "name": "A",
            "email": None,
            "login": "******",
            "is_superuser": True,
            "is_staff": False,
            "password": "******",
        }

        response = self.client.post("/users/", json=payload, headers=headers)

        assert response.status_code == 201

        password = payload.pop("password")
        assert_response_matches_payload(response, payload, expected_status=201)

        db_user = find_user(self.db, username=payload["cpf"])
        assert db_user

        assert verify_password(password, db_user.password)
        assert db_user.is_superuser
コード例 #3
0
def test_post_templates_results_csv(client, db):
    """
    Testa se o envio de um arquivo para /csv retorna o número de linhas nele
    """
    header = {"authorization": get_settings().upload_secret}
    sample_file = Path("tests/demo_templates_result.csv").absolute()
    files = {"csv_file": open(sample_file, "r")}
    results = import_test_results(db)
    response = client.post("/csv/?type=templates_results",
                           files=files,
                           headers=header)

    assert response.status_code == 200
    assert response.json()

    content = response.json()

    assert content["lines"] == 40

    db_objects = db.query(TemplatesResult).all()
    assert len(db_objects) == 40

    template_sms_0 = db_objects[0]

    assert template_sms_0.template_id == 1
    assert template_sms_0.IDExport == results[0].IDExport
    assert template_sms_0.result.IDExport == results[0].IDExport
コード例 #4
0
def post_pdf(sample_pdf, client) -> Response:
    """
    Posts a file to the main PDF endpoint
    """
    files = {"pdf_file": open(sample_pdf, "rb")}
    return client.post("/pdf/",
                       files=files,
                       headers={"authorization": get_settings().upload_secret})
コード例 #5
0
def test_post_results_csv(client, db):
    """
    Testa se o envio de um arquivo para /csv retorna o número de linhas nele
    """
    header = {"authorization": get_settings().upload_secret}
    sample_file = Path("tests/demo.csv").absolute()
    files = {"csv_file": open(sample_file, "r")}
    response = client.post("/csv/?type=results", files=files, headers=header)

    assert response.status_code == 200
    assert response.json()

    content = response.json()

    assert content["lines"] == 40

    db_results = read_results(db)
    assert len(db_results) == 40
コード例 #6
0
def test_post_hospitals_csv(client, db):
    """
    Testa se o envio de um arquivo para /csv de hospital funciona
    """
    header = {"authorization": get_settings().upload_secret}
    sample_file = Path("tests/demo_hospital.csv").absolute()
    files = {"csv_file": open(sample_file, "r")}

    response = client.post("/csv/?type=hospitals", files=files, headers=header)

    assert response.status_code == 200
    assert response.json()

    content = response.json()

    assert content["lines"] == 2

    db_objects = db.query(HospitalCS).all()
    assert len(db_objects) == 2
コード例 #7
0
ファイル: test_settings.py プロジェクト: fbidu/api_foot
def settings():
    """
    Returns a new setting instance
    """
    return get_settings()
コード例 #8
0
ファイル: conftest.py プロジェクト: fbidu/api_foot
"""
Provides fixtures for Pytest tests
"""
from fastapi.testclient import TestClient
from pytest import fixture
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from api_pezao import deps, main
from api_pezao.database import Base

POSTGRES_URL = deps.get_settings().postgres_url

if POSTGRES_URL:
    engine = create_engine(POSTGRES_URL, pool_pre_ping=True)
else:
    engine = create_engine("sqlite:///./test.db",
                           connect_args={"check_same_thread": False})

TestingSessionLocal = sessionmaker(autocommit=False,
                                   autoflush=False,
                                   bind=engine)

Base.metadata.create_all(bind=engine)


@fixture
def db():
    """
    Overrides the default db for testing
    """