Skip to content

Commit

Permalink
Set permissions and role for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazoyer committed Aug 23, 2024
1 parent 7886bca commit ef4d787
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 54 deletions.
13 changes: 8 additions & 5 deletions backend/tests/helpers/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
from infrahub.core.branch import Branch
from infrahub.core.initialization import (
create_account,
create_administrator_role,
create_administrators_group,
create_default_branch,
create_global_branch,
create_global_permissions,
create_root_node,
initialization,
)
Expand Down Expand Up @@ -104,11 +107,11 @@ async def client(
async def initialize_registry(
self, db: InfrahubDatabase, register_core_schema: SchemaBranch, bus_simulator: BusSimulator, api_token: str
) -> None:
await create_account(
db=db,
name="admin",
password=config.SETTINGS.initial.admin_password,
token_value=api_token,
admin_account = await create_account(
db=db, name="admin", password=config.SETTINGS.initial.admin_password, token_value=api_token
)
global_permissions = await create_global_permissions(db=db)
administrator_role = await create_administrator_role(db=db, global_permissions=global_permissions)
await create_administrators_group(db=db, role=administrator_role, admin_accounts=[admin_account])

await initialization(db=db)
11 changes: 2 additions & 9 deletions backend/tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,11 @@ async def create_token(self, account_name: Optional[str] = None) -> str:
token = str(UUIDT())
account_name = account_name or "admin"
response = await NodeManager.query(
schema=InfrahubKind.ACCOUNT,
db=self.db,
filters={"name__value": account_name},
limit=1,
schema=InfrahubKind.ACCOUNT, db=self.db, filters={"name__value": account_name}, limit=1
)
account = response[0]
account_token = await Node.init(db=self.db, schema=InfrahubKind.ACCOUNTTOKEN)
await account_token.new(
db=self.db,
token=token,
account=account,
)
await account_token.new(db=self.db, token=token, account=account)
await account_token.save(db=self.db)
return token

Expand Down
6 changes: 1 addition & 5 deletions backend/tests/integration/diff/test_diff_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@
class TestDiffUpdateConflict(TestInfrahubApp):
@pytest.fixture(scope="class")
async def initial_dataset(
self,
db: InfrahubDatabase,
default_branch,
client: InfrahubClient,
bus_simulator: BusSimulator,
self, db: InfrahubDatabase, default_branch, client: InfrahubClient, bus_simulator: BusSimulator
) -> None:
await load_schema(db, schema=CAR_SCHEMA)
john = await Node.init(schema=TestKind.PERSON, db=db)
Expand Down
11 changes: 2 additions & 9 deletions backend/tests/integration/git/test_git_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ async def base_dataset(self, db: InfrahubDatabase):
await initialization(db=db)

@pytest.fixture(scope="class")
async def test_client(
self,
base_dataset,
) -> InfrahubTestClient:
async def test_client(self, base_dataset) -> InfrahubTestClient:
await app_initialization(app)
return InfrahubTestClient(app=app)

Expand All @@ -67,11 +64,7 @@ async def client(self, test_client: InfrahubTestClient, integration_helper):
@pytest.fixture(scope="class")
async def query_99(self, db: InfrahubDatabase, test_client):
obj = await Node.init(schema=InfrahubKind.GRAPHQLQUERY, db=db)
await obj.new(
db=db,
name="query99",
query="query query99 { CoreRepository { edges { node { id }}}}",
)
await obj.new(db=db, name="query99", query="query query99 { CoreRepository { edges { node { id }}}}")
await obj.save(db=db)
return obj

Expand Down
8 changes: 1 addition & 7 deletions python_sdk/tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,7 @@ def _request(
if payload:
content = str(ujson.dumps(payload)).encode("UTF-8")
with self as client:
return client.request(
method=method.value,
url=url,
headers=headers,
timeout=timeout,
content=content,
)
return client.request(method=method.value, url=url, headers=headers, timeout=timeout, content=content)

async def async_request(
self, url: str, method: HTTPMethod, headers: dict[str, Any], timeout: int, payload: Optional[dict] = None
Expand Down
23 changes: 4 additions & 19 deletions python_sdk/tests/integration/test_infrahub_client_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ async def test_client(self) -> InfrahubTestClient:

@pytest.fixture
def client(self, test_client: InfrahubTestClient):
config = Config(
username="admin",
password="infrahub",
sync_requester=test_client.sync_request,
)
config = Config(username="admin", password="infrahub", sync_requester=test_client.sync_request)
return InfrahubClientSync(config=config)

@pytest.fixture(scope="class")
Expand All @@ -63,21 +59,13 @@ async def base_dataset(self, db: InfrahubDatabase, test_client: InfrahubTestClie

obj2 = await Node.init(schema="CoreRepository", db=db)
await obj2.new(
db=db,
name="repository1",
description="test repository",
location="[email protected]:mock/test.git",
db=db, name="repository1", description="test repository", location="[email protected]:mock/test.git"
)
await obj2.save(db=db)

obj3 = await Node.init(schema="CoreTransformJinja2", db=db)
await obj3.new(
db=db,
name="rfile1",
description="test rfile",
template_path="mytemplate.j2",
repository=obj2,
query=obj1,
db=db, name="rfile1", description="test rfile", template_path="mytemplate.j2", repository=obj2, query=obj1
)
await obj3.save(db=db)

Expand Down Expand Up @@ -256,10 +244,7 @@ def test_recorder_with_playback(
nodes = client.all(kind="CoreRepository")

playback_config = JSONPlayback(directory=str(tmp_path))
config = Config(
address=client.config.address,
sync_requester=playback_config.sync_request,
)
config = Config(address=client.config.address, sync_requester=playback_config.sync_request)
playback = InfrahubClientSync(config=config)
recorded_nodes = playback.all(kind="CoreRepository")

Expand Down

0 comments on commit ef4d787

Please sign in to comment.