Skip to content

test: migrate api token service tests to testcontainers#34148

Merged
asukaminato0721 merged 2 commits intolanggenius:mainfrom
YB0y:test/migrate-api-token-service-tests-to-testcontainers
Mar 26, 2026
Merged

test: migrate api token service tests to testcontainers#34148
asukaminato0721 merged 2 commits intolanggenius:mainfrom
YB0y:test/migrate-api-token-service-tests-to-testcontainers

Conversation

@YB0y
Copy link
Copy Markdown
Contributor

@YB0y YB0y commented Mar 26, 2026

Summary

Migrate tests from api/tests/unit_tests/services/test_api_token_service.py
to testcontainers integration tests at
api/tests/test_containers_integration_tests/services/test_api_token_service.py.

All 24 tests migrated. DB-dependent tests (query_token_from_db success and not-found paths) now use real PostgreSQL with ApiToken records instead of mocking Session/db. Redis cache tests and single-flight lock tests remain mocked as they test Redis-specific behavior. Deleted the unit test file.

Part of #32454

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues.
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint and make type-check (backend) and cd web && npx lint-staged (frontend) to appease the lint gods

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Mar 26, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-03-26 12:15:33.262688550 +0000
+++ /tmp/pyrefly_pr.txt	2026-03-26 12:15:22.660707995 +0000
@@ -894,6 +894,8 @@
    --> tests/test_containers_integration_tests/services/test_api_based_extension_service.py:441:72
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
    --> tests/test_containers_integration_tests/services/test_api_based_extension_service.py:527:57
+ERROR Argument `Literal['app']` is not assignable to parameter `value` with type `ApiTokenType | SQLCoreOperations[ApiTokenType]` in function `sqlalchemy.orm.base.Mapped.__set__` [bad-argument-type]
+  --> tests/test_containers_integration_tests/services/test_api_token_service.py:27:26
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
    --> tests/test_containers_integration_tests/services/test_app_dsl_service.py:112:42
 ERROR Argument `Literal['workflow']` is not assignable to parameter `value` with type `AppMode | SQLCoreOperations[AppMode]` in function `sqlalchemy.orm.base.Mapped.__set__` [bad-argument-type]

@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-03-26 12:17:35.057418480 +0000
+++ /tmp/pyrefly_pr.txt	2026-03-26 12:17:24.464350484 +0000
@@ -894,6 +894,8 @@
    --> tests/test_containers_integration_tests/services/test_api_based_extension_service.py:441:72
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
    --> tests/test_containers_integration_tests/services/test_api_based_extension_service.py:527:57
+ERROR Argument `Literal['app']` is not assignable to parameter `value` with type `ApiTokenType | SQLCoreOperations[ApiTokenType]` in function `sqlalchemy.orm.base.Mapped.__set__` [bad-argument-type]
+  --> tests/test_containers_integration_tests/services/test_api_token_service.py:27:26
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
    --> tests/test_containers_integration_tests/services/test_app_dsl_service.py:112:42
 ERROR Argument `Literal['workflow']` is not assignable to parameter `value` with type `AppMode | SQLCoreOperations[AppMode]` in function `sqlalchemy.orm.base.Mapped.__set__` [bad-argument-type]

@EndlessLucky
Copy link
Copy Markdown
Contributor

@YB0y Hi, how did you run workflow automatically? I enabled the workflow on my forked repo but the workflow doesn't work.

@asukaminato0721 asukaminato0721 added this pull request to the merge queue Mar 26, 2026
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Mar 26, 2026
Merged via the queue into langgenius:main with commit 1da66b9 Mar 26, 2026
22 checks passed
@YB0y YB0y deleted the test/migrate-api-token-service-tests-to-testcontainers branch April 1, 2026 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants