|
6 | 6 | from infrahub_sdk import InfrahubClient, InfrahubClientSync |
7 | 7 | from infrahub_sdk.exceptions import NodeNotFoundError |
8 | 8 | from infrahub_sdk.node import InfrahubNode, InfrahubNodeSync |
| 9 | +from tests.unit.sdk.conftest import BothClients |
9 | 10 |
|
10 | 11 | pytestmark = pytest.mark.httpx_mock(can_send_already_matched_responses=True) |
11 | 12 |
|
@@ -761,12 +762,37 @@ async def test_query_echo(httpx_mock: HTTPXMock, echo_clients, client_type): |
761 | 762 |
|
762 | 763 |
|
763 | 764 | @pytest.mark.parametrize("client_type", client_types) |
764 | | -async def test_clone(clients, client_type): |
| 765 | +async def test_clone(clients: BothClients, client_type: str) -> None: |
| 766 | + """Validate that the configuration of a cloned client is a replica of the original client""" |
765 | 767 | if client_type == "standard": |
766 | 768 | clone = clients.standard.clone() |
767 | 769 | assert clone.config == clients.standard.config |
768 | 770 | assert isinstance(clone, InfrahubClient) |
| 771 | + assert clients.standard.default_branch == clone.default_branch |
769 | 772 | else: |
770 | 773 | clone = clients.sync.clone() |
771 | 774 | assert clone.config == clients.sync.config |
772 | 775 | assert isinstance(clone, InfrahubClientSync) |
| 776 | + assert clients.sync.default_branch == clone.default_branch |
| 777 | + |
| 778 | + |
| 779 | +@pytest.mark.parametrize("client_type", client_types) |
| 780 | +async def test_clone_define_branch(clients: BothClients, client_type: str) -> None: |
| 781 | + """Validate that the clone branch parameter sets the correct branch of the cloned client""" |
| 782 | + clone_branch = "my_other_branch" |
| 783 | + if client_type == "standard": |
| 784 | + original_branch = clients.standard.default_branch |
| 785 | + clone = clients.standard.clone(branch=clone_branch) |
| 786 | + assert clients.standard.store._default_branch == original_branch |
| 787 | + assert isinstance(clone, InfrahubClient) |
| 788 | + assert clients.standard.default_branch != clone.default_branch |
| 789 | + else: |
| 790 | + original_branch = clients.standard.default_branch |
| 791 | + clone = clients.sync.clone(branch="my_other_branch") |
| 792 | + assert clients.sync.store._default_branch == original_branch |
| 793 | + assert isinstance(clone, InfrahubClientSync) |
| 794 | + assert clients.sync.default_branch != clone.default_branch |
| 795 | + |
| 796 | + assert clone.default_branch == clone_branch |
| 797 | + assert original_branch != clone_branch |
| 798 | + assert clone.store._default_branch == clone_branch |
0 commit comments