Skip to content

test: migrate oauth tests to testcontainers#33973

Merged
asukaminato0721 merged 6 commits into
langgenius:mainfrom
Daedalus-Icarus:test/migrate-oauth-tests-to-testcontainers
Mar 24, 2026
Merged

test: migrate oauth tests to testcontainers#33973
asukaminato0721 merged 6 commits into
langgenius:mainfrom
Daedalus-Icarus:test/migrate-oauth-tests-to-testcontainers

Conversation

@Daedalus-Icarus

Copy link
Copy Markdown
Contributor

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

Migrate OAuth controller tests from mock-based unit tests to testcontainers integration
tests by moving test_oauth.py from unit_tests/ to test_containers_integration_tests/.

Key changes:

  • Replace standalone Flask(__name__) fixtures with flask_app_with_containers
  • Remove db and Session mock patches (8 occurrences) — real DB session is now available
  • Rewrite get_account_by_email_with_case_fallback test to query real PostgreSQL
    instead of mocking session.execute side effects
  • Simplify _get_account_by_openid_or_email test by removing Session context manager mock
  • External services (OAuth providers, RegisterService, FeatureService, TenantService) remain mocked

Part of #32454

Screenshots

Before After
... ...

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. (This doesn't apply to typos!)
  • 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

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-03-23 18:35:04.244083734 +0000
+++ /tmp/pyrefly_pr.txt	2026-03-23 18:34:54.557135726 +0000
@@ -792,6 +792,12 @@
    --> tests/test_containers_integration_tests/conftest.py:198:39
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/controllers/console/app/test_chat_conversation_status_count_api.py:33:48
+ERROR Object of class `RequestError` has no attribute `response` [missing-attribute]
+   --> tests/test_containers_integration_tests/controllers/console/auth/test_oauth.py:198:9
+ERROR Object of class `RequestError` has no attribute `response` [missing-attribute]
+   --> tests/test_containers_integration_tests/controllers/console/auth/test_oauth.py:199:9
+ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
+   --> tests/test_containers_integration_tests/controllers/console/auth/test_oauth.py:436:20
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/controllers/console/helpers.py:40:48
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
@@ -1974,10 +1980,6 @@
    --> tests/unit_tests/controllers/console/auth/test_login_logout.py:467:16
 ERROR `None` is not subscriptable [unsupported-operation]
    --> tests/unit_tests/controllers/console/auth/test_login_logout.py:495:16
-ERROR Object of class `RequestError` has no attribute `response` [missing-attribute]
-   --> tests/unit_tests/controllers/console/auth/test_oauth.py:206:9
-ERROR Object of class `RequestError` has no attribute `response` [missing-attribute]
-   --> tests/unit_tests/controllers/console/auth/test_oauth.py:207:9
 ERROR Object of class `tuple` has no attribute `json` [missing-attribute]
   --> tests/unit_tests/controllers/console/auth/test_token_refresh.py:74:16
 ERROR Type `Response` is not iterable [not-iterable]

@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-03-23 18:37:15.544768008 +0000
+++ /tmp/pyrefly_pr.txt	2026-03-23 18:37:06.633640752 +0000
@@ -792,6 +792,12 @@
    --> tests/test_containers_integration_tests/conftest.py:198:39
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/controllers/console/app/test_chat_conversation_status_count_api.py:33:48
+ERROR Object of class `RequestError` has no attribute `response` [missing-attribute]
+   --> tests/test_containers_integration_tests/controllers/console/auth/test_oauth.py:196:9
+ERROR Object of class `RequestError` has no attribute `response` [missing-attribute]
+   --> tests/test_containers_integration_tests/controllers/console/auth/test_oauth.py:197:9
+ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
+   --> tests/test_containers_integration_tests/controllers/console/auth/test_oauth.py:432:20
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/controllers/console/helpers.py:40:48
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
@@ -1974,10 +1980,6 @@
    --> tests/unit_tests/controllers/console/auth/test_login_logout.py:467:16
 ERROR `None` is not subscriptable [unsupported-operation]
    --> tests/unit_tests/controllers/console/auth/test_login_logout.py:495:16
-ERROR Object of class `RequestError` has no attribute `response` [missing-attribute]
-   --> tests/unit_tests/controllers/console/auth/test_oauth.py:206:9
-ERROR Object of class `RequestError` has no attribute `response` [missing-attribute]
-   --> tests/unit_tests/controllers/console/auth/test_oauth.py:207:9
 ERROR Object of class `tuple` has no attribute `json` [missing-attribute]
   --> tests/unit_tests/controllers/console/auth/test_token_refresh.py:74:16
 ERROR Type `Response` is not iterable [not-iterable]

@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-03-23 18:51:17.874306814 +0000
+++ /tmp/pyrefly_pr.txt	2026-03-23 18:51:07.770284015 +0000
@@ -792,6 +792,10 @@
    --> tests/test_containers_integration_tests/conftest.py:198:39
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/controllers/console/app/test_chat_conversation_status_count_api.py:33:48
+ERROR Object of class `RequestError` has no attribute `response` [missing-attribute]
+   --> tests/test_containers_integration_tests/controllers/console/auth/test_oauth.py:196:9
+ERROR Object of class `RequestError` has no attribute `response` [missing-attribute]
+   --> tests/test_containers_integration_tests/controllers/console/auth/test_oauth.py:197:9
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/controllers/console/helpers.py:40:48
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
@@ -1974,10 +1978,6 @@
    --> tests/unit_tests/controllers/console/auth/test_login_logout.py:467:16
 ERROR `None` is not subscriptable [unsupported-operation]
    --> tests/unit_tests/controllers/console/auth/test_login_logout.py:495:16
-ERROR Object of class `RequestError` has no attribute `response` [missing-attribute]
-   --> tests/unit_tests/controllers/console/auth/test_oauth.py:206:9
-ERROR Object of class `RequestError` has no attribute `response` [missing-attribute]
-   --> tests/unit_tests/controllers/console/auth/test_oauth.py:207:9
 ERROR Object of class `tuple` has no attribute `json` [missing-attribute]
   --> tests/unit_tests/controllers/console/auth/test_token_refresh.py:74:16
 ERROR Type `Response` is not iterable [not-iterable]

@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-03-24 03:20:07.323950115 +0000
+++ /tmp/pyrefly_pr.txt	2026-03-24 03:19:58.414835500 +0000
@@ -792,6 +792,10 @@
    --> tests/test_containers_integration_tests/conftest.py:198:39
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/controllers/console/app/test_chat_conversation_status_count_api.py:33:48
+ERROR Object of class `RequestError` has no attribute `response` [missing-attribute]
+   --> tests/test_containers_integration_tests/controllers/console/auth/test_oauth.py:196:9
+ERROR Object of class `RequestError` has no attribute `response` [missing-attribute]
+   --> tests/test_containers_integration_tests/controllers/console/auth/test_oauth.py:197:9
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/controllers/console/helpers.py:40:48
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
@@ -1974,10 +1978,6 @@
    --> tests/unit_tests/controllers/console/auth/test_login_logout.py:467:16
 ERROR `None` is not subscriptable [unsupported-operation]
    --> tests/unit_tests/controllers/console/auth/test_login_logout.py:495:16
-ERROR Object of class `RequestError` has no attribute `response` [missing-attribute]
-   --> tests/unit_tests/controllers/console/auth/test_oauth.py:206:9
-ERROR Object of class `RequestError` has no attribute `response` [missing-attribute]
-   --> tests/unit_tests/controllers/console/auth/test_oauth.py:207:9
 ERROR Object of class `tuple` has no attribute `json` [missing-attribute]
   --> tests/unit_tests/controllers/console/auth/test_token_refresh.py:74:16
 ERROR Type `Response` is not iterable [not-iterable]

@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-03-24 03:22:32.049237689 +0000
+++ /tmp/pyrefly_pr.txt	2026-03-24 03:22:21.810162489 +0000
@@ -792,6 +792,10 @@
    --> tests/test_containers_integration_tests/conftest.py:198:39
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/controllers/console/app/test_chat_conversation_status_count_api.py:33:48
+ERROR Object of class `RequestError` has no attribute `response` [missing-attribute]
+   --> tests/test_containers_integration_tests/controllers/console/auth/test_oauth.py:196:9
+ERROR Object of class `RequestError` has no attribute `response` [missing-attribute]
+   --> tests/test_containers_integration_tests/controllers/console/auth/test_oauth.py:197:9
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/controllers/console/helpers.py:40:48
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
@@ -1974,10 +1978,6 @@
    --> tests/unit_tests/controllers/console/auth/test_login_logout.py:467:16
 ERROR `None` is not subscriptable [unsupported-operation]
    --> tests/unit_tests/controllers/console/auth/test_login_logout.py:495:16
-ERROR Object of class `RequestError` has no attribute `response` [missing-attribute]
-   --> tests/unit_tests/controllers/console/auth/test_oauth.py:206:9
-ERROR Object of class `RequestError` has no attribute `response` [missing-attribute]
-   --> tests/unit_tests/controllers/console/auth/test_oauth.py:207:9
 ERROR Object of class `tuple` has no attribute `json` [missing-attribute]
   --> tests/unit_tests/controllers/console/auth/test_token_refresh.py:74:16
 ERROR Type `Response` is not iterable [not-iterable]

@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-03-24 12:29:44.945544666 +0000
+++ /tmp/pyrefly_pr.txt	2026-03-24 12:29:35.496453685 +0000
@@ -792,6 +792,10 @@
    --> tests/test_containers_integration_tests/conftest.py:198:39
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/controllers/console/app/test_chat_conversation_status_count_api.py:33:48
+ERROR Object of class `RequestError` has no attribute `response` [missing-attribute]
+   --> tests/test_containers_integration_tests/controllers/console/auth/test_oauth.py:196:9
+ERROR Object of class `RequestError` has no attribute `response` [missing-attribute]
+   --> tests/test_containers_integration_tests/controllers/console/auth/test_oauth.py:197:9
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/controllers/console/helpers.py:40:48
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
@@ -1982,10 +1986,6 @@
    --> tests/unit_tests/controllers/console/auth/test_login_logout.py:467:16
 ERROR `None` is not subscriptable [unsupported-operation]
    --> tests/unit_tests/controllers/console/auth/test_login_logout.py:495:16
-ERROR Object of class `RequestError` has no attribute `response` [missing-attribute]
-   --> tests/unit_tests/controllers/console/auth/test_oauth.py:206:9
-ERROR Object of class `RequestError` has no attribute `response` [missing-attribute]
-   --> tests/unit_tests/controllers/console/auth/test_oauth.py:207:9
 ERROR Object of class `tuple` has no attribute `json` [missing-attribute]
   --> tests/unit_tests/controllers/console/auth/test_token_refresh.py:74:16
 ERROR Type `Response` is not iterable [not-iterable]

@Daedalus-Icarus

Copy link
Copy Markdown
Contributor Author

@asukaminato0721 Could you please take a look on this PR?

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Mar 24, 2026
@asukaminato0721
asukaminato0721 merged commit 542c1a1 into langgenius:main Mar 24, 2026
14 checks passed
@Daedalus-Icarus
Daedalus-Icarus deleted the test/migrate-oauth-tests-to-testcontainers branch March 24, 2026 12:57
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:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants