Skip to content

Commit

Permalink
Update integration tests: additional users and configurations infrast…
Browse files Browse the repository at this point in the history
…ructure
  • Loading branch information
cartermak committed Oct 2, 2023
1 parent f84f758 commit d107f66
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 21 deletions.
47 changes: 31 additions & 16 deletions tests/integration_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,65 @@
import sys

from aerie_cli.aerie_client import AerieClient
from aerie_cli.aerie_host import AerieHost
from aerie_cli.aerie_host import AerieHost, AerieHostConfiguration
from aerie_cli.commands.configurations import (
delete_all_persistent_files,
upload_configurations,
)
from aerie_cli.app import deactivate_session, activate_session
from aerie_cli.utils.sessions import get_active_session_client
from aerie_cli.app import deactivate_session
from aerie_cli.persistent import PersistentConfigurationManager, PersistentSessionManager
from aerie_cli.utils.sessions import (
get_active_session_client,
start_session_from_configuration,
)

# in case src_path is not from aeri-cli src and from site-packages
src_path = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/../src")
sys.path.insert(0, src_path)

# Configuration values mirror those in the test file localhost_config.json
GRAPHQL_URL = "http://localhost:8080/v1/graphql"
GATEWAY_URL = "http://localhost:9000"
USERNAME = "a"
PASSWORD = "a"
ANONYMOUS_LOCALHOST_CONF = AerieHostConfiguration("localhost", GRAPHQL_URL, GATEWAY_URL)

# Additional usernames to register with Aerie
ADDITIONAL_USERS = ["user1", "user2", "user3"]

# This should only ever be set to the admin secret for a local instance of aerie
HASURA_ADMIN_SECRET = os.environ.get("HASURA_GRAPHQL_ADMIN_SECRET")

aerie_host = AerieHost(GRAPHQL_URL, GATEWAY_URL)
aerie_host.authenticate(USERNAME, PASSWORD)
aerie_host.change_role("aerie_admin")
client = AerieClient(aerie_host)

# Test constants
DOWNLOADED_FILE_NAME = "downloaded_file.test"

TEST_DIR = os.path.dirname(os.path.abspath(__file__))

FILES_PATH = os.path.join(TEST_DIR, "files")

# Configuration Variables
CONFIGURATIONS_PATH = os.path.join(FILES_PATH, "configuration")
CONFIGURATION_PATH = os.path.join(CONFIGURATIONS_PATH, "localhost_config.json")

# Login to add additional users to the `users` table
for username in ADDITIONAL_USERS:
start_session_from_configuration(
ANONYMOUS_LOCALHOST_CONF,
username
)

# Resets the configurations and adds localhost
deactivate_session()
delete_all_persistent_files()
upload_configurations(CONFIGURATION_PATH)
activate_session("localhost")
persisent_client = None

# Login as the main username, set role, and store session as persistent
localhost_conf = PersistentConfigurationManager.get_configuration_by_name("localhost")
aerie_host = start_session_from_configuration(localhost_conf, USERNAME, PASSWORD)
aerie_host.change_role("aerie_admin")
PersistentSessionManager.set_active_session(aerie_host)

client = None
try:
persisent_client = get_active_session_client()
client = get_active_session_client()
except:
raise RuntimeError("Configuration is not active!")
assert (
persisent_client.aerie_host.gateway_url == GATEWAY_URL
client.aerie_host.gateway_url == GATEWAY_URL
), "Aerie instances are mismatched. Ensure test URLs are the same."
2 changes: 1 addition & 1 deletion tests/integration_tests/test_constraints.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typer.testing import CliRunner

from .conftest import client, HASURA_ADMIN_SECRET
from .conftest import client
from aerie_cli.__main__ import app

from aerie_cli.schemas.client import ActivityPlanCreate
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/test_expansion.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from aerie_cli.__main__ import app
from aerie_cli.schemas.client import ActivityPlanCreate

from .conftest import client, HASURA_ADMIN_SECRET
from .conftest import client

runner = CliRunner(mix_stderr = False)

Expand Down
1 change: 0 additions & 1 deletion tests/integration_tests/test_metadata.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typer.testing import CliRunner

from .conftest import client, HASURA_ADMIN_SECRET
from aerie_cli.__main__ import app

import os
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from aerie_cli.__main__ import app

from .conftest import client, HASURA_ADMIN_SECRET
from .conftest import client

runner = CliRunner(mix_stderr = False)

Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/test_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from aerie_cli.__main__ import app
from aerie_cli.schemas.client import ActivityPlanCreate

from .conftest import client, HASURA_ADMIN_SECRET
from .conftest import client

runner = CliRunner(mix_stderr = False)

Expand Down

0 comments on commit d107f66

Please sign in to comment.