Skip to content

Commit 4133df1

Browse files
arnaudsjsinmantaci
authored andcommitted
Fix bug where isExpertMode field of graphql endpoint always returns False. (PR #9391)
# Description * Fix bug where `isExpertMode` field of graphql endpoint always returns False. * Move `test_query_is_expert_mode` test case to lsm extension repository (inmanta/inmanta-lsm#2156). # Self Check: - [ ] ~~Attached issue to pull request~~ - [x] Changelog entry - [x] Type annotations are present - [x] Code is clear and sufficiently documented - [x] No (preventable) type errors (check using make mypy or make mypy-diff) - [x] Sufficient test cases (reproduces the bug/tests the requested feature) - [x] Correct, in line with design - [ ] ~~End user documentation is included or an issue is created for end-user documentation~~ - [ ] ~~If this PR fixes a race condition in the test suite, also push the fix to the relevant stable branche(s) (see [test-fixes](https://internal.inmanta.com/development/core/tasks/build-master.html#test-fixes) for more info)~~
1 parent 1839856 commit 4133df1

File tree

3 files changed

+50
-111
lines changed

3 files changed

+50
-111
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
description: "Fix bug where isExpertMode field of graphql endpoint always returns False."
3+
change-type: patch
4+
destination-branches: [master]

src/inmanta/graphql/schema.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import dataclasses
1616
import typing
1717
import uuid
18+
from typing import cast
1819

1920
import inmanta.data.sqlalchemy as models
2021
import strawberry
@@ -156,10 +157,9 @@ def get_expert_mode(root: "Environment") -> bool:
156157
Checks settings of environment to figure out if expert mode is enabled or not
157158
"""
158159
assert hasattr(root, "settings") # Make mypy happy
159-
is_expert_mode = root.settings.get("enable_lsm_expert_mode", False)
160-
if isinstance(is_expert_mode, str) and is_expert_mode.lower() == "false":
160+
if "enable_lsm_expert_mode" not in root.settings["settings"]:
161161
return False
162-
return bool(is_expert_mode)
162+
return cast(bool, root.settings["settings"]["enable_lsm_expert_mode"]["value"])
163163

164164

165165
def get_is_compiling(root: "Environment", info: strawberry.Info) -> bool:

tests/test_graphql.py

Lines changed: 43 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,33 @@
2626

2727

2828
@pytest.fixture
29-
async def setup_database(project_default):
29+
async def setup_database(project_default, server, client):
30+
id_env_1 = uuid.UUID("11111111-1234-5678-1234-000000000001")
31+
result = await client.environment_create(
32+
project_id=project_default,
33+
name="test-env-b",
34+
environment_id=id_env_1,
35+
)
36+
assert result.code == 200
37+
38+
id_env_2 = uuid.UUID("11111111-1234-5678-1234-000000000002")
39+
result = await client.environment_create(
40+
project_id=project_default,
41+
name="test-env-c",
42+
environment_id=id_env_2,
43+
)
44+
assert result.code == 200
45+
46+
id_env_3 = uuid.UUID("11111111-1234-5678-1234-000000000003")
47+
result = await client.environment_create(
48+
project_id=project_default,
49+
name="test-env-a",
50+
environment_id=id_env_3,
51+
)
52+
assert result.code == 200
53+
result = await client.halt_environment(id_env_3)
54+
assert result.code == 200
55+
3056
def add_notifications(env_id: uuid.UUID) -> list[models.Notification]:
3157
notifications = []
3258
for i in range(8):
@@ -46,42 +72,9 @@ def add_notifications(env_id: uuid.UUID) -> list[models.Notification]:
4672
)
4773
return notifications
4874

49-
# Initialize DB
75+
# Add notifications
5076
async with data.get_session() as session:
51-
environment_1 = models.Environment(
52-
id=uuid.UUID("11111111-1234-5678-1234-000000000001"),
53-
name="test-env-b",
54-
project=project_default,
55-
halted=False,
56-
settings={
57-
"enable_lsm_expert_mode": False,
58-
},
59-
)
60-
environment_2 = models.Environment(
61-
id=uuid.UUID("11111111-1234-5678-1234-000000000002"),
62-
name="test-env-c",
63-
project=project_default,
64-
halted=False,
65-
settings={
66-
"enable_lsm_expert_mode": True,
67-
},
68-
)
69-
environment_3 = models.Environment(
70-
id=uuid.UUID("11111111-1234-5678-1234-000000000003"),
71-
name="test-env-a",
72-
project=project_default,
73-
halted=True,
74-
)
75-
76-
session.add_all(
77-
[
78-
environment_1,
79-
environment_2,
80-
environment_3,
81-
*add_notifications(environment_1.id),
82-
*add_notifications(environment_2.id),
83-
]
84-
)
77+
session.add_all([*add_notifications(id_env_1), *add_notifications(id_env_2)])
8578
await session.commit()
8679
await session.flush()
8780

@@ -95,62 +88,6 @@ async def test_graphql_schema(server, client):
9588
assert result.result["data"]["__schema"]
9689

9790

98-
async def test_query_is_expert_mode(server, client, setup_database, project_default):
99-
"""
100-
Tests the custom attribute isExpertMode
101-
"""
102-
query = """
103-
{
104-
environments {
105-
edges {
106-
node {
107-
id
108-
halted
109-
isExpertMode
110-
project
111-
}
112-
}
113-
}
114-
}
115-
"""
116-
result = await client.graphql(query=query)
117-
assert result.code == 200
118-
assert result.result["data"] == {
119-
"data": {
120-
"environments": {
121-
"edges": [
122-
{
123-
"node": {
124-
"halted": False,
125-
"id": "11111111-1234-5678-1234-000000000001",
126-
"isExpertMode": False,
127-
"project": project_default,
128-
}
129-
},
130-
{
131-
"node": {
132-
"halted": False,
133-
"id": "11111111-1234-5678-1234-000000000002",
134-
"isExpertMode": True,
135-
"project": project_default,
136-
}
137-
},
138-
{
139-
"node": {
140-
"halted": True,
141-
"id": "11111111-1234-5678-1234-000000000003",
142-
"isExpertMode": False,
143-
"project": project_default,
144-
}
145-
},
146-
]
147-
}
148-
},
149-
"errors": None,
150-
"extensions": {},
151-
}
152-
153-
15491
async def test_query_environments_with_filtering(server, client, setup_database):
15592
"""
15693
Display basic filtering capabilities
@@ -178,7 +115,7 @@ async def test_query_environments_with_filtering(server, client, setup_database)
178115
"node": {
179116
"halted": False,
180117
"id": "11111111-1234-5678-1234-000000000002",
181-
"isExpertMode": True,
118+
"isExpertMode": False,
182119
}
183120
}
184121
]
@@ -223,21 +160,19 @@ async def test_query_environments_with_paging(server, client, setup_database):
223160
"""
224161
Display basic paging capabilities
225162
"""
226-
async with data.get_session() as session:
227-
project = models.Project(id=uuid.UUID("00000000-1234-5678-1234-000000000002"), name="test-proj-2")
228-
instances = [project]
229-
for i in range(10):
230-
instances.append(
231-
models.Environment(
232-
id=uuid.UUID(f"21111111-1234-5678-1234-00000000000{i}"),
233-
name=f"test-env-{i}",
234-
project=project.id,
235-
halted=False,
236-
)
237-
)
238-
session.add_all(instances)
239-
await session.commit()
240-
await session.flush()
163+
# Create second project
164+
id_project_2 = uuid.UUID("00000000-1234-5678-1234-000000000002")
165+
result = await client.project_create(name="test-proj-2", project_id=id_project_2)
166+
assert result.code == 200
167+
# Create environments in project
168+
for i in range(10):
169+
result = await client.environment_create(
170+
project_id=id_project_2,
171+
name=f"test-env-{i}",
172+
environment_id=uuid.UUID(f"21111111-1234-5678-1234-00000000000{i}"),
173+
)
174+
assert result.code == 200
175+
241176
query = """
242177
{
243178
environments(%s){

0 commit comments

Comments
 (0)