Skip to content

Commit 33debcb

Browse files
author
Datata1
committed
fix test
1 parent 62006e9 commit 33debcb

File tree

2 files changed

+35
-45
lines changed

2 files changed

+35
-45
lines changed

tests/integration/conftest.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717

1818
def pytest_addoption(parser):
19-
"""Add custom command line options for integration tests."""
2019
parser.addoption(
2120
"--run-integration",
2221
action="store_true",
@@ -26,14 +25,12 @@ def pytest_addoption(parser):
2625

2726

2827
def pytest_configure(config):
29-
"""Register custom markers."""
3028
config.addinivalue_line(
3129
"markers", "integration: mark test as integration test (requires API token)"
3230
)
3331

3432

3533
def pytest_collection_modifyitems(config, items):
36-
"""Skip integration tests unless --run-integration is passed."""
3734
if config.getoption("--run-integration"):
3835
return
3936

@@ -121,19 +118,27 @@ async def test_workspaces(
121118
) -> AsyncGenerator[List[Workspace], None]:
122119
created_workspaces: List[Workspace] = []
123120

124-
for i in range(2):
125-
workspace_name = f"{TEST_WORKSPACE_PREFIX}-{i + 1}"
121+
workspace_configs = [
122+
{"name": f"{TEST_WORKSPACE_PREFIX}-1", "git_url": None},
123+
{
124+
"name": f"{TEST_WORKSPACE_PREFIX}-git",
125+
"git_url": "https://github.com/octocat/Hello-World.git",
126+
},
127+
]
128+
129+
for config in workspace_configs:
126130
payload = WorkspaceCreate(
127131
team_id=test_team_id,
128-
name=workspace_name,
132+
name=config["name"],
129133
plan_id=test_plan_id,
134+
git_url=config["git_url"],
130135
)
131136
try:
132137
workspace = await session_sdk_client.workspaces.create(payload=payload)
133138
created_workspaces.append(workspace)
134139
log.info(f"Created test workspace: {workspace.name} (ID: {workspace.id})")
135140
except Exception as e:
136-
log.error(f"Failed to create test workspace {workspace_name}: {e}")
141+
log.error(f"Failed to create test workspace {config['name']}: {e}")
137142
for ws in created_workspaces:
138143
try:
139144
await ws.delete()
@@ -155,3 +160,17 @@ async def test_workspaces(
155160
@pytest.fixture(scope="session")
156161
async def test_workspace(test_workspaces: List[Workspace]) -> Workspace:
157162
return test_workspaces[0]
163+
164+
165+
@pytest.fixture(scope="session")
166+
def git_workspace_id(test_workspaces: List[Workspace]) -> int:
167+
return test_workspaces[1].id
168+
169+
170+
@pytest.fixture
171+
async def workspace_with_git(
172+
sdk_client: CodesphereSDK, git_workspace_id: int
173+
) -> Workspace:
174+
workspace = await sdk_client.workspaces.get(workspace_id=git_workspace_id)
175+
await workspace.wait_until_running(timeout=120.0)
176+
return workspace

tests/integration/test_git.py

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,26 @@
1-
from typing import AsyncGenerator
2-
31
import pytest
42

5-
from codesphere import CodesphereSDK
6-
from codesphere.resources.workspace import Workspace, WorkspaceCreate
3+
from codesphere.resources.workspace import Workspace
74

85
pytestmark = pytest.mark.integration
96

107

11-
@pytest.fixture(scope="session")
12-
async def git_workspace(
13-
session_sdk_client: CodesphereSDK,
14-
test_team_id: int,
15-
test_plan_id: int,
16-
) -> AsyncGenerator[Workspace, None]:
17-
payload = WorkspaceCreate(
18-
team_id=test_team_id,
19-
name="sdk-git-integration-test-git",
20-
plan_id=test_plan_id,
21-
git_url="https://github.com/octocat/Hello-World.git",
22-
)
23-
24-
workspace = await session_sdk_client.workspaces.create(payload=payload)
25-
26-
try:
27-
await workspace.wait_until_running(timeout=120.0)
28-
yield workspace
29-
finally:
30-
try:
31-
await workspace.delete()
32-
except Exception:
33-
pass
34-
35-
368
class TestGitIntegration:
379
@pytest.mark.asyncio
38-
async def test_get_head(self, git_workspace: Workspace):
39-
result = await git_workspace.git.get_head()
10+
async def test_get_head(self, workspace_with_git: Workspace):
11+
result = await workspace_with_git.git.get_head()
4012

4113
assert result.head is not None
4214
assert len(result.head) > 0
4315

4416
@pytest.mark.asyncio
45-
async def test_pull_default(self, git_workspace: Workspace):
46-
# This should not raise an exception
47-
await git_workspace.git.pull()
17+
async def test_pull_default(self, workspace_with_git: Workspace):
18+
await workspace_with_git.git.pull()
4819

4920
@pytest.mark.asyncio
50-
async def test_pull_with_remote(self, git_workspace: Workspace):
51-
await git_workspace.git.pull(remote="origin")
21+
async def test_pull_with_remote(self, workspace_with_git: Workspace):
22+
await workspace_with_git.git.pull(remote="origin")
5223

5324
@pytest.mark.asyncio
54-
async def test_pull_with_remote_and_branch(self, git_workspace: Workspace):
55-
await git_workspace.git.pull(remote="origin", branch="master")
25+
async def test_pull_with_remote_and_branch(self, workspace_with_git: Workspace):
26+
await workspace_with_git.git.pull(remote="origin", branch="master")

0 commit comments

Comments
 (0)