Skip to content

Commit f13a959

Browse files
committed
Use a default name constant
1 parent d70dd6a commit f13a959

File tree

4 files changed

+28
-21
lines changed

4 files changed

+28
-21
lines changed

server/tests/client_checks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
INACTIVE_PROPERTY = {"name": "pvStatus", "owner": "admin", "value": "Inactive", "channels": []}
1212
MAX_WAIT_SECONDS = 180
1313
TIME_PERIOD_INCREMENT = 2
14+
DEFAULT_CHANNEL_NAME = "IOC1-1:ai:archive"
1415

1516

1617
def channel_match(channel0, channel1, properties_to_match: list[str]):

server/tests/test_bash_ioc.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
from docker import DockerClient
88
from docker.models.containers import Container
99

10-
from .client_checks import INACTIVE_PROPERTY, check_channel_property, create_client_and_wait, wait_for_sync
10+
from .client_checks import (
11+
DEFAULT_CHANNEL_NAME,
12+
INACTIVE_PROPERTY,
13+
check_channel_property,
14+
create_client_and_wait,
15+
wait_for_sync,
16+
)
1117
from .docker import ComposeFixtureFactory
1218

1319
LOG: logging.Logger = logging.getLogger(__name__)
@@ -54,29 +60,28 @@ def test_remove_property(self, setup_compose: DockerCompose) -> None: # noqa: F
5460

5561
# Check ioc1-1 has ai:archive with info tag "archive"
5662
LOG.debug('Checking ioc1-1 has ai:archive with info tag "archive"')
57-
archive_channel_name = "IOC1-1:ai:archive"
58-
archive_channel = cf_client.find(name=archive_channel_name)
63+
channel = cf_client.find(name=DEFAULT_CHANNEL_NAME)
5964

60-
def get_len_archive_properties(archive_channel):
61-
return len([prop for prop in archive_channel[0]["properties"] if prop["name"] == "archive"])
65+
def get_len_archive_properties(channel):
66+
return len([prop for prop in channel[0]["properties"] if prop["name"] == "archive"])
6267

63-
assert get_len_archive_properties(archive_channel) == 1
68+
assert get_len_archive_properties(channel) == 1
6469

6570
docker_ioc.stop()
6671
LOG.info("Waiting for channels to go inactive")
6772
assert wait_for_sync(
6873
cf_client,
69-
lambda cf_client: check_channel_property(cf_client, name=archive_channel_name, prop=INACTIVE_PROPERTY),
74+
lambda cf_client: check_channel_property(cf_client, name=DEFAULT_CHANNEL_NAME, prop=INACTIVE_PROPERTY),
7075
)
7176
docker_ioc.start()
7277

7378
docker_exec_new_command(docker_ioc, "DB_FILE=archiver_bug_test.db ./demo /ioc/st_bugtest.cmd")
7479
# Detach by not waiting for the thread to finish
7580

7681
LOG.debug("ioc1-1 restart")
77-
assert wait_for_sync(cf_client, lambda cf_client: check_channel_property(cf_client, name=archive_channel_name))
82+
assert wait_for_sync(cf_client, lambda cf_client: check_channel_property(cf_client, name=DEFAULT_CHANNEL_NAME))
7883
LOG.debug("ioc1-1 has restarted and synced")
7984

80-
archive_channel = cf_client.find(name=archive_channel_name)
81-
LOG.debug("archive channel: %s", archive_channel)
82-
assert get_len_archive_properties(archive_channel) == 0
85+
channel = cf_client.find(name=DEFAULT_CHANNEL_NAME)
86+
LOG.debug("archive channel: %s", channel)
87+
assert get_len_archive_properties(channel) == 0

server/tests/test_multiple_recceiver.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from channelfinder import ChannelFinderClient
66
from testcontainers.compose import DockerCompose
77

8-
from .client_checks import create_client_and_wait
8+
from .client_checks import DEFAULT_CHANNEL_NAME, create_client_and_wait
99
from .docker import ComposeFixtureFactory
1010

1111
LOG: logging.Logger = logging.getLogger(__name__)
@@ -27,16 +27,16 @@ class TestMultipleRecceiver:
2727
def test_number_of_channels_and_channel_name(self, cf_client: ChannelFinderClient) -> None:
2828
channels = cf_client.find(name="*")
2929
assert len(channels) == EXPECTED_DEFAULT_CHANNEL_COUNT
30-
assert channels[0]["name"] == "IOC1-1:ai:archive"
30+
assert channels[0]["name"] == DEFAULT_CHANNEL_NAME
3131

