diff --git a/.github/workflows/maintests.yml b/.github/workflows/maintests.yml index c239042..4333cb4 100644 --- a/.github/workflows/maintests.yml +++ b/.github/workflows/maintests.yml @@ -32,4 +32,4 @@ jobs: - name: Run pre-commit uses: pre-commit/action@v3.0.0 - name: Run unit tests - run: tox -e tests + run: tox -e tests-no-api-calls diff --git a/.github/workflows/prtests.yml b/.github/workflows/prtests.yml index 21cb76c..8a4ade7 100644 --- a/.github/workflows/prtests.yml +++ b/.github/workflows/prtests.yml @@ -37,4 +37,4 @@ jobs: - name: Run pre-commit uses: pre-commit/action@v3.0.0 - name: Run unit tests - run: tox -e tests + run: tox -e tests-no-api-calls diff --git a/src/horde_sdk/ai_horde_api/endpoints.py b/src/horde_sdk/ai_horde_api/endpoints.py index 7a99227..c0c27c1 100644 --- a/src/horde_sdk/ai_horde_api/endpoints.py +++ b/src/horde_sdk/ai_horde_api/endpoints.py @@ -1,7 +1,7 @@ from strenum import StrEnum -# AI_HORDE_BASE_URL = "https://dev.aihorde.net/api/" -AI_HORDE_BASE_URL = "http://localhost:9834/api/" +AI_HORDE_BASE_URL = "https://aihorde.net/api/" +# AI_HORDE_BASE_URL = "http://localhost:9834/api/" class AI_HORDE_API_URL_Literals(StrEnum): diff --git a/tests/ai_horde_api/test_api_calls.py b/tests/ai_horde_api/test_api_calls.py index c7b67f6..96718ec 100644 --- a/tests/ai_horde_api/test_api_calls.py +++ b/tests/ai_horde_api/test_api_calls.py @@ -5,38 +5,38 @@ from horde_sdk.generic_api.apimodels import BaseResponse -@pytest.fixture -def default_image_gen_request() -> ImageGenerateAsyncRequest: - return ImageGenerateAsyncRequest( - apikey="0000000000", - prompt="a cat in a hat", - models=["Deliberate"], - ) - +class TestAIHordeAPIClient: + @pytest.fixture + def default_image_gen_request(self) -> ImageGenerateAsyncRequest: + return ImageGenerateAsyncRequest( + apikey="0000000000", + prompt="a cat in a hat", + models=["Deliberate"], + ) -def test_AIHordeAPIClient_init(): - AIHordeAPIClient() + def test_AIHordeAPIClient_init(self): + AIHordeAPIClient() + def test_AIHordeAPIClient_async(self, default_image_gen_request: ImageGenerateAsyncRequest): + client = AIHordeAPIClient() -def test_AIHordeAPIClient_async(default_image_gen_request: ImageGenerateAsyncRequest): - client = AIHordeAPIClient() - api_response: ImageGenerateAsyncResponse | RequestErrorResponse = client.generate_image_async( - default_image_gen_request - ) + api_response: ImageGenerateAsyncResponse | RequestErrorResponse = client.generate_image_async( + default_image_gen_request + ) - if isinstance(api_response, RequestErrorResponse): - pytest.fail(f"API Response was an error: {api_response.message}") + if isinstance(api_response, RequestErrorResponse): + pytest.fail(f"API Response was an error: {api_response.message}") - assert isinstance(api_response, ImageGenerateAsyncResponse) + assert isinstance(api_response, ImageGenerateAsyncResponse) - cancel_request = CancelImageGenerateRequest(apikey="0000000000", id=api_response.id) - cancel_response: BaseResponse | RequestErrorResponse = client.submit_request(cancel_request) + cancel_request = CancelImageGenerateRequest(apikey="0000000000", id=api_response.id) + cancel_response: BaseResponse | RequestErrorResponse = client.submit_request(cancel_request) - if isinstance(cancel_response, RequestErrorResponse): - pytest.fail( - f"API Response was an error: {cancel_response.message}" - f"Please note that the job ({api_response.id}) is orphaned and will continue to run on the server" - "until it is finished, it times out or it is cancelled manually." - ) + if isinstance(cancel_response, RequestErrorResponse): + pytest.fail( + f"API Response was an error: {cancel_response.message}" + f"Please note that the job ({api_response.id}) is orphaned and will continue to run on the server" + "until it is finished, it times out or it is cancelled manually." + ) - assert isinstance(cancel_response, CancelImageGenerateRequest.get_expected_response_type()) + assert isinstance(cancel_response, CancelImageGenerateRequest.get_expected_response_type()) diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..82d1b29 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,15 @@ +def pytest_collection_modifyitems(items): + """Modifies test items in place to ensure test modules run in a given order.""" + MODULE_ORDER = ["tests_generic", "test_utils", "test_dynamically_check_apimodels"] + # `test.scripts` must run first because it downloads the legacy database + module_mapping = {item: item.module.__name__ for item in items} + + sorted_items = items.copy() + + # Iteratively move tests of each module to the end of the test queue + for module in MODULE_ORDER: + sorted_items = [it for it in sorted_items if module_mapping[it] != module] + [ + it for it in sorted_items if module_mapping[it] == module + ] + + items[:] = sorted_items diff --git a/tox.ini b/tox.ini index ac7a5ae..3a69d47 100644 --- a/tox.ini +++ b/tox.ini @@ -30,3 +30,16 @@ deps = -r requirements.txt commands = pytest tests {posargs} --cov + + +[testenv:tests-no-api-calls] +description = same as 'tests', but does not reach out to the APIs +skip_install = false +deps = + pytest>=7 + pytest-sugar + pytest-cov + requests + -r requirements.txt +commands = + pytest tests {posargs} --ignore-glob=*api_calls.py --cov \ No newline at end of file