| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
import pytest |
| 19 |
import asyncio |
| 20 |
from concurrent.futures import ThreadPoolExecutor, wait |
| 21 |
|
| 22 |
from confluent_kafka.schema_registry.common.schema_registry_client import SchemaVersion |
| 23 |
from confluent_kafka.schema_registry.error import SchemaRegistryError |
| 24 |
from confluent_kafka.schema_registry.schema_registry_client import Schema, \ |
| 25 |
AsyncSchemaRegistryClient |
| 26 |
from tests.schema_registry.conftest import USERINFO, \ |
| 27 |
SCHEMA_ID, SCHEMA, SUBJECTS, COUNTER, VERSION, VERSIONS |
| 28 |
|
| 29 |
""" |
| 30 |
Basic AsyncSchemaRegistryClient API functionality tests. |
| 31 |
|
| 32 |
These tests cover the following criteria using the mock AsyncSchemaRegistryClient: |
| 33 |
- Proper request/response handling: |
| 34 |
The right data sent to the right place in the right format |
| 35 |
- Error handling: (SR error codes are converted to a |
| 36 |
SchemaRegistryError correctly) |
| 37 |
- Caching: Caching of schema_ids and schemas works as expected. |
| 38 |
|
| 39 |
See ./conftest.py for details on mock AsyncSchemaRegistryClient usage. |
| 40 |
""" |
| 41 |
TEST_URL = 'http://SchemaRegistry:65534' |
| 42 |
TEST_USERNAME = 'sr_user' |
| 43 |
TEST_USER_PASSWORD = 'sr_user_secret' |
| 44 |
|
| 45 |
|
| 46 |
def cmp_schema(schema1: Schema, schema2: Schema) -> bool: |
| 47 |
""" |
| 48 |
Compare to Schemas for equivalence |
| 49 |
|
| 50 |
Args: |
| 51 |
schema1 (Schema): Schema instance to compare |
| 52 |
schema2 (Schema): Schema instance to compare against |
| 53 |
|
| 54 |
Returns: |
| 55 |
bool: True if the schema's match else False |
| 56 |
|
| 57 |
""" |
| 58 |
return all([schema1.schema_str == schema2.schema_str, |
| 59 |
schema1.schema_type == schema2.schema_type]) |
| 60 |
|
| 61 |
|
| 62 |
async def test_basic_auth_unauthorized(mock_schema_registry, load_avsc): |
| 63 |
conf = {'url': TEST_URL, |
| 64 |
'basic.auth.user.info': "user:secret"} |
| 65 |
sr = AsyncSchemaRegistryClient(conf) |
| 66 |
|
| 67 |
with pytest.raises(SchemaRegistryError, match="401 Unauthorized"): |
| 68 |
await sr.get_subjects() |
| 69 |
|
| 70 |
|
| 71 |
async def test_basic_auth_authorized(mock_schema_registry, load_avsc): |
| 72 |
conf = {'url': TEST_URL, |
| 73 |
'basic.auth.user.info': USERINFO} |
| 74 |
sr = AsyncSchemaRegistryClient(conf) |
| 75 |
|
| 76 |
result = await sr.get_subjects() |
| 77 |
|
| 78 |
assert result == SUBJECTS |
| 79 |
|
| 80 |
|
| 81 |
async def test_register_schema(mock_schema_registry, load_avsc): |
| 82 |
conf = {'url': TEST_URL} |
| 83 |
sr = AsyncSchemaRegistryClient(conf) |
| 84 |
schema = Schema(load_avsc('basic_schema.avsc'), schema_type='AVRO') |
| 85 |
|
| 86 |
result = await sr.register_schema('test-key', schema) |
| 87 |
assert result == SCHEMA_ID |
| 88 |
|
| 89 |
|
| 90 |
async def test_register_schema_full_response_recall(mock_schema_registry, load_avsc): |
| 91 |
conf = {'url': TEST_URL} |
| 92 |
sr = AsyncSchemaRegistryClient(conf) |
| 93 |
schema = Schema(load_avsc('basic_schema.avsc'), schema_type='AVRO') |
| 94 |
|
| 95 |
await sr.register_schema('test-key', schema) |
| 96 |
|
| 97 |
result = await sr.register_schema_full_response('test-key', schema) |
| 98 |
assert result.schema_id == SCHEMA_ID |
| 99 |
|
| 100 |
|
| 101 |
async def test_register_schema_incompatible(mock_schema_registry, load_avsc): |
| 102 |
conf = {'url': TEST_URL} |
| 103 |
sr = AsyncSchemaRegistryClient(conf) |
| 104 |
schema = Schema(load_avsc('basic_schema.avsc'), schema_type='AVRO') |
| 105 |
|
| 106 |
with pytest.raises(SchemaRegistryError, match="Incompatible Schema") as e: |
| 107 |
await sr.register_schema('conflict', schema) |
| 108 |
|
| 109 |
assert e.value.http_status_code == 409 |
| 110 |
assert e.value.error_code == -1 |
| 111 |
|
| 112 |
|
| 113 |
async def test_register_schema_invalid(mock_schema_registry, load_avsc): |
| 114 |
conf = {'url': TEST_URL} |
| 115 |
sr = AsyncSchemaRegistryClient(conf) |
| 116 |
schema = Schema(load_avsc('invalid_schema.avsc'), schema_type='AVRO') |
| 117 |
|
| 118 |
with pytest.raises(SchemaRegistryError, match="Invalid Schema") as e: |
| 119 |
await sr.register_schema('invalid', schema) |
| 120 |
|
| 121 |
assert e.value.http_status_code == 422 |
| 122 |
assert e.value.error_code == 42201 |
| 123 |
|
| 124 |
|
| 125 |
async def test_register_schema_cache(mock_schema_registry, load_avsc): |
| 126 |
conf = {'url': TEST_URL} |
| 127 |
sr = AsyncSchemaRegistryClient(conf) |
| 128 |
schema = load_avsc('basic_schema.avsc') |
| 129 |
|
| 130 |
count_before = COUNTER['POST'].get( |
| 131 |
'/subjects/test-cache/versions', 0) |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
await sr.register_schema('test-cache', Schema(schema, 'AVRO')) |
| 137 |
|
| 138 |
def register(): |
| 139 |
return asyncio.run(sr.register_schema('test-cache', schema)) |
| 140 |
|
| 141 |
fs = [] |
| 142 |
with ThreadPoolExecutor(max_workers=10) as executor: |
| 143 |
for _ in range(0, 1000): |
| 144 |
fs.append(executor.submit(register)) |
| 145 |
wait(fs) |
| 146 |
|
| 147 |
count_after = COUNTER['POST'].get( |
| 148 |
'/subjects/test-cache/versions') |
| 149 |
|
| 150 |
assert count_after - count_before == 1 |
| 151 |
|
| 152 |
|
| 153 |
async def test_get_schema(mock_schema_registry, load_avsc): |
| 154 |
conf = {'url': TEST_URL} |
| 155 |
sr = AsyncSchemaRegistryClient(conf) |
| 156 |
|
| 157 |
expected = Schema(load_avsc(SCHEMA), schema_type='AVRO') |
| 158 |
actual = await sr.get_schema(47) |
| 159 |
|
| 160 |
assert cmp_schema(expected, actual) |
| 161 |
|
| 162 |
|
| 163 |
async def test_get_schema_not_found(mock_schema_registry): |
| 164 |
conf = {'url': TEST_URL} |
| 165 |
sr = AsyncSchemaRegistryClient(conf) |
| 166 |
|
| 167 |
with pytest.raises(SchemaRegistryError, match="Schema not found") as e: |
| 168 |
await sr.get_schema(404) |
| 169 |
assert e.value.http_status_code == 404 |
| 170 |
assert e.value.error_code == 40403 |
| 171 |
|
| 172 |
|
| 173 |
async def test_get_schema_cache(mock_schema_registry): |
| 174 |
conf = {'url': TEST_URL} |
| 175 |
sr = AsyncSchemaRegistryClient(conf) |
| 176 |
|
| 177 |
count_before = COUNTER['GET'].get( |
| 178 |
'/schemas/ids/47', 0) |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
await sr.get_schema(47) |
| 184 |
|
| 185 |
def get(): |
| 186 |
return asyncio.run(sr.get_schema(47)) |
| 187 |
|
| 188 |
fs = [] |
| 189 |
with ThreadPoolExecutor(max_workers=10) as executor: |
| 190 |
for _ in range(0, 1000): |
| 191 |
fs.append(executor.submit(get)) |
| 192 |
wait(fs) |
| 193 |
|
| 194 |
count_after = COUNTER['GET'].get( |
| 195 |
'/schemas/ids/47') |
| 196 |
|
| 197 |
assert count_after - count_before == 1 |
| 198 |
|
| 199 |
|
| 200 |
async def test_get_schema_types(mock_schema_registry): |
| 201 |
conf = {'url': TEST_URL} |
| 202 |
sr = AsyncSchemaRegistryClient(conf) |
| 203 |
|
| 204 |
expected = ['AVRO', 'JSON', 'PROTOBUF'] |
| 205 |
actual = await sr.get_schema_types() |
| 206 |
assert expected == actual |
| 207 |
|
| 208 |
|
| 209 |
async def test_get_subjects_by_schema_id(mock_schema_registry): |
| 210 |
conf = {'url': TEST_URL} |
| 211 |
sr = AsyncSchemaRegistryClient(conf) |
| 212 |
|
| 213 |
expected = SUBJECTS |
| 214 |
actual = await sr.get_subjects_by_schema_id(47) |
| 215 |
assert expected == actual |
| 216 |
|
| 217 |
|
| 218 |
async def test_get_schema_versions(mock_schema_registry): |
| 219 |
conf = {'url': TEST_URL} |
| 220 |
sr = AsyncSchemaRegistryClient(conf) |
| 221 |
|
| 222 |
expected = [SchemaVersion(subject='subject1', version=1), SchemaVersion(subject='subject2', version=2)] |
| 223 |
actual = await sr.get_schema_versions(47) |
| 224 |
assert expected == actual |
| 225 |
|
| 226 |
|
| 227 |
async def test_get_registration(mock_schema_registry, load_avsc): |
| 228 |
conf = {'url': TEST_URL} |
| 229 |
sr = AsyncSchemaRegistryClient(conf) |
| 230 |
|
| 231 |
subject = 'get_registration' |
| 232 |
schema = Schema(load_avsc(SCHEMA), schema_type='AVRO') |
| 233 |
|
| 234 |
response = await sr.lookup_schema(subject, schema) |
| 235 |
|
| 236 |
assert response.subject == subject |
| 237 |
assert response.version == VERSION |
| 238 |
assert response.schema_id == SCHEMA_ID |
| 239 |
assert cmp_schema(response.schema, schema) |
| 240 |
|
| 241 |
|
| 242 |
async def test_get_registration_subject_not_found(mock_schema_registry, load_avsc): |
| 243 |
conf = {'url': TEST_URL} |
| 244 |
sr = AsyncSchemaRegistryClient(conf) |
| 245 |
|
| 246 |
subject = 'notfound' |
| 247 |
schema = Schema(load_avsc(SCHEMA), schema_type='AVRO') |
| 248 |
|
| 249 |
with pytest.raises(SchemaRegistryError, match="Subject not found") as e: |
| 250 |
await sr.lookup_schema(subject, schema) |
| 251 |
assert e.value.http_status_code == 404 |
| 252 |
assert e.value.error_code == 40401 |
| 253 |
|
| 254 |
|
| 255 |
async def test_get_registration_schema_not_found(mock_schema_registry, load_avsc): |
| 256 |
conf = {'url': TEST_URL} |
| 257 |
sr = AsyncSchemaRegistryClient(conf) |
| 258 |
|
| 259 |
subject = 'schemanotfound' |
| 260 |
schema = Schema(load_avsc(SCHEMA), schema_type='AVRO') |
| 261 |
|
| 262 |
with pytest.raises(SchemaRegistryError, match="Schema not found") as e: |
| 263 |
await sr.lookup_schema(subject, schema) |
| 264 |
assert e.value.http_status_code == 404 |
| 265 |
assert e.value.error_code == 40403 |
| 266 |
|
| 267 |
|
| 268 |
async def test_get_subjects(mock_schema_registry): |
| 269 |
conf = {'url': TEST_URL} |
| 270 |
sr = AsyncSchemaRegistryClient(conf) |
| 271 |
|
| 272 |
result = await sr.get_subjects() |
| 273 |
|
| 274 |
assert result == SUBJECTS |
| 275 |
|
| 276 |
|
| 277 |
async def test_delete(mock_schema_registry): |
| 278 |
conf = {'url': TEST_URL} |
| 279 |
sr = AsyncSchemaRegistryClient(conf) |
| 280 |
|
| 281 |
result = await sr.delete_subject("delete_subject") |
| 282 |
assert result == VERSIONS |
| 283 |
|
| 284 |
|
| 285 |
async def test_delete_subject_not_found(mock_schema_registry): |
| 286 |
conf = {'url': TEST_URL} |
| 287 |
sr = AsyncSchemaRegistryClient(conf) |
| 288 |
|
| 289 |
with pytest.raises(SchemaRegistryError, match="Subject not found") as e: |
| 290 |
await sr.delete_subject("notfound") |
| 291 |
assert e.value.http_status_code == 404 |
| 292 |
assert e.value.error_code == 40401 |
| 293 |
|
| 294 |
|
| 295 |
async def test_get_version(mock_schema_registry, load_avsc): |
| 296 |
conf = {'url': TEST_URL} |
| 297 |
sr = AsyncSchemaRegistryClient(conf) |
| 298 |
|
| 299 |
subject = "get_version" |
| 300 |
version = 3 |
| 301 |
schema = Schema(load_avsc(SCHEMA), schema_type='AVRO') |
| 302 |
|
| 303 |
result = await sr.get_version(subject, version) |
| 304 |
assert result.subject == subject |
| 305 |
assert result.version == version |
| 306 |
assert cmp_schema(result.schema, schema) |
| 307 |
assert result.schema_id == SCHEMA_ID |
| 308 |
|
| 309 |
|
| 310 |
async def test_get_version_no_version(mock_schema_registry): |
| 311 |
conf = {'url': TEST_URL} |
| 312 |
sr = AsyncSchemaRegistryClient(conf) |
| 313 |
|
| 314 |
subject = "get_version" |
| 315 |
version = 404 |
| 316 |
|
| 317 |
with pytest.raises(SchemaRegistryError, match="Version not found") as e: |
| 318 |
await sr.get_version(subject, version) |
| 319 |
assert e.value.http_status_code == 404 |
| 320 |
assert e.value.error_code == 40402 |
| 321 |
|
| 322 |
|
| 323 |
async def test_get_version_invalid(mock_schema_registry): |
| 324 |
conf = {'url': TEST_URL} |
| 325 |
sr = AsyncSchemaRegistryClient(conf) |
| 326 |
|
| 327 |
subject = "get_version" |
| 328 |
version = 422 |
| 329 |
|
| 330 |
with pytest.raises(SchemaRegistryError, match="Invalid version") as e: |
| 331 |
await sr.get_version(subject, version) |
| 332 |
assert e.value.http_status_code == 422 |
| 333 |
assert e.value.error_code == 42202 |
| 334 |
|
| 335 |
|
| 336 |
async def test_get_version_subject_not_found(mock_schema_registry): |
| 337 |
conf = {'url': TEST_URL} |
| 338 |
sr = AsyncSchemaRegistryClient(conf) |
| 339 |
|
| 340 |
subject = "notfound" |
| 341 |
version = 3 |
| 342 |
|
| 343 |
with pytest.raises(SchemaRegistryError, match="Subject not found") as e: |
| 344 |
await sr.get_version(subject, version) |
| 345 |
assert e.value.http_status_code == 404 |
| 346 |
assert e.value.error_code == 40401 |
| 347 |
|
| 348 |
|
| 349 |
async def test_delete_version(mock_schema_registry): |
| 350 |
conf = {'url': TEST_URL} |
| 351 |
sr = AsyncSchemaRegistryClient(conf) |
| 352 |
|
| 353 |
result = await sr.delete_version("delete_version", 3) |
| 354 |
|
| 355 |
assert result == 3 |
| 356 |
|
| 357 |
|
| 358 |
async def test_delete_version_not_found(mock_schema_registry): |
| 359 |
conf = {'url': TEST_URL} |
| 360 |
sr = AsyncSchemaRegistryClient(conf) |
| 361 |
|
| 362 |
with pytest.raises(SchemaRegistryError, match="Version not found") as e: |
| 363 |
await sr.delete_version("delete_version", 404) |
| 364 |
assert e.value.http_status_code == 404 |
| 365 |
assert e.value.error_code == 40402 |
| 366 |
|
| 367 |
|
| 368 |
async def test_delete_version_subject_not_found(mock_schema_registry): |
| 369 |
conf = {'url': TEST_URL} |
| 370 |
sr = AsyncSchemaRegistryClient(conf) |
| 371 |
|
| 372 |
with pytest.raises(SchemaRegistryError, match="Subject not found") as e: |
| 373 |
await sr.delete_version("notfound", 3) |
| 374 |
assert e.value.http_status_code == 404 |
| 375 |
assert e.value.error_code == 40401 |
| 376 |
|
| 377 |
|
| 378 |
async def test_delete_version_invalid(mock_schema_registry): |
| 379 |
conf = {'url': TEST_URL} |
| 380 |
sr = AsyncSchemaRegistryClient(conf) |
| 381 |
|
| 382 |
with pytest.raises(SchemaRegistryError, match="Invalid version") as e: |
| 383 |
await sr.delete_version("invalid_version", 422) |
| 384 |
assert e.value.http_status_code == 422 |
| 385 |
assert e.value.error_code == 42202 |
| 386 |
|
| 387 |
|
| 388 |
async def test_get_referenced_by(mock_schema_registry): |
| 389 |
conf = {'url': TEST_URL} |
| 390 |
sr = AsyncSchemaRegistryClient(conf) |
| 391 |
|
| 392 |
assert await sr.get_referenced_by("get_version", 3) == [1, 2] |
| 393 |
|
| 394 |
|
| 395 |
async def test_set_compatibility(mock_schema_registry): |
| 396 |
conf = {'url': TEST_URL} |
| 397 |
sr = AsyncSchemaRegistryClient(conf) |
| 398 |
|
| 399 |
result = await sr.set_compatibility(level="FULL") |
| 400 |
assert result == {'compatibility': 'FULL'} |
| 401 |
|
| 402 |
|
| 403 |
async def test_set_compatibility_invalid(mock_schema_registry): |
| 404 |
conf = {'url': TEST_URL} |
| 405 |
sr = AsyncSchemaRegistryClient(conf) |
| 406 |
with pytest.raises(SchemaRegistryError, match="Invalid compatibility level") as e: |
| 407 |
await sr.set_compatibility(level="INVALID") |
| 408 |
e.value.http_status_code = 422 |
| 409 |
e.value.error_code = 42203 |
| 410 |
|
| 411 |
|
| 412 |
async def test_delete_config(mock_schema_registry): |
| 413 |
conf = {'url': TEST_URL} |
| 414 |
sr = AsyncSchemaRegistryClient(conf) |
| 415 |
|
| 416 |
result = await sr.delete_config() |
| 417 |
assert result.compatibility == 'FULL' |
| 418 |
|
| 419 |
|
| 420 |
async def test_delete_config_subject_not_found(mock_schema_registry): |
| 421 |
conf = {'url': TEST_URL} |
| 422 |
sr = AsyncSchemaRegistryClient(conf) |
| 423 |
|
| 424 |
with pytest.raises(SchemaRegistryError, match="Subject not found") as e: |
| 425 |
await sr.delete_config("notfound") |
| 426 |
assert e.value.http_status_code == 404 |
| 427 |
assert e.value.error_code == 40401 |
| 428 |
|
| 429 |
|
| 430 |
async def test_get_compatibility_subject_not_found(mock_schema_registry): |
| 431 |
conf = {'url': TEST_URL} |
| 432 |
sr = AsyncSchemaRegistryClient(conf) |
| 433 |
|
| 434 |
with pytest.raises(SchemaRegistryError, match="Subject not found") as e: |
| 435 |
await sr.get_compatibility("notfound") |
| 436 |
assert e.value.http_status_code == 404 |
| 437 |
assert e.value.error_code == 40401 |
| 438 |
|
| 439 |
|
| 440 |
async def test_get_contexts(mock_schema_registry): |
| 441 |
conf = {'url': TEST_URL} |
| 442 |
sr = AsyncSchemaRegistryClient(conf) |
| 443 |
|
| 444 |
result = await sr.get_contexts() |
| 445 |
assert result == ['context1', 'context2'] |
| 446 |
|
| 447 |
|
| 448 |
async def test_schema_equivilence(load_avsc): |
| 449 |
schema_str1 = load_avsc('basic_schema.avsc') |
| 450 |
schema_str2 = load_avsc('basic_schema.avsc') |
| 451 |
|
| 452 |
schema = Schema(schema_str1, 'AVRO') |
| 453 |
schema2 = Schema(schema_str2, 'AVRO') |
| 454 |
|
| 455 |
assert schema.__eq__(schema2) |
| 456 |
assert schema == schema2 |
| 457 |
assert schema_str1.__eq__(schema_str2) |
| 458 |
assert schema_str1 == schema_str2 |
| 459 |
|
| 460 |
|
| 461 |
@pytest.mark.parametrize( |
| 462 |
'subject_name,version,expected_compatibility', |
| 463 |
[ |
| 464 |
('conflict', 'latest', False), |
| 465 |
('conflict', 1, False), |
| 466 |
('test-key', 'latest', True), |
| 467 |
('test-key', 1, True), |
| 468 |
] |
| 469 |
) |
| 470 |
async def test_test_compatibility_no_error( |
| 471 |
mock_schema_registry, load_avsc, subject_name, version, expected_compatibility |
| 472 |
): |
| 473 |
conf = {'url': TEST_URL} |
| 474 |
sr = AsyncSchemaRegistryClient(conf) |
| 475 |
schema = Schema(load_avsc('basic_schema.avsc'), schema_type='AVRO') |
| 476 |
|
| 477 |
is_compatible = await sr.test_compatibility(subject_name, schema) |
| 478 |
assert is_compatible is expected_compatibility |
| 479 |
|
| 480 |
|
| 481 |
@pytest.mark.parametrize( |
| 482 |
'subject_name,version,match_str,status_code,error_code', |
| 483 |
[ |
| 484 |
('notfound', 'latest', 'Subject not found', 404, 40401), |
| 485 |
('invalid', 'latest', 'Invalid Schema', 422, 42201), |
| 486 |
('invalid', '422', 'Invalid version', 422, 42202), |
| 487 |
('notfound', 404, 'Version not found', 404, 40402), |
| 488 |
] |
| 489 |
) |
| 490 |
async def test_test_compatibility_with_error( |
| 491 |
mock_schema_registry, load_avsc, subject_name, version, match_str, status_code, error_code |
| 492 |
): |
| 493 |
conf = {'url': TEST_URL} |
| 494 |
sr = AsyncSchemaRegistryClient(conf) |
| 495 |
schema = Schema(load_avsc('basic_schema.avsc'), schema_type='AVRO') |
| 496 |
|
| 497 |
with pytest.raises(SchemaRegistryError, match=match_str) as e: |
| 498 |
await sr.test_compatibility(subject_name, schema, version) |
| 499 |
assert e.value.http_status_code == status_code |
| 500 |
assert e.value.error_code == error_code |
| 501 |
|
| 502 |
|
| 503 |
async def test_test_compatibility_all_versions_no_error(mock_schema_registry, load_avsc): |
| 504 |
conf = {'url': TEST_URL} |
| 505 |
sr = AsyncSchemaRegistryClient(conf) |
| 506 |
schema = Schema(load_avsc('basic_schema.avsc'), schema_type='AVRO') |
| 507 |
|
| 508 |
is_compatible = await sr.test_compatibility_all_versions('subject-all-versions', schema) |
| 509 |
assert is_compatible is True |
| 510 |
|
| 511 |
|
| 512 |
async def test_get_global_mode(mock_schema_registry): |
| 513 |
conf = {'url': TEST_URL} |
| 514 |
sr = AsyncSchemaRegistryClient(conf) |
| 515 |
|
| 516 |
mode = await sr.get_global_mode() |
| 517 |
assert mode == 'READWRITE' |
| 518 |
|
| 519 |
|
| 520 |
async def test_set_global_mode(mock_schema_registry): |
| 521 |
conf = {'url': TEST_URL} |
| 522 |
sr = AsyncSchemaRegistryClient(conf) |
| 523 |
|
| 524 |
result = await sr.update_global_mode('READONLY') |
| 525 |
assert result == 'READONLY' |
| 526 |
|
| 527 |
|
| 528 |
async def test_get_mode(mock_schema_registry): |
| 529 |
conf = {'url': TEST_URL} |
| 530 |
sr = AsyncSchemaRegistryClient(conf) |
| 531 |
|
| 532 |
result = await sr.get_mode('test-key') |
| 533 |
assert result == 'READWRITE' |
| 534 |
|
| 535 |
|
| 536 |
@pytest.mark.parametrize( |
| 537 |
'subject_name,match_str,status_code,error_code', |
| 538 |
[ |
| 539 |
('invalid_mode', 'Invalid mode', 422, 42204), |
| 540 |
('operation_not_permitted', 'Operation not permitted', 422, 42205), |
| 541 |
] |
| 542 |
) |
| 543 |
async def test_update_mode_with_error(mock_schema_registry, subject_name, match_str, status_code, error_code): |
| 544 |
conf = {'url': TEST_URL} |
| 545 |
sr = AsyncSchemaRegistryClient(conf) |
| 546 |
|
| 547 |
with pytest.raises(SchemaRegistryError, match=match_str) as e: |
| 548 |
await sr.update_mode(subject_name, 'READONLY') |
| 549 |
assert e.value.http_status_code == status_code |
| 550 |
assert e.value.error_code == error_code |
| 551 |
|
| 552 |
|
| 553 |
async def test_update_mode(mock_schema_registry): |
| 554 |
conf = {'url': TEST_URL} |
| 555 |
sr = AsyncSchemaRegistryClient(conf) |
| 556 |
|
| 557 |
result = await sr.update_mode('test-key', 'READONLY') |
| 558 |
assert result == 'READONLY' |
| 559 |
|
| 560 |
|
| 561 |
async def test_delete_mode(mock_schema_registry): |
| 562 |
conf = {'url': TEST_URL} |
| 563 |
sr = AsyncSchemaRegistryClient(conf) |
| 564 |
|
| 565 |
result = await sr.delete_mode('test-key') |
| 566 |
assert result == 'READWRITE' |