forked from OpenHands/OpenHands
-
Notifications
You must be signed in to change notification settings - Fork 0
test: move real-DB store tests to tests/integration/ #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aivong-openhands
wants to merge
5
commits into
main
Choose a base branch
from
test/fix-store-tests-to-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
db49465
test: move real-DB store tests to tests/integration/
0f7e5cd
ci: add workflow for enterprise integration tests
690a9d8
test: auto-apply integration marker to all tests in tests/integration/
f3379db
fix(lint): fix import order in integration tests for ruff v0.4.1
3f60f84
fix(enterprise): address review comments in integration test conftest…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| name: Run Enterprise Integration Tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| pull_request: | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ (github.head_ref && github.ref) || github.run_id }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| test-enterprise-integration: | ||
| name: Enterprise Python Integration Tests | ||
| runs-on: ubuntu-24.04 | ||
| strategy: | ||
| matrix: | ||
| python-version: ["3.12"] | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - name: Install poetry via pipx | ||
| run: pipx install poetry | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
| cache: "poetry" | ||
| - name: Install Python dependencies using Poetry | ||
| working-directory: ./enterprise | ||
| run: poetry install --with dev,test | ||
| - name: Run Integration Tests | ||
| # Use base working directory for coverage paths to line up. | ||
| run: PYTHONPATH=".:$PYTHONPATH" poetry run --project=enterprise pytest --forked -n auto -s -p no:ddtrace -p no:ddtrace.pytest_bdd -p no:ddtrace.pytest_benchmark ./enterprise/tests/integration --cov=enterprise --cov-branch | ||
| env: | ||
| COVERAGE_FILE: ".coverage.enterprise.integration.${{ matrix.python_version }}" | ||
| - name: Store coverage file | ||
| uses: actions/upload-artifact@v7 | ||
| with: | ||
| name: coverage-enterprise-integration | ||
| path: ".coverage.enterprise.integration.${{ matrix.python_version }}" | ||
| include-hidden-files: true | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import asyncio | ||
| import os | ||
|
|
||
| import pytest | ||
| from sqlalchemy import create_engine | ||
| from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine | ||
| from sqlalchemy.orm import sessionmaker | ||
|
|
||
| # Import all models so their tables are created. | ||
| from storage.api_key import ApiKey # noqa: F401 | ||
| from storage.base import Base | ||
| from storage.billing_session import BillingSession # noqa: F401 | ||
| from storage.conversation_work import ConversationWork # noqa: F401 | ||
| from storage.device_code import DeviceCode # noqa: F401 | ||
| from storage.feedback import Feedback # noqa: F401 | ||
| from storage.github_app_installation import GithubAppInstallation # noqa: F401 | ||
| from storage.org import Org # noqa: F401 | ||
| from storage.org_git_claim import OrgGitClaim # noqa: F401 | ||
| from storage.org_invitation import OrgInvitation # noqa: F401 | ||
| from storage.org_member import OrgMember # noqa: F401 | ||
| from storage.role import Role # noqa: F401 | ||
| from storage.slack_conversation import SlackConversation # noqa: F401 | ||
| from storage.stored_conversation_metadata import ( | ||
| StoredConversationMetadata, # noqa: F401 | ||
| ) | ||
| from storage.stored_conversation_metadata_saas import ( # noqa: F401 | ||
| StoredConversationMetadataSaas, | ||
| ) | ||
| from storage.stored_offline_token import StoredOfflineToken # noqa: F401 | ||
| from storage.stripe_customer import StripeCustomer # noqa: F401 | ||
| from storage.user import User # noqa: F401 | ||
| from storage.user_settings import UserSettings # noqa: F401 | ||
|
|
||
|
|
||
| def pytest_collection_modifyitems(items): | ||
| for item in items: | ||
| item.add_marker(pytest.mark.integration) | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def allow_short_context_windows(): | ||
| old = os.environ.get('ALLOW_SHORT_CONTEXT_WINDOWS') | ||
| os.environ['ALLOW_SHORT_CONTEXT_WINDOWS'] = 'true' | ||
| try: | ||
| yield | ||
| finally: | ||
| if old is None: | ||
| os.environ.pop('ALLOW_SHORT_CONTEXT_WINDOWS', None) | ||
| else: | ||
| os.environ['ALLOW_SHORT_CONTEXT_WINDOWS'] = old | ||
|
|
||
|
|
||
| @pytest.fixture(scope='function') | ||
| def db_path(tmp_path): | ||
| """Create a unique temp file path for each test.""" | ||
| return str(tmp_path / 'test.db') | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def engine(db_path): | ||
| """Create a sync engine with tables using file-based DB.""" | ||
| engine = create_engine( | ||
| f'sqlite:///{db_path}', connect_args={'check_same_thread': False} | ||
| ) | ||
| Base.metadata.create_all(engine) | ||
| return engine | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def session_maker(engine): | ||
| return sessionmaker(bind=engine) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def async_engine(db_path): | ||
| """Create an async engine using the SAME file-based database.""" | ||
| async_engine = create_async_engine( | ||
| f'sqlite+aiosqlite:///{db_path}', | ||
| connect_args={'check_same_thread': False}, | ||
| ) | ||
|
|
||
| async def create_tables(): | ||
| async with async_engine.begin() as conn: | ||
| await conn.run_sync(Base.metadata.create_all) | ||
|
|
||
| asyncio.run(create_tables()) | ||
| return async_engine | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| @pytest.fixture | ||
| async def async_session_maker(async_engine): | ||
| """Create an async session maker bound to the async engine.""" | ||
| return async_sessionmaker( | ||
| bind=async_engine, | ||
| class_=AsyncSession, | ||
| expire_on_commit=False, | ||
| ) | ||
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.