Skip to content

Commit 5488726

Browse files
committed
Added an option to parse endpoint from endpoints.json
1 parent 46e2f94 commit 5488726

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

tests/conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
import json
23
import os
34
import random
45
import time
@@ -345,6 +346,13 @@ def _get_client(
345346
else:
346347
redis_url = from_url
347348

349+
endpoints_config = os.getenv("REDIS_ENDPOINTS_CONFIG_PATH", None)
350+
if endpoints_config is not None:
351+
with open(endpoints_config, 'r') as f:
352+
data = json.load(f)
353+
db = next(iter(data.values()))
354+
redis_url = db['endpoints'][0]
355+
348356
redis_tls_url = request.config.getoption("--redis-ssl-url")
349357

350358
if "protocol" not in redis_url and kwargs.get("protocol") is None:

tests/test_asyncio/conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import os
23
import random
34
from contextlib import asynccontextmanager as _asynccontextmanager
@@ -64,6 +65,13 @@ async def client_factory(
6465
if "protocol" not in url and kwargs.get("protocol") is None:
6566
kwargs["protocol"] = request.config.getoption("--protocol")
6667

68+
endpoints_config = os.getenv("REDIS_ENDPOINTS_CONFIG_PATH", None)
69+
if endpoints_config is not None:
70+
with open(endpoints_config, 'r') as f:
71+
data = json.load(f)
72+
db = next(iter(data.values()))
73+
url = db['endpoints'][0]
74+
6775
cluster_mode = REDIS_INFO["cluster_enabled"]
6876
if not cluster_mode:
6977
single = kwargs.pop("single_connection_client", False) or single_connection

tests/test_asyncio/test_credentials.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,31 @@ async def test_async_pipeline_with_credential_provider(self, r_credential: Redis
573573

574574
assert await pipe.execute() == [True, b'value']
575575

576+
@pytest.mark.parametrize(
577+
"r_credential",
578+
[
579+
{
580+
"cred_provider_class": EntraIdCredentialsProvider,
581+
},
582+
],
583+
indirect=True,
584+
)
585+
@pytest.mark.asyncio
586+
@pytest.mark.onlynoncluster
587+
@pytest.mark.cp_integration
588+
async def test_async_auth_pubsub_with_credential_provider(self, r_credential: Redis):
589+
p = r_credential.pubsub()
590+
await p.subscribe("entraid")
591+
592+
await r_credential.publish('entraid', 'test')
593+
await r_credential.publish('entraid', 'test')
594+
595+
msg1 = await p.get_message()
596+
msg2 = await p.get_message()
597+
598+
assert msg1['type'] == 'subscribe'
599+
assert msg2['type'] == 'message'
600+
576601

577602

578603
@pytest.mark.asyncio

tests/test_credentials.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,27 @@ def test_auth_pipeline_with_credential_provider(self, r: redis.Redis):
546546

547547
assert pipe.execute() == [True, b'value']
548548

549+
@pytest.mark.parametrize(
550+
"r",
551+
[
552+
{
553+
"cred_provider_class": EntraIdCredentialsProvider,
554+
},
555+
],
556+
indirect=True,
557+
)
558+
@pytest.mark.onlynoncluster
559+
@pytest.mark.cp_integration
560+
def test_auth_pubsub_with_credential_provider(self, r: redis.Redis):
561+
p = r.pubsub()
562+
p.subscribe("entraid")
563+
564+
r.publish('entraid', 'test')
565+
r.publish('entraid', 'test')
566+
567+
assert p.get_message()['type'] == 'subscribe'
568+
assert p.get_message()['type'] == 'message'
569+
549570

550571
@pytest.mark.onlycluster
551572
@pytest.mark.cp_integration

0 commit comments

Comments
 (0)