-
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.
oper: rodando pytest na pasta correta
- Loading branch information
Showing
2 changed files
with
1 addition
and
73 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
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,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'] |