Skip to content

Commit

Permalink
modifying ec2_client fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderegg committed Jun 13, 2024
1 parent 46a356a commit 6e7b1f2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
12 changes: 5 additions & 7 deletions packages/pytest-simcore/src/pytest_simcore/aws_ec2_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@


@pytest.fixture
async def ec2_client(
mocked_ec2_server_settings: EC2Settings,
) -> AsyncIterator[EC2Client]:
async def ec2_client(ec2_settings: EC2Settings) -> AsyncIterator[EC2Client]:
session = aioboto3.Session()
exit_stack = contextlib.AsyncExitStack()
session_client = session.client(
"ec2",
endpoint_url=mocked_ec2_server_settings.EC2_ENDPOINT,
aws_access_key_id=mocked_ec2_server_settings.EC2_ACCESS_KEY_ID,
aws_secret_access_key=mocked_ec2_server_settings.EC2_SECRET_ACCESS_KEY,
region_name=mocked_ec2_server_settings.EC2_REGION_NAME,
endpoint_url=ec2_settings.EC2_ENDPOINT,
aws_access_key_id=ec2_settings.EC2_ACCESS_KEY_ID,
aws_secret_access_key=ec2_settings.EC2_SECRET_ACCESS_KEY,
region_name=ec2_settings.EC2_REGION_NAME,
)
assert isinstance(session_client, ClientCreatorContext)
ec2_client = cast(EC2Client, await exit_stack.enter_async_context(session_client))
Expand Down
17 changes: 16 additions & 1 deletion services/autoscaling/tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,19 @@
)
from pydantic import ByteSize, PositiveInt, parse_obj_as
from pytest_mock.plugin import MockerFixture
from pytest_simcore.helpers.utils_envs import EnvVarsDict, setenvs_from_dict
from pytest_simcore.helpers.utils_envs import (
EnvVarsDict,
delenvs_from_dict,
setenvs_from_dict,
)
from pytest_simcore.helpers.utils_host import get_localhost_ip
from settings_library.rabbit import RabbitSettings
from settings_library.ssm import SSMSettings
from simcore_service_autoscaling.core.application import create_app
from simcore_service_autoscaling.core.settings import (
AUTOSCALING_ENV_PREFIX,
ApplicationSettings,
AutoscalingEC2Settings,
EC2Settings,
)
from simcore_service_autoscaling.models import (
Expand Down Expand Up @@ -145,15 +150,25 @@ def fake_ssm_settings() -> SSMSettings:
return SSMSettings(**SSMSettings.Config.schema_extra["examples"][0])


@pytest.fixture
def ec2_settings() -> EC2Settings:
return AutoscalingEC2Settings.create_from_envs()


@pytest.fixture
def app_environment(
mock_env_devel_environment: EnvVarsDict,
monkeypatch: pytest.MonkeyPatch,
faker: Faker,
aws_allowed_ec2_instance_type_names: list[InstanceTypeType],
external_envfile_dict: EnvVarsDict,
) -> EnvVarsDict:
# SEE https://faker.readthedocs.io/en/master/providers/faker.providers.internet.html?highlight=internet#faker-providers-internet

if external_envfile_dict:
delenvs_from_dict(monkeypatch, mock_env_devel_environment, raising=False)
return setenvs_from_dict(monkeypatch, {**external_envfile_dict})

envs = setenvs_from_dict(
monkeypatch,
{
Expand Down

0 comments on commit 6e7b1f2

Please sign in to comment.