Skip to content

Commit 8cca20c

Browse files
emasabedenhill
authored andcommitted
different fixtures to use for regression tests on past versions
1 parent bed874b commit 8cca20c

File tree

2 files changed

+56
-16
lines changed

2 files changed

+56
-16
lines changed

tests/integration/conftest.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@
2626
work_dir = os.path.dirname(os.path.realpath(__file__))
2727

2828

29-
def create_trivup_cluster():
30-
return TrivupFixture({'with_sr': True,
31-
'debug': True,
32-
'cp_version': 'latest',
33-
'broker_conf': ['transaction.state.log.replication.factor=1',
34-
'transaction.state.log.min.isr=1']})
29+
def create_trivup_cluster(conf={}):
30+
trivup_fixture_conf = {'with_sr': True,
31+
'debug': True,
32+
'cp_version': 'latest',
33+
'broker_conf': ['transaction.state.log.replication.factor=1',
34+
'transaction.state.log.min.isr=1']}
35+
trivup_fixture_conf.update(conf)
36+
return TrivupFixture(trivup_fixture_conf)
3537

3638

3739
def create_byo_cluster(conf):
@@ -41,8 +43,11 @@ def create_byo_cluster(conf):
4143
return ByoFixture(conf)
4244

4345

44-
@pytest.fixture(scope="package")
45-
def kafka_cluster():
46+
def kafka_cluster_fixture(
47+
brokers_env="BROKERS",
48+
sr_url_env="SR_URL",
49+
trivup_cluster_conf={}
50+
):
4651
"""
4752
If BROKERS environment variable is set to a CSV list of bootstrap servers
4853
an existing cluster is used.
@@ -52,22 +57,28 @@ def kafka_cluster():
5257
If BROKERS is not set a TrivUp cluster is created and used.
5358
"""
5459

55-
bootstraps = os.environ.get("BROKERS", "")
60+
bootstraps = os.environ.get(brokers_env, "")
5661
if bootstraps != "":
5762
conf = {"bootstrap.servers": bootstraps}
58-
sr_url = os.environ.get("SR_URL", "")
63+
sr_url = os.environ.get(sr_url_env, "")
5964
if sr_url != "":
6065
conf["schema.registry.url"] = sr_url
6166
print("Using ByoFixture with config from env variables: ", conf)
6267
cluster = create_byo_cluster(conf)
6368
else:
64-
cluster = create_trivup_cluster()
69+
cluster = create_trivup_cluster(trivup_cluster_conf)
6570
try:
6671
yield cluster
6772
finally:
6873
cluster.stop()
6974

7075

76+
@pytest.fixture(scope="package")
77+
def kafka_cluster():
78+
for fixture in kafka_cluster_fixture():
79+
yield fixture
80+
81+
7182
@pytest.fixture()
7283
def load_file():
7384
def get_handle(name):

tests/integration/schema_registry/test_api_client.py

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@
2121

2222
from confluent_kafka.schema_registry import Schema
2323
from confluent_kafka.schema_registry.error import SchemaRegistryError
24+
from tests.integration.conftest import kafka_cluster_fixture
25+
26+
27+
@pytest.fixture(scope="module")
28+
def kafka_cluster_cp_7_0_1():
29+
"""
30+
Returns a Trivup cluster with CP version 7.0.1.
31+
SR version 7.0.1 is the last returning 500 instead of 422
32+
for the invalid schema passed to test_api_get_register_schema_invalid
33+
"""
34+
for fixture in kafka_cluster_fixture(
35+
brokers_env="BROKERS_7_0_1",
36+
sr_url_env="SR_URL_7_0_1",
37+
trivup_cluster_conf={'cp_version': '7.0.1'}
38+
):
39+
yield fixture
2440

2541

2642
def _subject_name(prefix):
@@ -157,15 +173,28 @@ def test_api_get_registration_subject_not_found(kafka_cluster, load_file):
157173
assert e.value.error_code == 40401
158174

159175

160-
def test_api_get_register_schema_invalid(kafka_cluster, load_file):
176+
@pytest.mark.parametrize("kafka_cluster_name, http_status_code, error_code", [
177+
["kafka_cluster_cp_7_0_1", 500, 500],
178+
["kafka_cluster", 422, 42201],
179+
])
180+
def test_api_get_register_schema_invalid(
181+
kafka_cluster_name,
182+
http_status_code,
183+
error_code,
184+
load_file,
185+
request):
161186
"""
162187
Attempts to obtain registration information with an invalid schema
188+
with different CP versions.
163189
164190
Args:
165-
kafka_cluster (KafkaClusterFixture): Kafka Cluster fixture
191+
kafka_cluster_name (str): name of the Kafka Cluster fixture to use
192+
http_status_code (int): HTTP status return code expected in this version
193+
error_code (int): error code expected in this version
166194
load_file (callable(str)): Schema fixture constructor
167-
195+
request (FixtureRequest): PyTest object giving access to the test context
168196
"""
197+
kafka_cluster = request.getfixturevalue(kafka_cluster_name)
169198
sr = kafka_cluster.schema_registry()
170199
subject = _subject_name("registration_invalid_schema")
171200
schema = Schema(load_file('basic_schema.avsc'), schema_type='AVRO')
@@ -177,8 +206,8 @@ def test_api_get_register_schema_invalid(kafka_cluster, load_file):
177206
with pytest.raises(SchemaRegistryError, match="Invalid schema") as e:
178207
sr.lookup_schema(subject, schema2)
179208

180-
assert e.value.http_status_code == 422
181-
assert e.value.error_code == 42201
209+
assert e.value.http_status_code == http_status_code
210+
assert e.value.error_code == error_code
182211

183212

184213
def test_api_get_subjects(kafka_cluster, load_file):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy