Exemple #1
0
    def test_login_to_tenant_writes_tenant_and_reloads_it_when_token_is_reloaded(
            self, patch_post):
        tenant_id = str(uuid.uuid4())
        post = patch_post({
            "data": {
                "tenant": [{
                    "id": tenant_id
                }],
                "switchTenant": {
                    "accessToken": "ACCESS_TOKEN",
                    "expiresAt": "2100-01-01",
                    "refreshToken": "REFRESH_TOKEN",
                },
            }
        })

        client = Client(api_token="abc")
        assert client._active_tenant_id is None
        client.login_to_tenant(tenant_id=tenant_id)
        client.save_api_token()
        assert client._active_tenant_id == tenant_id

        # new client loads the active tenant and token
        assert Client()._active_tenant_id == tenant_id
        assert Client()._api_token == "abc"
Exemple #2
0
    def test_login_to_tenant_writes_tenant_and_reloads_it_when_token_is_reloaded(
        self, patch_post, cloud_api
    ):
        tenant_id = str(uuid.uuid4())
        post = patch_post(
            {
                "data": {
                    "tenant": [{"id": tenant_id}],
                    "switch_tenant": {
                        "access_token": "ACCESS_TOKEN",
                        "expires_at": "2100-01-01",
                        "refresh_token": "REFRESH_TOKEN",
                    },
                }
            }
        )

        client = Client(api_token="abc")
        assert client._active_tenant_id is None
        client.login_to_tenant(tenant_id=tenant_id)
        client.save_api_token()
        assert client.active_tenant_id == tenant_id

        # new client loads the active tenant and token
        client_load_active_tenant = Client()
        # The tenant is initialized by calling the property active_tenant_id
        assert client_load_active_tenant.active_tenant_id == tenant_id
        assert client_load_active_tenant._api_token == "abc"
Exemple #3
0
    def test_load_local_api_token_is_called_when_the_client_is_initialized_without_token(
            self):
        with tempfile.TemporaryDirectory() as tmp:
            with set_temporary_config({"home_dir": tmp}):
                client = Client(api_token="a")
                client.save_api_token()

                client = Client()
                assert client._api_token == "a"
Exemple #4
0
    def test_save_local_settings(self):
        with tempfile.TemporaryDirectory() as tmp:
            with set_temporary_config({"home_dir": tmp, "cloud.graphql": "xyz"}):
                path = Path(tmp) / "client" / "xyz" / "settings.toml"

                client = Client(api_token="a")
                client.save_api_token()
                with path.open("r") as f:
                    assert toml.load(f)["api_token"] == "a"

                client = Client(api_token="b")
                client.save_api_token()
                with path.open("r") as f:
                    assert toml.load(f)["api_token"] == "b"