Skip to content

Commit 79c6d4e

Browse files
authored
Remove unsupported allow_import parameter (#18)
remove support for allow_import when creating incarnation (it's no longer supported by foxops)
1 parent b75eb0b commit 79c6d4e

File tree

7 files changed

+91
-538
lines changed

7 files changed

+91
-538
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
**/.pytest_cache/
33
**/.mypy_cache/
44
.coverage
5+
.dmypy.json
56
.idea/
67
dist/

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,17 @@ clean:
33
docker ps -aq --filter "label=creator=pytest-docker-tools" | xargs docker rm -f
44
docker volume ls --filter "label=creator=pytest-docker-tools" --format '{{ .Name }}' | xargs docker volume rm
55
docker network ls --filter "label=creator=pytest-docker-tools" --format '{{ .Name }}' | xargs docker network rm
6+
7+
fmt:
8+
poetry run black src tests
9+
poetry run isort src tests
10+
11+
lint:
12+
poetry run black --check --diff src tests
13+
poetry run isort --check-only src tests
14+
poetry run flake8 src tests
15+
16+
typecheck:
17+
poetry run dmypy run -- src tests
18+
19+
pre-commit: fmt lint typecheck

poetry.lock

Lines changed: 63 additions & 485 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ readme = "README.md"
1010

1111
[tool.poetry.dependencies]
1212
python = ">=3.11,<4.0"
13-
httpx = "^0.23.0"
13+
httpx = "^0.24.1"
1414
tenacity = "^8.0.1"
15-
structlog = ">=21.2,<23.0"
15+
structlog = "^23.1.0"
1616

1717
[tool.poetry.group.dev.dependencies]
1818
# Linting
19-
black = {extras = ["d"], version = "^22.10.0"}
20-
flake8 = "^5.0.4"
21-
flake8-bugbear = "^22.9.23"
19+
black = "^23.7.0"
20+
flake8 = "^6.1.0"
21+
flake8-bugbear = "^23.7.10"
2222
isort = "^5.9.3"
2323

2424
# Testing
2525
pytest = "^7.1.3"
26-
pytest-asyncio = "^0.20.1"
26+
pytest-asyncio = "^0.21.1"
2727
pytest-cov = "^4.0.0"
2828
pytest-docker-tools = "^3.1.3"
2929
pytest-mock = "^3.10.0"

src/foxops_client/client_async.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
2-
from typing import Any, Tuple
2+
from typing import Any
33

44
import httpx
55
from httpx import Response
@@ -135,15 +135,7 @@ async def create_incarnation(
135135
template_data: dict[str, str],
136136
target_directory: str | None = None,
137137
automerge: bool | None = None,
138-
allow_import: bool | None = None,
139-
) -> Tuple[bool, IncarnationWithDetails]:
140-
"""
141-
Call the FoxOps API to create a new incarnation.
142-
143-
Returns a tuple of (imported, incarnation), where imported is a boolean that is True if the incarnation
144-
already existed and was added to the foxops inventory. This can only be True if the allow_import parameter
145-
is set to True.
146-
"""
138+
) -> IncarnationWithDetails:
147139
data: dict[str, Any] = {
148140
"incarnation_repository": incarnation_repository,
149141
"template_repository": template_repository,
@@ -155,17 +147,11 @@ async def create_incarnation(
155147
if automerge is not None:
156148
data["automerge"] = automerge
157149

158-
params = {}
159-
if allow_import is not None:
160-
params["allow_import"] = allow_import
161-
162-
resp = await self.retry_function(self.client.post)("/api/incarnations", params=params, json=data)
150+
resp = await self.retry_function(self.client.post)("/api/incarnations", json=data)
163151

164152
match resp.status_code:
165-
case httpx.codes.OK:
166-
return True, IncarnationWithDetails.from_dict(resp.json())
167153
case httpx.codes.CREATED:
168-
return False, IncarnationWithDetails.from_dict(resp.json())
154+
return IncarnationWithDetails.from_dict(resp.json())
169155
case httpx.codes.BAD_REQUEST:
170156
self.log.error(f"received error from FoxOps API: {resp.status_code} {resp.headers} {resp.text}")
171157
raise FoxopsApiError(resp.json()["message"])

src/foxops_client/client_sync.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import asyncio
2-
from typing import Tuple
32

43
from foxops_client.client_async import AsyncFoxopsClient
54
from foxops_client.types import Incarnation, IncarnationWithDetails
@@ -60,8 +59,7 @@ def create_incarnation(
6059
template_data: dict[str, str],
6160
target_directory: str | None = None,
6261
automerge: bool | None = None,
63-
allow_import: bool | None = None,
64-
) -> Tuple[bool, IncarnationWithDetails]:
62+
) -> IncarnationWithDetails:
6563
return self.loop.run_until_complete(
6664
self.client.create_incarnation(
6765
incarnation_repository,
@@ -70,6 +68,5 @@ def create_incarnation(
7068
template_data,
7169
target_directory=target_directory,
7270
automerge=automerge,
73-
allow_import=allow_import,
7471
)
7572
)

tests/test_client.py

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,14 @@ def test_create_incarnation(gitlab_api_client, foxops_client: FoxopsClient, temp
2525
incarnation_path = gitlab_project_factory(return_path=True)
2626

2727
# WHEN
28-
imported, incarnation = foxops_client.create_incarnation(
28+
incarnation = foxops_client.create_incarnation(
2929
incarnation_repository=incarnation_path,
3030
template_repository=template_path,
3131
template_repository_version="main",
3232
template_data={"input_variable": "foo"},
3333
)
3434

3535
# THEN
36-
assert imported is False
3736
assert incarnation.id is not None
3837

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

4443

45-
def test_create_incarnation_import_with_existing_incarnation(incarnation, foxops_client: FoxopsClient):
46-
# GIVEN
47-
foxops_client.delete_incarnation(incarnation.id)
48-
49-
# WHEN
50-
imported, response = foxops_client.create_incarnation(
51-
incarnation_repository=incarnation.incarnation_repository,
52-
template_repository=incarnation.template_repository,
53-
template_repository_version=incarnation.template_repository_version,
54-
template_data=incarnation.template_data,
55-
allow_import=True,
56-
)
57-
58-
# THEN
59-
assert imported is True
60-
61-
assert response.incarnation_repository == incarnation.incarnation_repository
62-
assert response.template_repository == incarnation.template_repository
63-
assert response.template_repository_version == "main"
64-
assert response.template_data == {"input_variable": "foo"}
65-
66-
6744
def test_create_incarnation_with_conflicting_existing_incarnation(incarnation, foxops_client):
6845
# WHEN
6946
with pytest.raises(FoxopsApiError) as e:
@@ -148,7 +125,7 @@ def create_incarnation(template, gitlab_project_factory, foxops_client):
148125
template_path = template
149126
incarnation_path = gitlab_project_factory(return_path=True)
150127

151-
_, incarnation = foxops_client.create_incarnation(
128+
incarnation = foxops_client.create_incarnation(
152129
incarnation_repository=incarnation_path,
153130
template_repository=template_path,
154131
template_repository_version="main",

0 commit comments

Comments
 (0)