Skip to content

Commit

Permalink
revert test changes unrelated to pydantic v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam-D-Lewis committed Apr 3, 2024
1 parent 32ee7ba commit e1030d8
Show file tree
Hide file tree
Showing 13 changed files with 907 additions and 777 deletions.
81 changes: 55 additions & 26 deletions tests/tests_unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
from unittest.mock import Mock

import pytest
from typer.testing import CliRunner

from _nebari.cli import create_cli
from _nebari.config import write_configuration
from _nebari.constants import (
AWS_DEFAULT_REGION,
Expand All @@ -15,6 +13,8 @@
from _nebari.initialize import render_config
from _nebari.render import render_template
from _nebari.stages.bootstrap import CiEnum
from _nebari.stages.kubernetes_keycloak import AuthenticationEnum
from _nebari.stages.terraform_state import TerraformStateEnum
from nebari import schema
from nebari.plugins import nebari_plugin_manager

Expand Down Expand Up @@ -100,42 +100,81 @@ def _mock_return_value(return_value):

@pytest.fixture(
params=[
# cloud_provider, region
# project, namespace, domain, cloud_provider, region, ci_provider, auth_provider
(
"pytestdo",
"dev",
"do.nebari.dev",
schema.ProviderEnum.do,
DO_DEFAULT_REGION,
CiEnum.github_actions,
AuthenticationEnum.password,
),
(
"pytestaws",
"dev",
"aws.nebari.dev",
schema.ProviderEnum.aws,
AWS_DEFAULT_REGION,
CiEnum.github_actions,
AuthenticationEnum.password,
),
(
"pytestgcp",
"dev",
"gcp.nebari.dev",
schema.ProviderEnum.gcp,
GCP_DEFAULT_REGION,
CiEnum.github_actions,
AuthenticationEnum.password,
),
(
"pytestazure",
"dev",
"azure.nebari.dev",
schema.ProviderEnum.azure,
AZURE_DEFAULT_REGION,
CiEnum.github_actions,
AuthenticationEnum.password,
),
]
)
def nebari_config_options(request):
def nebari_config_options(request) -> schema.Main:
"""This fixtures creates a set of nebari configurations for tests"""
cloud_provider, region = request.param
return {
"project_name": "testproject",
"nebari_domain": "test.nebari.dev",
"cloud_provider": cloud_provider,
"region": region,
"ci_provider": CiEnum.github_actions,
"repository": "github.com/test/test",
"disable_prompt": True,
}
DEFAULT_GH_REPO = "github.com/test/test"
DEFAULT_TERRAFORM_STATE = TerraformStateEnum.remote

(
project,
namespace,
domain,
cloud_provider,
region,
ci_provider,
auth_provider,
) = request.param

return dict(
project_name=project,
namespace=namespace,
nebari_domain=domain,
cloud_provider=cloud_provider,
region=region,
ci_provider=ci_provider,
auth_provider=auth_provider,
repository=DEFAULT_GH_REPO,
repository_auto_provision=False,
auth_auto_provision=False,
terraform_state=DEFAULT_TERRAFORM_STATE,
disable_prompt=True,
)


@pytest.fixture
def nebari_config(nebari_config_options, config_schema):
return config_schema.model_validate(render_config(**nebari_config_options))
def nebari_config(nebari_config_options):
return nebari_plugin_manager.config_schema.parse_obj(
render_config(**nebari_config_options)
)


@pytest.fixture
Expand Down Expand Up @@ -168,13 +207,3 @@ def new_upgrade_cls():
@pytest.fixture
def config_schema():
return nebari_plugin_manager.config_schema


@pytest.fixture
def cli():
return create_cli()


@pytest.fixture(scope="session")
def runner():
return CliRunner()
67 changes: 67 additions & 0 deletions tests/tests_unit/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import subprocess

import pytest

from _nebari.subcommands.init import InitInputs
from nebari.plugins import nebari_plugin_manager

PROJECT_NAME = "clitest"
DOMAIN_NAME = "clitest.dev"


@pytest.mark.parametrize(
"namespace, auth_provider, ci_provider, ssl_cert_email",
(
[None, None, None, None],
["prod", "password", "github-actions", "[email protected]"],
),
)
def test_nebari_init(tmp_path, namespace, auth_provider, ci_provider, ssl_cert_email):
"""Test `nebari init` CLI command."""
command = [
"nebari",
"init",
"local",
f"--project={PROJECT_NAME}",
f"--domain={DOMAIN_NAME}",
"--disable-prompt",
]

default_values = InitInputs()

if namespace:
command.append(f"--namespace={namespace}")
else:
namespace = default_values.namespace
if auth_provider:
command.append(f"--auth-provider={auth_provider}")
else:
auth_provider = default_values.auth_provider
if ci_provider:
command.append(f"--ci-provider={ci_provider}")
else:
ci_provider = default_values.ci_provider
if ssl_cert_email:
command.append(f"--ssl-cert-email={ssl_cert_email}")
else:
ssl_cert_email = default_values.ssl_cert_email

subprocess.run(command, cwd=tmp_path, check=True)

config = nebari_plugin_manager.read_config(tmp_path / "nebari-config.yaml")

assert config.namespace == namespace
assert config.security.authentication.type.lower() == auth_provider
assert config.ci_cd.type == ci_provider
assert config.certificate.acme_email == ssl_cert_email


@pytest.mark.parametrize(
"command",
(
["nebari", "--version"],
["nebari", "info"],
),
)
def test_nebari_commands_no_args(command):
subprocess.run(command, check=True, capture_output=True, text=True).stdout.strip()
12 changes: 10 additions & 2 deletions tests/tests_unit/test_cli_deploy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
def test_dns_option(config_gcp, runner, cli):
from typer.testing import CliRunner

from _nebari.cli import create_cli

runner = CliRunner()


def test_dns_option(config_gcp):
app = create_cli()
result = runner.invoke(
cli,
app,
[
"deploy",
"-c",
Expand Down
Loading

0 comments on commit e1030d8

Please sign in to comment.