Skip to content
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

feat: dynamically add workspaces in action #129

Merged
merged 16 commits into from
Nov 7, 2023
10 changes: 5 additions & 5 deletions .github/actions/integration_tests/action.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: 'Integration Tests'
description: 'Runs the Integration tests '
name: "Integration Tests"
description: "Runs the Integration tests "

inputs:
API_KEY:
description: 'The API_KEY for deepset Cloud'
description: "The API_KEY for deepset Cloud"
required: true
API_URL:
description: 'The API_URL for deepset Cloud'
description: "The API_URL for deepset Cloud"
required: true

outputs: {}
Expand All @@ -23,4 +23,4 @@ runs:
- name: Run SDK Tests
shell: bash
run: |
API_KEY=${{inputs.API_KEY}} API_URL=${{inputs.API_URL}} hatch run test:integration
API_KEY=${{inputs.API_KEY}} API_URL=${{inputs.API_URL}} hatch run test:integration
2 changes: 1 addition & 1 deletion .github/workflows/deploy-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ env:

jobs:
deploy-test:
if: ${{ github.event.label.name == 'test-deploy' }}`
if: ${{ github.event.label.name == 'test-deploy' }} || github.event.label.name !='integration'`
wochinge marked this conversation as resolved.
Show resolved Hide resolved
uses: ./.github/workflows/deploy.yml
with:
deployment_env: test
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/merge-queue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Merge Queue

on:
merge_group:
pull_request:
types: [labeled, synchronize]
workflow_call:
inputs:
api_url:
Expand All @@ -24,6 +26,7 @@ jobs:
name: Tests
environment: ${{ github.event.inputs.deployment_env }}
runs-on: ubuntu-latest
if: (github.event.action =='labeled' && github.event.label.name =='integration') || (github.event.action =='synchronize' && contains(github.event.pull_request.labels.*.name, 'integration')) || github.event.action =='workflow_call' || github.event_name == 'merge_group'
steps:
- uses: actions/checkout@v4
- name: Run integration tests
Expand Down
53 changes: 53 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import datetime
import json
import os
from http import HTTPStatus
from typing import List
from unittest.mock import AsyncMock, Mock
from uuid import uuid4

import httpx
import pytest
import structlog
from dotenv import load_dotenv
from tenacity import retry, stop_after_delay, wait_fixed

from deepset_cloud_sdk._api.config import CommonConfig
from deepset_cloud_sdk._api.deepset_cloud_api import DeepsetCloudAPI
Expand All @@ -24,6 +28,16 @@
logger = structlog.get_logger(__name__)


def _get_file_names(integration_config: CommonConfig, workspace_name: str) -> List[str]:
list_response = httpx.get(
f"{integration_config.api_url}/workspaces/{workspace_name}/files",
headers={"Authorization": f"Bearer {integration_config.api_key}"},
)
assert list_response.status_code == HTTPStatus.OK
file_names: List[str] = list_response.json()["data"]
return file_names


@pytest.fixture
def integration_config() -> CommonConfig:
config = CommonConfig(
Expand Down Expand Up @@ -79,3 +93,42 @@ def upload_session_response() -> UploadSession:
expires_at=datetime.datetime.now(),
aws_prefixed_request_config=AWSPrefixedRequestConfig(url="uploadURL", fields={"key": "value"}),
)


@retry(
stop=stop_after_delay(120),
wait=wait_fixed(1),
reraise=True,
)
def _wait_for_file_to_be_available(integration_config: CommonConfig, workspace_name: str) -> None:
assert len(_get_file_names(integration_config, workspace_name)) > 0


@pytest.fixture
def workspace_name(integration_config: CommonConfig) -> str:
"""Create a workspace for the tests and delete it afterwards."""
workspace_name = "sdk_integration"

# try creating workspace
response = httpx.post(
f"{integration_config.api_url}/workspaces",
json={"name": workspace_name},
headers={"Authorization": f"Bearer {integration_config.api_key}"},
)
assert response.status_code in (HTTPStatus.CREATED, HTTPStatus.CONFLICT)

if len(_get_file_names(integration_config=integration_config, workspace_name=workspace_name)) == 0:
with open("tests/data/example.txt", "rb") as example_file_txt:
response = httpx.post(
f"{integration_config.api_url}/workspaces/{workspace_name}/files",
files={
"file": ("example.txt", example_file_txt, "text/plain"),
"meta": (None, json.dumps({"find": "me"}).encode("utf-8")),
},
headers={"Authorization": f"Bearer {integration_config.api_key}"},
)
assert response.status_code == HTTPStatus.CREATED

_wait_for_file_to_be_available(integration_config, workspace_name)

return workspace_name
11 changes: 3 additions & 8 deletions tests/integration/api/test_integration_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,19 @@
from deepset_cloud_sdk._api.files import FilesAPI


@pytest.fixture
def workspace_name() -> str:
return "sdk_read"


@pytest.mark.asyncio
class TestListFiles:
async def test_list_paginated(self, integration_config: CommonConfig, workspace_name: str) -> None:
async with DeepsetCloudAPI.factory(integration_config) as deepset_cloud_api:
files_api = FilesAPI(deepset_cloud_api)
result = await files_api.list_paginated(
workspace_name=workspace_name, limit=10, name="Seven", content="HBO's", odata_filter="find eq 'me'"
workspace_name=workspace_name, limit=10, name="example", content="text", odata_filter="find eq 'me'"
)

assert result.total == 1
assert result.has_more is False
assert len(result.data) == 1
found_file = result.data[0]
assert found_file.name == "20_Light_of_the_Seven.txt"
assert found_file.size == 5044
assert found_file.name == "example.txt"
assert found_file.size > 0
assert found_file.meta == {"find": "me"}
11 changes: 4 additions & 7 deletions tests/integration/api/test_integration_upload_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
)


@pytest.fixture
def workspace_name() -> str:
return "sdk_read"


@pytest.mark.asyncio
class TestCreateUploadSessions:
async def test_create_and_close_upload_session(self, integration_config: CommonConfig, workspace_name: str) -> None:
Expand Down Expand Up @@ -44,11 +39,13 @@ async def test_list_upload_session(self, integration_config: CommonConfig, works
async with DeepsetCloudAPI.factory(integration_config) as deepset_cloud_api:
upload_session_client = UploadSessionsAPI(deepset_cloud_api)

await upload_session_client.create(workspace_name=workspace_name)

result: UploadSessionDetailList = await upload_session_client.list(
workspace_name=workspace_name, limit=3, page_number=3
workspace_name=workspace_name, limit=1, page_number=1
)

assert result.total > 0
assert result.has_more is True
assert result.data is not None
assert len(result.data) == 3
assert len(result.data) == 1
5 changes: 0 additions & 5 deletions tests/integration/service/test_integration_files_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
from deepset_cloud_sdk._service.files_service import DeepsetCloudFile, FilesService


@pytest.fixture
ArzelaAscoIi marked this conversation as resolved.
Show resolved Hide resolved
def workspace_name() -> str:
return "sdk_write"


@pytest.mark.asyncio
class TestUploadsFileService:
async def test_upload(self, integration_config: CommonConfig, workspace_name: str) -> None:
Expand Down
Loading