3232
# Smoke Test Default Properties
3333
def test_number_of_aliases_and_alais_property(self, cf_client: ChannelFinderClient) -> None:
3434
channels = cf_client.find(property=[("alias", "*")])
3535
assert len(channels) == 8
36-
assert channels[0]["name"] == "IOC1-1:ai:archive:alias"
36+
assert channels[0]["name"] == DEFAULT_CHANNEL_NAME + ":alias"
3737
assert {
3838
"name": "alias",
39-
"value": "IOC1-1:ai:archive",
39+
"value": DEFAULT_CHANNEL_NAME,
4040
"owner": "admin",
4141
"channels": [],
4242
} in channels[0]["properties"]

server/tests/test_single_ioc.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from testcontainers.compose import DockerCompose
88

99
from .client_checks import (
10+
DEFAULT_CHANNEL_NAME,
1011
INACTIVE_PROPERTY,
1112
channels_match,
1213
check_channel_property,
@@ -39,7 +40,7 @@ class TestRestartIOC:
3940
def test_channels_same_after_restart(self, setup_compose: DockerCompose, cf_client: ChannelFinderClient) -> None: # noqa: F811
4041
channels_begin = cf_client.find(name="*")
4142
restart_container(setup_compose, "ioc1-1")
42-
assert wait_for_sync(cf_client, lambda cf_client: check_channel_property(cf_client, "IOC1-1:ai:archive"))
43+
assert wait_for_sync(cf_client, lambda cf_client: check_channel_property(cf_client, DEFAULT_CHANNEL_NAME))
4344
channels_end = cf_client.find(name="*")
4445
assert len(channels_begin) == len(channels_end)
4546
channels_match(channels_begin, channels_end, PROPERTIES_TO_MATCH)
@@ -52,12 +53,12 @@ def test_manual_channels_same_after_restart(
5253
test_property = {"name": "test_property", "owner": "testowner"}
5354
cf_client.set(properties=[test_property])
5455
test_property_value = test_property | {"value": "test_value"}
55-
channels = cf_client.find(name="IOC1-1:ai:archive")
56+
channels = cf_client.find(name=DEFAULT_CHANNEL_NAME)
5657
channels[0]["properties"] = [test_property_value]
5758
cf_client.set(property=test_property)
5859
channels_begin = cf_client.find(name="*")
5960
restart_container(setup_compose, "ioc1-1")
60-
assert wait_for_sync(cf_client, lambda cf_client: check_channel_property(cf_client, "IOC1-1:ai:archive"))
61+
assert wait_for_sync(cf_client, lambda cf_client: check_channel_property(cf_client, DEFAULT_CHANNEL_NAME))
6162
channels_end = cf_client.find(name="*")
6263
assert len(channels_begin) == len(channels_end)
6364
channels_match(channels_begin, channels_end, PROPERTIES_TO_MATCH + ["test_property"])
@@ -85,7 +86,7 @@ def test_status_property_works_after_cf_restart(
8586
# Assert
8687
shutdown_container(setup_compose, "ioc1-1")
8788
assert wait_for_sync(
88-
cf_client, lambda cf_client: check_channel_property(cf_client, "IOC1-1:ai:archive", INACTIVE_PROPERTY)
89+
cf_client, lambda cf_client: check_channel_property(cf_client, DEFAULT_CHANNEL_NAME, INACTIVE_PROPERTY)
8990
)
9091
channels_inactive = cf_client.find(property=[("iocName", "IOC1-1")])
9192
assert all(INACTIVE_PROPERTY in ch["properties"] for ch in channels_inactive)
@@ -109,7 +110,7 @@ def test_status_property_works_between_cf_down(
109110

110111
# Assert
111112
assert wait_for_sync(
112-
cf_client, lambda cf_client: check_channel_property(cf_client, "IOC1-1:ai:archive", INACTIVE_PROPERTY)
113+
cf_client, lambda cf_client: check_channel_property(cf_client, DEFAULT_CHANNEL_NAME, INACTIVE_PROPERTY)
113114
)
114115
channels_inactive = cf_client.find(property=[("iocName", "IOC1-1")])
115116
assert all(INACTIVE_PROPERTY in ch["properties"] for ch in channels_inactive)
@@ -123,6 +124,6 @@ def test_move_ioc_host(
123124
) -> None:
124125
channels_begin = cf_client.find(name="*")
125126
clone_container(setup_compose, "ioc1-1-new", host_name="ioc1-1")
126-
wait_for_sync(cf_client, lambda cf_client: check_channel_property(cf_client, "IOC1-1:ai:archive"))
127+
wait_for_sync(cf_client, lambda cf_client: check_channel_property(cf_client, DEFAULT_CHANNEL_NAME))
127128
channels_end = cf_client.find(name="*")
128129
assert len(channels_begin) == len(channels_end)

0 commit comments

Comments
 (0)