|
| 1 | +"""Describe overall framework configuration.""" |
| 2 | +import pytest |
| 3 | +from boto3 import Session |
| 4 | +from botocore.client import BaseClient |
| 5 | + |
| 6 | +from tests.settings import DEFAULT_AWS_REGION |
| 7 | + |
| 8 | + |
| 9 | +def pytest_addoption(parser) -> None: |
| 10 | + """Get cli-arguments. |
| 11 | +
|
| 12 | + :param parser: pytest parser |
| 13 | + :return: |
| 14 | + """ |
| 15 | + parser.addoption("--nginx-api", action="store", default="", help="The NGINX Plus API url.") |
| 16 | + parser.addoption("--aws-region", action="store", default=DEFAULT_AWS_REGION, help="The AWS region name.") |
| 17 | + |
| 18 | + |
| 19 | +class CLIArguments: |
| 20 | + """ |
| 21 | + Encapsulate CLI arguments. |
| 22 | +
|
| 23 | + Attributes: |
| 24 | + nginx_api (str): NGINX Plus API url |
| 25 | + aws_region (str): AWS region name |
| 26 | + """ |
| 27 | + def __init__(self, nginx_api: str, aws_region: str): |
| 28 | + self.nginx_api = nginx_api |
| 29 | + self.aws_region = aws_region |
| 30 | + |
| 31 | + |
| 32 | +@pytest.fixture(scope="session", autouse=True) |
| 33 | +def cli_arguments(request) -> CLIArguments: |
| 34 | + """ |
| 35 | + Verify the CLI arguments. |
| 36 | +
|
| 37 | + :param request: pytest fixture |
| 38 | + :return: CLIArguments |
| 39 | + """ |
| 40 | + nginx_api = request.config.getoption("--nginx-api") |
| 41 | + assert nginx_api != "", "Empty NGINX Plus API url is not allowed" |
| 42 | + print(f"\nTests will use NGINX Plus API url: {nginx_api}") |
| 43 | + |
| 44 | + aws_region = request.config.getoption("--aws-region") |
| 45 | + print(f"\nTests will use AWS region: {aws_region}") |
| 46 | + |
| 47 | + return CLIArguments(nginx_api, aws_region) |
| 48 | + |
| 49 | + |
| 50 | +@pytest.fixture(scope="session") |
| 51 | +def autoscaling_client(cli_arguments) -> BaseClient: |
| 52 | + """ |
| 53 | + Set up kubernets-client to operate in cluster. |
| 54 | +
|
| 55 | + boto3 looks for AWS credentials file and uses a `default` profile from it. |
| 56 | +
|
| 57 | + :param cli_arguments: a set of command-line arguments |
| 58 | + :return: |
| 59 | + """ |
| 60 | + session = Session(profile_name='default', |
| 61 | + region_name=cli_arguments.aws_region) |
| 62 | + return session.client('autoscaling') |
0 commit comments