Skip to content

Commit

Permalink
fix imports on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zmraul committed Mar 14, 2024
1 parent c60d0d0 commit 784e41e
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 37 deletions.
22 changes: 0 additions & 22 deletions tests/helpers.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/conftest.py → tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2022 Canonical Ltd.
# See LICENSE file for licensing details.

from tests.helpers import NUM_UNITS
from .helpers import NUM_UNITS


def pytest_addoption(parser):
Expand Down
16 changes: 15 additions & 1 deletion tests/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,26 @@
"""Helpers for integration tests."""
import logging
import subprocess
from pathlib import Path
from urllib.request import urlopen

import yaml
from pytest_operator.plugin import OpsTest
from tenacity import before_log, retry, stop_after_attempt, wait_fixed

from tests.helpers import APP_NAME
METADATA = yaml.safe_load(Path("./metadata.yaml").read_text())
APP_NAME = METADATA["name"]
STORAGE_PATH = METADATA["storage"]["database"]["location"]
TLS_RESOURCES = {
"cert-file": "tests/tls/redis.crt",
"key-file": "tests/tls/redis.key",
"ca-cert-file": "tests/tls/ca.crt",
}
APPLICATION_DATA = {
"leader-host": "leader-host",
"redis-password": "password",
}
NUM_UNITS = 3

logger = logging.getLogger(__name__)

Expand Down
8 changes: 5 additions & 3 deletions tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Copyright 2022 Canonical Ltd.
# See LICENSE file for licensing details.


import logging

import pytest
Expand All @@ -11,8 +10,11 @@
from pytest_operator.plugin import OpsTest
from redis import Redis

from tests.helpers import APP_NAME, METADATA, NUM_UNITS, TLS_RESOURCES
from tests.integration.helpers import (
from .helpers import (
APP_NAME,
METADATA,
NUM_UNITS,
TLS_RESOURCES,
attach_resource,
change_config,
get_address,
Expand Down
4 changes: 1 addition & 3 deletions tests/integration/test_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
# Copyright 2022 Canonical Ltd.
# See LICENSE file for licensing details.


import logging

import pytest
from pytest_operator.plugin import OpsTest
from redis import Redis
from redis.exceptions import AuthenticationError

from tests.helpers import APP_NAME, METADATA
from tests.integration.helpers import get_address, get_password
from .helpers import APP_NAME, METADATA, get_address, get_password

logger = logging.getLogger(__name__)

Expand Down
5 changes: 3 additions & 2 deletions tests/integration/test_redis_relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
from lightkube.resources.core_v1 import Pod
from pytest_operator.plugin import OpsTest

from tests.helpers import APP_NAME, METADATA
from tests.integration.helpers import (
from .helpers import (
APP_NAME,
METADATA,
check_application_status,
get_address,
get_unit_map,
Expand Down
7 changes: 4 additions & 3 deletions tests/integration/test_scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
# Copyright 2022 Canonical Ltd.
# See LICENSE file for licensing details.


import logging
import time

import pytest
from pytest_operator.plugin import OpsTest
from redis import Redis

from tests.helpers import APP_NAME, METADATA, NUM_UNITS
from tests.integration.helpers import (
from .helpers import (
APP_NAME,
METADATA,
NUM_UNITS,
get_address,
get_password,
get_sentinel_password,
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
from redis.exceptions import RedisError

from charm import RedisK8sCharm
from tests.helpers import APPLICATION_DATA

APPLICATION_DATA = {
"leader-host": "leader-host",
"redis-password": "password",
}


class TestCharm(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ env_list = lint, unit

[vars]
src_path = {tox_root}/src/
tests_path = {tox_root}/tests/
tests_path = {tox_root}/tests
lib_path = {tox_root}/lib/charms/redis_k8s
all_path = {[vars]src_path} {[vars]tests_path}

Expand Down

0 comments on commit 784e41e

Please sign in to comment.