Skip to content

Commit 2a312e7

Browse files
committed
CAIP-80 update test
1 parent a2be0ed commit 2a312e7

1 file changed

Lines changed: 39 additions & 22 deletions

File tree

tests/bdk/integration/test_post_message.py

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,49 @@
11
import os
2-
import yaml
3-
from pytest import fixture, mark
42
import re
53
from datetime import datetime, timedelta
4+
from pathlib import Path
5+
6+
import pytest
7+
import yaml
68

79
from symphony.bdk.core.config.loader import BdkConfigLoader
810
from symphony.bdk.core.symphony_bdk import SymphonyBdk
911

12+
STREAM_ID = os.getenv("STREAM_ID")
13+
BOT_USERNAME = os.getenv("BOT_USERNAME")
14+
SYMPHONY_HOST = os.getenv("SYMPHONY_HOST")
15+
TEST_RSA_KEY = os.getenv("TEST_RSA_KEY")
1016

17+
# Skip all tests in this file if the required environment variables are not set.
18+
pytestmark = pytest.mark.skipif(
19+
not all([STREAM_ID, BOT_USERNAME, SYMPHONY_HOST, TEST_RSA_KEY]),
20+
reason="Required environment variables for integration tests are not set "
21+
"(STREAM_ID, BOT_USERNAME, SYMPHONY_HOST, TEST_RSA_KEY)"
22+
)
1123

1224
NUMBER_OF_MESSAGES = 10
13-
STREAM_ID = os.getenv("STREAM_ID", "put-stream-id-to-env-vars")
14-
CONFIG_PATH = "/home/runner/.symphony/config.yaml"
15-
16-
@fixture
17-
def bot_config():
18-
bot_user = os.getenv("BOT_USERNAME", "put-useranme-to-env-vars")
19-
sym_host = os.getenv("SYMPHONY_HOST", "put-symphony-host-to-env-vars")
20-
key_path = "/home/runner/.symphony/key.pem"
21-
bot_config = {"host": sym_host,
22-
"bot": {"username": bot_user, "privateKey": {"path": key_path}}}
23-
with open(CONFIG_PATH, "w") as config_file:
24-
yaml.dump(bot_config, config_file)
25-
26-
with open(key_path, "w") as key_file:
27-
key_file.write(os.getenv("TEST_RSA_KEY", "PUT A KEY HERE OR INTO ENV VAR"))
28-
yield
29-
os.remove(key_path), os.remove(CONFIG_PATH)
25+
@pytest.fixture
26+
def bot_config_path(tmp_path: Path):
27+
key_path = tmp_path / "key.pem"
28+
config_path = tmp_path / "config.yaml"
29+
30+
31+
bot_config_dict = {
32+
"host": SYMPHONY_HOST,
33+
"bot": {
34+
"username": BOT_USERNAME,
35+
"privateKey": {"path": str(key_path)}
36+
}
37+
}
38+
39+
# Write the key and config files
40+
key_path.write_text(TEST_RSA_KEY)
41+
with config_path.open("w") as config_file:
42+
yaml.dump(bot_config_dict, config_file)
43+
44+
yield config_path
45+
46+
os.remove(key_path), os.remove(config_path)
3047

3148
async def send_messages(messages, stream_id, since):
3249
for i in range(NUMBER_OF_MESSAGES):
@@ -41,12 +58,12 @@ async def get_test_messages(bdk, since):
4158
return cleaned_messages_text
4259

4360

44-
@mark.asyncio
45-
async def test_bot_read_write_messages(bot_config):
61+
@pytest.mark.asyncio
62+
async def test_bot_read_write_messages(bot_config_path):
4663
# Given: test execution start time
4764
since = int((datetime.now() - timedelta(seconds=2)).timestamp()) * 1000
4865
# Given: BDK is initialized with config
49-
config = BdkConfigLoader.load_from_symphony_dir(CONFIG_PATH)
66+
config = BdkConfigLoader.load_from_symphony_dir(str(bot_config_path))
5067
async with SymphonyBdk(config) as bdk:
5168
# When: messages are sent via bot
5269
await send_messages(bdk.messages(), STREAM_ID, since)

0 commit comments

Comments
 (0)