Skip to content

Corrige tests de researcher#1452

Merged
robertatakenaka merged 2 commits into
scieloorg:mainfrom
robertatakenaka:fix_researcher_and_editorialm_tests
Jul 22, 2026
Merged

Corrige tests de researcher#1452
robertatakenaka merged 2 commits into
scieloorg:mainfrom
robertatakenaka:fix_researcher_and_editorialm_tests

Conversation

@robertatakenaka

@robertatakenaka robertatakenaka commented Jul 22, 2026

Copy link
Copy Markdown
Member

O que esse PR faz?

Corrige test_researcher_id_create_with_wrong_lattes, que testava por
engano um identifier de e-mail ("user.teste", source_name="EMAIL") —
o mesmo cenário já coberto por test_researcher_id_create_with_wrong_email
— em vez de um identifier de Lattes em formato inválido. Corrigido para
identifier="invalid_lattes_format", source_name="LATTES", dando ao
teste a cobertura real que seu nome promete.

Além disso, limpa problemas de estilo acumulados no arquivo: typo em
subTest, comentários redundantes, assertEqual duplicados, espaços em
branco desnecessários, e corrige o setUp de AffiliationMixinTest, que
usava Country.acron2 e Location.objects.create — nenhum dos dois
corresponde à interface atual dos models — substituídos por
Country.acronym e Location.create_or_update. Fixtures de acronym
que ultrapassavam max_length=20 também foram corrigidas.

Onde a revisão poderia começar?

test_researcher_id_create_with_wrong_lattes, para confirmar que o novo
identifier ("invalid_lattes_format") realmente é um formato de Lattes
inválido e que a exceção esperada (ValidationError) é a levantada pela
validação real. Em seguida, AffiliationMixinTest.setUp, para confirmar
que os parâmetros usados batem com a assinatura atual de Country e
Location.

Como este poderia ser testado manualmente?

  1. Rodar python manage.py test researcher e confirmar que todos os
    testes passam, incluindo test_researcher_id_create_with_wrong_lattes
    e test_researcher_id_create_with_wrong_email separadamente.
  2. Confirmar que AffiliationMixinTest passa com os novos parâmetros de
    Country/Location.
django@d472b88177fe:/app$ python manage.py test researcher.tests --keepdb
WARNING 2026-07-22 15:26:44,985 profiling_tools 17 281473227738432 PROFILING_ENABLED=True
WARNING 2026-07-22 15:26:44,985 profiling_tools 17 281473227738432 PROFILING_LOG_ALL=True
WARNING 2026-07-22 15:26:44,985 profiling_tools 17 281473227738432 PROFILING_LOG_SLOW_REQUESTS=0.2
WARNING 2026-07-22 15:26:44,985 profiling_tools 17 281473227738432 PROFILING_LOG_HIGH_MEMORY=20
/usr/local/lib/python3.11/site-packages/django/db/backends/utils.py:98: RuntimeWarning: Accessing the database during app initialization is discouraged. To fix this warning, avoid executing queries in AppConfig.ready() or when your app modules are imported.
  warnings.warn(self.APPS_NOT_READY_WARNING_MSG, category=RuntimeWarning)
Found 30 test(s).
Using existing test database for alias 'default'...
System check identified some issues:

WARNINGS:
?: (urls.W005) URL namespace 'pid_provider' isn't unique. You may not be able to reverse all URLs in this namespace
?: (wagtailadmin.W003) The WAGTAILADMIN_BASE_URL setting is not defined
	HINT: This should be the base URL used to access the Wagtail admin site. Without this, admin URLs outside of the admin (e.g. notification emails and the user bar) will not display correctly.
?: settings.ACCOUNT_AUTHENTICATION_METHOD is deprecated, use: settings.ACCOUNT_LOGIN_METHODS = {'username'}
?: settings.ACCOUNT_EMAIL_REQUIRED is deprecated, use: settings.ACCOUNT_SIGNUP_FIELDS = ['email*', 'username*', 'password1*', 'password2*']
pid_provider.FixPidV2.pid_provider_xml: (fields.W342) Setting unique=True on a ForeignKey has the same effect as using a OneToOneField.
	HINT: ForeignKey(unique=True) is usually better served by a OneToOneField.

System check identified 5 issues (0 silenced).
..............................
----------------------------------------------------------------------
Ran 30 tests in 0.363s

OK

Algum cenário de contexto que queira dar?

Esse bug (teste de Lattes testando e-mail) só ficou claro ao comparar a
posição do trecho alterado com o restante do arquivo — o nome do método
não deixava dúvida sobre a intenção, mas o corpo testava outra coisa.
Aproveitou-se a limpeza para resolver, no mesmo PR, os pequenos problemas
de estilo e a desatualização do setUp de AffiliationMixinTest em
relação aos models atuais.

Screenshots

Não aplicável.

Quais são os tickets relevantes?

Relacionado com #1450, #1451

Referências

Comparação com test_researcher_id_create_with_wrong_email, no mesmo
arquivo.


Segurança da informação (NSI.04)

Este PR manipula dados sensíveis ou pessoais (LGPD)?

  • Não

Este PR altera autenticação, autorização, controle de acesso ou gerenciamento de sessão?

  • Não

Este PR introduz, atualiza ou remove dependências de terceiros?

  • Não

Este PR foi validado pelo pipeline de segurança (SonarQube / Trivy)?

  • Não aplicável a este PR (justifique): correção de teste e limpeza de estilo, sem alteração de lógica de produção.

Este PR concatena, monta ou executa comandos SQL, HTML ou JavaScript a partir de entrada externa?

  • Não

Este PR expõe novos endpoints, telas ou serviços?

  • Não

Algum segredo, senha, chave ou token está sendo adicionado ao código-fonte?

  • Não, nenhum segredo foi commitado

Propósito
test_researcher_id_create_with_wrong_lattes estava sem a instrução
'with self.assertRaises(...):' antes da chamada de
ResearcherIds.get_or_create, deixando o bloco indentado sem nenhum
with/if/for correspondente. Isso causa IndentationError ao importar o
módulo, derrubando toda a suíte de testes de researcher (e não apenas
este teste).

Solução técnica
Adicionada a linha 'with self.assertRaises(ValidationError):' antes da
chamada de ResearcherIds.get_or_create(identifier='invalid_lattes_format',
source_name='LATTES'), seguindo o mesmo padrão já usado em
test_researcher_id_create_with_wrong_email e nos testes de ORCID inválido
deste mesmo arquivo.
@robertatakenaka
robertatakenaka force-pushed the fix_researcher_and_editorialm_tests branch from f0c5991 to e2f28e0 Compare July 22, 2026 18:05
@robertatakenaka robertatakenaka changed the title Fix researcher and editorialm tests Corrige tests de researcher Jul 22, 2026
@robertatakenaka
robertatakenaka merged commit 3f2f18b into scieloorg:main Jul 22, 2026
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant