Skip to content

Commit

Permalink
oper: rodando pytest na pasta correta
Browse files Browse the repository at this point in the history
  • Loading branch information
iagocpv committed Nov 5, 2024
1 parent 7204194 commit 15c88a6
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 73 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/testAndDeploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
max-parallel: 4
matrix:
python-version: [3.12]

steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -58,7 +57,7 @@ jobs:
- name: Run Tests
run: |
pytest
cd src/tupan && pytest
- name: Stop PostgreSQL container
run: |
Expand Down
71 changes: 0 additions & 71 deletions src/tupan/alertas/tests.py
Original file line number Diff line number Diff line change
@@ -1,73 +1,2 @@
import pytest
import json
from django.urls import reverse
from .models import Alerta, HistoricoAlerta

@pytest.fixture
def alerta_auxiliar():
alerta = {
"nome": "Alerta1",
"condicao": "<2",
}
return alerta


class TestAlerta:
@pytest.mark.django_db
def teste_criar_alerta(self, alerta_auxiliar):
Alerta.objects.create(**alerta_auxiliar)

assert Alerta.objects.count() == 1
alerta_no_banco = Alerta.objects.first()

assert alerta_no_banco.pk == 1
assert alerta_no_banco.nome == alerta_auxiliar['nome']
assert alerta_no_banco.condicao == alerta_auxiliar['condicao']
assert alerta_no_banco.ativo == True

@pytest.mark.django_db
def teste_url_listar_alertas(self, client, alerta_auxiliar):
Alerta.objects.create(**alerta_auxiliar)

url = reverse("alertas")
response = client.get(url)

json_data = response.json()

assert response.status_code == 200
assert len(json_data) == 1
assert json_data[0]['nome'] == "Alerta1"
assert json_data[0]['condicao'] == "<2"

@pytest.mark.django_db
def teste_url_cadastrar_alerta(self, client, alerta_auxiliar):

url = reverse("alertas")
response = client.post(url, data=json.dumps(alerta_auxiliar), content_type="application/json")

json_data = response.json()
assert response.status_code == 201
assert json_data['nome'] == 'Alerta1'
assert json_data['ativo'] == True


class TestHistoricoAlerta:
@pytest.fixture
def historico_alerta_auxiliar(self, alerta_auxiliar):
alerta = Alerta.objects.create(**alerta_auxiliar)
hist = {
"timestamp": 1726067292,
"alerta": alerta
}
return hist

@pytest.mark.django_db
def teste_criar_historico(self, historico_alerta_auxiliar):
HistoricoAlerta.objects.create(**historico_alerta_auxiliar)

assert HistoricoAlerta.objects.count() == 1
historico_no_banco = HistoricoAlerta.objects.first()

assert historico_no_banco.pk == 1
assert historico_no_banco.timestamp == historico_alerta_auxiliar['timestamp']
assert historico_no_banco.alerta == historico_alerta_auxiliar['alerta']

0 comments on commit 15c88a6

Please sign in to comment.