Skip to content

Commit 6fc31f3

Browse files
committed
Add unit tase case and update description
1 parent 8f8659d commit 6fc31f3

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

airbyte_cdk/sources/declarative/declarative_component_schema.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ definitions:
348348
type: string
349349
stream_count:
350350
title: Stream Count
351-
description: Numbers of the streams to try reading from when running a check operation.
351+
description: The number of streams to attempt reading from during a check operation. If `stream_count` exceeds the total number of available streams, the minimum of the two values will be used.
352352
type: integer
353353
default: 0
354354
CheckDynamicStream:

unit_tests/sources/declarative/checks/test_check_stream.py

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -363,14 +363,15 @@ def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapp
363363

364364

365365
@pytest.mark.parametrize(
366-
"check_component, expected_result, expectation, response_code, expected_messages",
366+
"check_component, expected_result, expectation, response_code, expected_messages, request_count",
367367
[
368368
pytest.param(
369369
{"check": {"type": "CheckStream", "stream_names": ["static_stream"]}},
370370
True,
371371
False,
372372
200,
373373
[{"id": 1, "name": "static_1"}, {"id": 2, "name": "static_2"}],
374+
0,
374375
id="test_check_only_static_streams",
375376
),
376377
pytest.param(
@@ -391,6 +392,7 @@ def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapp
391392
False,
392393
200,
393394
[],
395+
0,
394396
id="test_check_static_streams_and_http_dynamic_stream",
395397
),
396398
pytest.param(
@@ -411,6 +413,7 @@ def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapp
411413
False,
412414
200,
413415
[],
416+
0,
414417
id="test_check_static_streams_and_config_dynamic_stream",
415418
),
416419
pytest.param(
@@ -434,6 +437,7 @@ def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapp
434437
False,
435438
200,
436439
[],
440+
0,
437441
id="test_check_http_dynamic_stream_and_config_dynamic_stream",
438442
),
439443
pytest.param(
@@ -458,14 +462,36 @@ def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapp
458462
False,
459463
200,
460464
[],
465+
0,
461466
id="test_check_static_streams_and_http_dynamic_stream_and_config_dynamic_stream",
462467
),
468+
pytest.param(
469+
{
470+
"check": {
471+
"type": "CheckStream",
472+
"dynamic_streams_check_configs": [
473+
{
474+
"type": "DynamicStreamCheckConfig",
475+
"dynamic_stream_name": "http_dynamic_stream",
476+
"stream_count": 1000,
477+
},
478+
],
479+
}
480+
},
481+
True,
482+
False,
483+
200,
484+
[],
485+
1,
486+
id="test_stream_count_gt_generated_streams",
487+
),
463488
pytest.param(
464489
{"check": {"type": "CheckStream", "stream_names": ["non_existent_stream"]}},
465490
False,
466491
True,
467492
200,
468493
[],
494+
0,
469495
id="test_non_existent_static_stream",
470496
),
471497
pytest.param(
@@ -485,6 +511,7 @@ def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapp
485511
False,
486512
200,
487513
[],
514+
0,
488515
id="test_non_existent_dynamic_stream",
489516
),
490517
pytest.param(
@@ -493,6 +520,7 @@ def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapp
493520
False,
494521
404,
495522
["Not found. The requested resource was not found on the server."],
523+
0,
496524
id="test_stream_unavailable_unhandled_error",
497525
),
498526
pytest.param(
@@ -501,6 +529,7 @@ def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapp
501529
False,
502530
403,
503531
["Forbidden. You don't have permission to access this resource."],
532+
0,
504533
id="test_stream_unavailable_handled_error",
505534
),
506535
pytest.param(
@@ -509,6 +538,7 @@ def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapp
509538
False,
510539
401,
511540
["Unauthorized. Please ensure you are authenticated correctly."],
541+
0,
512542
id="test_stream_unauthorized_error",
513543
),
514544
pytest.param(
@@ -532,6 +562,7 @@ def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapp
532562
False,
533563
404,
534564
["Not found. The requested resource was not found on the server."],
565+
0,
535566
id="test_dynamic_stream_unavailable_unhandled_error",
536567
),
537568
pytest.param(
@@ -555,6 +586,7 @@ def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapp
555586
False,
556587
403,
557588
["Forbidden. You don't have permission to access this resource."],
589+
0,
558590
id="test_dynamic_stream_unavailable_handled_error",
559591
),
560592
pytest.param(
@@ -578,12 +610,13 @@ def parse_response(self, response: requests.Response, **kwargs) -> Iterable[Mapp
578610
False,
579611
401,
580612
["Unauthorized. Please ensure you are authenticated correctly."],
613+
0,
581614
id="test_dynamic_stream_unauthorized_error",
582615
),
583616
],
584617
)
585618
def test_check_stream1(
586-
check_component, expected_result, expectation, response_code, expected_messages
619+
check_component, expected_result, expectation, response_code, expected_messages, request_count
587620
):
588621
manifest = {**deepcopy(_MANIFEST_WITHOUT_CHECK_COMPONENT), **check_component}
589622

@@ -600,13 +633,17 @@ def test_check_stream1(
600633
)
601634
http_mocker.get(items_request, items_response)
602635

603-
item_request = HttpRequest(url="https://api.test.com/items/1")
636+
item_request_1 = HttpRequest(url="https://api.test.com/items/1")
604637
item_response = HttpResponse(body=json.dumps(expected_messages), status_code=response_code)
605-
http_mocker.get(item_request, item_response)
638+
http_mocker.get(item_request_1, item_response)
606639

607-
item_request = HttpRequest(url="https://api.test.com/items/3")
640+
item_request_2 = HttpRequest(url="https://api.test.com/items/2")
608641
item_response = HttpResponse(body=json.dumps(expected_messages), status_code=response_code)
609-
http_mocker.get(item_request, item_response)
642+
http_mocker.get(item_request_2, item_response)
643+
644+
item_request_3 = HttpRequest(url="https://api.test.com/items/3")
645+
item_response = HttpResponse(body=json.dumps(expected_messages), status_code=response_code)
646+
http_mocker.get(item_request_3, item_response)
610647

611648
source = ConcurrentDeclarativeSource(
612649
source_config=manifest,
@@ -619,7 +656,7 @@ def test_check_stream1(
619656
source.check_connection(logger, _CONFIG)
620657
else:
621658
stream_is_available, reason = source.check_connection(logger, _CONFIG)
622-
659+
http_mocker.assert_number_of_calls(item_request_2, request_count)
623660
assert stream_is_available == expected_result
624661

625662

0 commit comments

Comments
 (0)