Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@
# Tempo máximo em segundos que uma tarefa pode levar para ser concluída (timeout "suave").
# `env.int()` garante que o valor lido seja um inteiro.
TASK_TIMEOUT = env.int('TASK_TIMEOUT', default=5 * 60)
RUN_ASYNC = env.bool('RUN_ASYNC', default=0)
RUN_ASYNC = env.bool('RUN_ASYNC', default=1)
# Celery Results
# ------------------------------------------------------------------------------
# https://django-celery-results.readthedocs.io/en/latest/getting_started.html
Expand Down
2 changes: 1 addition & 1 deletion config/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
default="FMiraeekXCSl3zHfg7D4oHx7ufT46HRnwnsawKgTCC53BYajVkVzb8HhOvBOHakR",
)
# https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts
ALLOWED_HOSTS = ["localhost", "0.0.0.0", "127.0.0.1", "192.168.1.98"]
ALLOWED_HOSTS = ["localhost", "0.0.0.0", "127.0.0.1", "core.local"]

# CACHES
# ------------------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions pid_provider/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
QueryBuilderPidProviderXML,
fix_get_article_data,
fix_get_data_to_compare,
fix_xml_with_pre_data,
)
from tracker.models import BaseEvent, UnexpectedEvent

Expand Down Expand Up @@ -787,7 +788,7 @@ def register(
xml_adapter_data = None

input_data = {}
input_data.update(xml_with_pre.data)
input_data.update(fix_xml_with_pre_data(xml_with_pre))
input_data.update(fix_get_article_data(xml_with_pre))
input_data["origin"] = origin
response["input_data"] = input_data
Expand Down Expand Up @@ -1387,7 +1388,7 @@ def is_registered(
try:
select_record_response = None
response = {}
response["input_data"] = xml_with_pre.data
response["input_data"] = fix_xml_with_pre_data(xml_with_pre)

xml_adapter = xml_sps_adapter.PidProviderXMLAdapter(xml_with_pre)
response["xml_adapter_data"] = xml_adapter.data
Expand Down
20 changes: 19 additions & 1 deletion pid_provider/query_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
from pid_provider import exceptions


def fix_xml_with_pre_data(xml_with_pre):
data = xml_with_pre.data
try:
pkg_names = xml_with_pre.pkg_name_variations
except AttributeError:
return data

data["pkg_names"] = sorted(item for item in (pkg_names or []) if item)
return data


def fix_get_data_to_compare(xml_adapter):
"""
packtools 4.16.11
Expand Down Expand Up @@ -217,13 +228,20 @@ def pkg_name_list(self):
todos os nomes depreciados/alternativos já usados no passado.
Valores falsy são descartados.
"""
try:
pkg_names = self.xml_adapter.xml_with_pre.pkg_name_variations
except AttributeError:
pass
else:
return {item for item in (pkg_names or []) if item}

pkg_names = set()
if self.xml_adapter.pkg_name:
pkg_names.add(self.xml_adapter.pkg_name)
if self.xml_adapter.sps_pkg_name:
pkg_names.add(self.xml_adapter.sps_pkg_name)
pkg_names.update(self.xml_adapter.xml_with_pre.deprecated_sps_pkg_name_list)
return set(item for item in pkg_names if item)
return {item for item in pkg_names if item}

def validate_input_data(self):
"""
Expand Down
47 changes: 46 additions & 1 deletion pid_provider/tests/test_query_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
para o módulo real onde essas classes/funções estão definidas no projeto,
caso seja diferente.
"""
import json
from types import SimpleNamespace
from unittest.mock import MagicMock, patch

from django.test import SimpleTestCase
Expand All @@ -34,6 +36,7 @@
compare,
compare_items,
compare_lists,
fix_xml_with_pre_data,
get_score,
zero_to_none,
)
Expand Down Expand Up @@ -82,7 +85,10 @@ def make_xml_adapter(
# configurado explicitamente aqui, senão vira um MagicMock não
# configurado (nunca None nem o valor esperado).
adapter.z_partial_body = (data or {}).get("z_partial_body")
adapter.xml_with_pre.deprecated_sps_pkg_name_list = deprecated_sps_pkg_name_list or []
del adapter.xml_with_pre.pkg_name_variations
adapter.xml_with_pre.deprecated_sps_pkg_name_list = (
deprecated_sps_pkg_name_list or []
)
adapter.xml_with_pre.body_fragment_fingerprint = body_fragment_fingerprint
adapter.xml_with_pre.body_fingerprint = body_fingerprint
# QueryBuilderPidProviderXML.__init__ lê xml_with_pre.readable_data
Expand All @@ -100,6 +106,27 @@ def make_xml_adapter(
return adapter


class FixXMLWithPreDataTests(SimpleTestCase):

def test_uses_json_safe_normalized_pkg_name_variations(self):
xml_with_pre = SimpleNamespace(
data={"pid_v3": "V3", "pkg_names": ["legacy"]},
pkg_name_variations={"pkg-b", None, "", "pkg-a"},
)

result = fix_xml_with_pre_data(xml_with_pre)

self.assertEqual(result["pkg_names"], ["pkg-a", "pkg-b"])
json.dumps(result)

def test_keeps_original_pkg_names_when_attribute_is_unavailable(self):
xml_with_pre = SimpleNamespace(data={"pkg_names": ["legacy"]})

result = fix_xml_with_pre_data(xml_with_pre)

self.assertEqual(result, {"pkg_names": ["legacy"]})


class ValidateInputDataTests(SimpleTestCase):

def test_raises_when_pub_year_missing(self):
Expand Down Expand Up @@ -188,6 +215,24 @@ def test_raises_not_enough_parameters_when_body_fragment_is_blank(self):

class PkgNameListTests(SimpleTestCase):

def test_uses_authoritative_variations_and_drops_falsy(self):
adapter = make_xml_adapter(
data={},
pkg_name="fallback-name",
sps_pkg_name="fallback-sps-name",
deprecated_sps_pkg_name_list=["fallback-deprecated-name"],
)
adapter.xml_with_pre.pkg_name_variations = {
"pkg-b",
None,
"",
"pkg-a",
}

qbuilder = QueryBuilderPidProviderXML(adapter)

self.assertEqual(qbuilder.pkg_name_list, {"pkg-a", "pkg-b"})

def test_combines_all_sources_and_drops_falsy(self):
adapter = make_xml_adapter(
data={},
Expand Down
Loading