Skip to content

Commit

Permalink
changes in admin and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mfagundes committed May 8, 2023
1 parent c4f2503 commit e99f11c
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 7 deletions.
77 changes: 73 additions & 4 deletions basedosdados_api/api/v1/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,77 @@ class StatusAdmin(TabbedTranslationAdmin):
]


admin.site.register(Analysis)
admin.site.register(AnalysisType)
class AnalysisTypeAdmin(TabbedTranslationAdmin):
readonly_fields = [
"id",
]
list_display = [
"name",
"slug",
]
search_fields = [
"name",
"slug",
]


class AnalysisAdmin(TabbedTranslationAdmin):
readonly_fields = [
"id",
]
list_display = [
"name",
"analysis_type",
]
search_fields = [
"name",
"description",
]
autocomplete_fields = ["analysis_type", "datasets", "themes", "tags"]
filter_horizontal = ["datasets", "themes", "tags"]


class KeyAdmin(admin.ModelAdmin):
readonly_fields = [
"id",
]
list_display = [
"name",
"value",
]
search_fields = [
"name",
"value",
]


class QualityCheckAdmin(TabbedTranslationAdmin):
readonly_fields = [
"id",
]
list_display = [
"name",
"analysis",
"dataset",
"passed",
]
search_fields = [
"name",
"descriptiion",
]
autocomplete_fields = [
"analysis",
"dataset",
"table",
"column",
"key",
"raw_data_source",
"information_request",
]


admin.site.register(Analysis, AnalysisAdmin)
admin.site.register(AnalysisType, AnalysisTypeAdmin)
admin.site.register(Area, AreaAdmin)
admin.site.register(Availability, AvailabilityAdmin)
admin.site.register(BigQueryType)
Expand All @@ -542,7 +611,7 @@ class StatusAdmin(TabbedTranslationAdmin):
admin.site.register(Entity, EntityAdmin)
admin.site.register(EntityCategory, EntityCategoryAdmin)
admin.site.register(InformationRequest, InformationRequestAdmin)
admin.site.register(Key)
admin.site.register(Key, KeyAdmin)
admin.site.register(Language, LanguageAdmin)
admin.site.register(License, LicenseAdmin)
admin.site.register(ObservationLevel, ObservationLevelAdmin)
Expand All @@ -554,4 +623,4 @@ class StatusAdmin(TabbedTranslationAdmin):
admin.site.register(Tag, TagAdmin)
admin.site.register(Theme, ThemeAdmin)
admin.site.register(Update, UpdateAdmin)
admin.site.register(QualityCheck)
admin.site.register(QualityCheck, QualityCheckAdmin)
21 changes: 21 additions & 0 deletions basedosdados_api/api/v1/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
RawDataSource,
InformationRequest,
DateTimeRange,
Analysis,
)


Expand Down Expand Up @@ -113,3 +114,23 @@ def test_create_information_request(pedido_informacao, entity_escola, entity_anu
pedido_informacao.save()

assert InformationRequest.objects.exists()


@pytest.mark.django_db
def test_create_analysis(
analise_bairros,
dataset_dados_mestres,
tema_saude,
tema_educacao,
tag_aborto,
tag_covid,
usuario_inicio,
):
"""Test for Analysis."""
analise_bairros.datasets.add(dataset_dados_mestres)
analise_bairros.themes.add(tema_saude, tema_educacao)
analise_bairros.tags.add(tag_aborto, tag_covid)
analise_bairros.authors.add(usuario_inicio)
analise_bairros.save()

assert Analysis.objects.exists()
91 changes: 88 additions & 3 deletions basedosdados_api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
import pytest
import uuid

from django.contrib.auth.models import User

from basedosdados_api.account.models import Account

# from django.core.exceptions import ValidationError

from basedosdados_api.api.v1.models import (
# AnalysisType,
AnalysisType,
Table,
Dataset,
Organization,
Expand All @@ -26,7 +25,12 @@
Availability,
InformationRequest,
Status,
Coverage, EntityCategory,
Coverage,
EntityCategory,
Analysis,
Dictionary,
Key,
QualityCheck,
)


Expand Down Expand Up @@ -427,3 +431,84 @@ def fixture_pedido_informacao(
status=status_em_processamento,
started_by=usuario_inicio,
)


#############################################################################################
# Analysis fixtures
#############################################################################################


@pytest.fixture(name="analise_tipo1")
@pytest.mark.django_db
def fixture_analise_tipo1():
return AnalysisType.objects.create(
name="Análise tipo 1",
slug="analise-tipo-1",
)


@pytest.fixture(name="analise_bairros")
@pytest.mark.django_db
def fixture_analise_bairros(
analise_tipo1,
dataset_dados_mestres,
tema_saude,
tema_educacao,
tag_aborto,
tag_covid,
):
"""Fixture for Analysis."""
analysis = Analysis.objects.create(
name="Análise de bairros",
description="Descrição da análise de bairros",
analysis_type=analise_tipo1,
url="https://analise.com/bairros",
)
return analysis


@pytest.fixture(name="dicionario_1")
@pytest.mark.django_db
def test_dictionary(
coluna_nome_bairros,
):
"""Fixture for Dictionary."""
return Dictionary.objects.create(
column=coluna_nome_bairros,
)


@pytest.fixture(name="chave_1")
@pytest.mark.django_db
def fixture_chave_1(dicionario_1):
chave = Key.objects.create(dictionary=dicionario_1, name="Chave 1", value="Valor 1")

return chave


@pytest.fixture(name="teste_qualidade")
@pytest.mark.django_db
def fixture_teste_qualidade(
pipeline,
analise_bairros,
dataset_dados_mestres,
tabela_bairros,
coluna_nome_bairros,
chave_1,
raw_data_source,
pedido_informacao,
):
teste_qualidade = QualityCheck.objects.create(
name="Teste de qualidade",
description="Descrição do teste de qualidade",
passed=True,
pipeline=pipeline,
analysis=analise_bairros,
dataset=dataset_dados_mestres,
table=tabela_bairros,
column=coluna_nome_bairros,
key=chave_1,
raw_data_source=raw_data_source,
information_request=pedido_informacao,
)
return teste_qualidade

0 comments on commit e99f11c

Please sign in to comment.