Skip to content

Commit

Permalink
Remove unsupported allow_import parameter (#18)
Browse files Browse the repository at this point in the history
remove support for allow_import when creating incarnation

(it's no longer supported by foxops)
  • Loading branch information
defreng authored Sep 3, 2023
1 parent b75eb0b commit 79c6d4e
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 538 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
**/.pytest_cache/
**/.mypy_cache/
.coverage
.dmypy.json
.idea/
dist/
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,17 @@ clean:
docker ps -aq --filter "label=creator=pytest-docker-tools" | xargs docker rm -f
docker volume ls --filter "label=creator=pytest-docker-tools" --format '{{ .Name }}' | xargs docker volume rm
docker network ls --filter "label=creator=pytest-docker-tools" --format '{{ .Name }}' | xargs docker network rm

fmt:
poetry run black src tests
poetry run isort src tests

lint:
poetry run black --check --diff src tests
poetry run isort --check-only src tests
poetry run flake8 src tests

typecheck:
poetry run dmypy run -- src tests

pre-commit: fmt lint typecheck
548 changes: 63 additions & 485 deletions poetry.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ readme = "README.md"

[tool.poetry.dependencies]
python = ">=3.11,<4.0"
httpx = "^0.23.0"
httpx = "^0.24.1"
tenacity = "^8.0.1"
structlog = ">=21.2,<23.0"
structlog = "^23.1.0"

[tool.poetry.group.dev.dependencies]
# Linting
black = {extras = ["d"], version = "^22.10.0"}
flake8 = "^5.0.4"
flake8-bugbear = "^22.9.23"
black = "^23.7.0"
flake8 = "^6.1.0"
flake8-bugbear = "^23.7.10"
isort = "^5.9.3"

# Testing
pytest = "^7.1.3"
pytest-asyncio = "^0.20.1"
pytest-asyncio = "^0.21.1"
pytest-cov = "^4.0.0"
pytest-docker-tools = "^3.1.3"
pytest-mock = "^3.10.0"
Expand Down
22 changes: 4 additions & 18 deletions src/foxops_client/client_async.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import Any, Tuple
from typing import Any

import httpx
from httpx import Response
Expand Down Expand Up @@ -135,15 +135,7 @@ async def create_incarnation(
template_data: dict[str, str],
target_directory: str | None = None,
automerge: bool | None = None,
allow_import: bool | None = None,
) -> Tuple[bool, IncarnationWithDetails]:
"""
Call the FoxOps API to create a new incarnation.
Returns a tuple of (imported, incarnation), where imported is a boolean that is True if the incarnation
already existed and was added to the foxops inventory. This can only be True if the allow_import parameter
is set to True.
"""
) -> IncarnationWithDetails:
data: dict[str, Any] = {
"incarnation_repository": incarnation_repository,
"template_repository": template_repository,
Expand All @@ -155,17 +147,11 @@ async def create_incarnation(
if automerge is not None:
data["automerge"] = automerge

params = {}
if allow_import is not None:
params["allow_import"] = allow_import

resp = await self.retry_function(self.client.post)("/api/incarnations", params=params, json=data)
resp = await self.retry_function(self.client.post)("/api/incarnations", json=data)

match resp.status_code:
case httpx.codes.OK:
return True, IncarnationWithDetails.from_dict(resp.json())
case httpx.codes.CREATED:
return False, IncarnationWithDetails.from_dict(resp.json())
return IncarnationWithDetails.from_dict(resp.json())
case httpx.codes.BAD_REQUEST:
self.log.error(f"received error from FoxOps API: {resp.status_code} {resp.headers} {resp.text}")
raise FoxopsApiError(resp.json()["message"])
Expand Down
5 changes: 1 addition & 4 deletions src/foxops_client/client_sync.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
from typing import Tuple

from foxops_client.client_async import AsyncFoxopsClient
from foxops_client.types import Incarnation, IncarnationWithDetails
Expand Down Expand Up @@ -60,8 +59,7 @@ def create_incarnation(
template_data: dict[str, str],
target_directory: str | None = None,
automerge: bool | None = None,
allow_import: bool | None = None,
) -> Tuple[bool, IncarnationWithDetails]:
) -> IncarnationWithDetails:
return self.loop.run_until_complete(
self.client.create_incarnation(
incarnation_repository,
Expand All @@ -70,6 +68,5 @@ def create_incarnation(
template_data,
target_directory=target_directory,
automerge=automerge,
allow_import=allow_import,
)
)
27 changes: 2 additions & 25 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ def test_create_incarnation(gitlab_api_client, foxops_client: FoxopsClient, temp
incarnation_path = gitlab_project_factory(return_path=True)

# WHEN
imported, incarnation = foxops_client.create_incarnation(
incarnation = foxops_client.create_incarnation(
incarnation_repository=incarnation_path,
template_repository=template_path,
template_repository_version="main",
template_data={"input_variable": "foo"},
)

# THEN
assert imported is False
assert incarnation.id is not None

assert incarnation.incarnation_repository == incarnation_path
Expand All @@ -42,28 +41,6 @@ def test_create_incarnation(gitlab_api_client, foxops_client: FoxopsClient, temp
assert incarnation.template_data == {"input_variable": "foo"}


def test_create_incarnation_import_with_existing_incarnation(incarnation, foxops_client: FoxopsClient):
# GIVEN
foxops_client.delete_incarnation(incarnation.id)

# WHEN
imported, response = foxops_client.create_incarnation(
incarnation_repository=incarnation.incarnation_repository,
template_repository=incarnation.template_repository,
template_repository_version=incarnation.template_repository_version,
template_data=incarnation.template_data,
allow_import=True,
)

# THEN
assert imported is True

assert response.incarnation_repository == incarnation.incarnation_repository
assert response.template_repository == incarnation.template_repository
assert response.template_repository_version == "main"
assert response.template_data == {"input_variable": "foo"}


def test_create_incarnation_with_conflicting_existing_incarnation(incarnation, foxops_client):
# WHEN
with pytest.raises(FoxopsApiError) as e:
Expand Down Expand Up @@ -148,7 +125,7 @@ def create_incarnation(template, gitlab_project_factory, foxops_client):
template_path = template
incarnation_path = gitlab_project_factory(return_path=True)

_, incarnation = foxops_client.create_incarnation(
incarnation = foxops_client.create_incarnation(
incarnation_repository=incarnation_path,
template_repository=template_path,
template_repository_version="main",
Expand Down

0 comments on commit 79c6d4e

Please sign in to comment.