コード例 #1
0
    def test_client_clears_active_tenant_if_login_fails_on_initialization(
        self, patch_post, cloud_api
    ):
        post = patch_post(
            {
                "errors": [
                    {
                        "message": "",
                        "locations": [],
                        "path": ["tenant"],
                        "extensions": {"code": "UNAUTHENTICATED"},
                    }
                ]
            }
        )

        # create a client just so we can use its settings methods to store settings
        client = Client()
        settings = client._load_local_settings()
        settings.update(api_token="API_TOKEN", active_tenant_id=str(uuid.uuid4()))
        client._save_local_settings(settings)

        # this initialization will fail with the patched error
        client = Client()
        settings = client._load_local_settings()
        assert "active_tenant_id" not in settings
コード例 #2
0
    def test_client_infers_correct_tenant_if_a_token_is_not_user_scoped(
            self, patch_posts, cloud_api):
        patch_posts([
            # First, raise an UNAUTHENTICATED error
            {
                "errors": [{
                    "message": "",
                    "locations": [],
                    "path": ["tenant"],
                    "extensions": {
                        "code": "UNAUTHENTICATED"
                    },
                }]
            },
            # Then, return a tenant id
            {
                "data": {
                    "tenant": [{
                        "id": "tenant-id"
                    }]
                }
            },
        ])

        # create a client just so we can use its settings methods to store settings
        disk_tenant = str(uuid.uuid4())
        client = Client()
        client._save_local_settings(
            dict(api_token="API_TOKEN", active_tenant_id=disk_tenant))

        # this initialization will fail to login to the active tenant then load the
        # correct tenant from the API
        client = Client(api_token="API_TOKEN")
        client._init_tenant()
        assert client._tenant_id == "tenant-id"

        # Disk is unchanged
        settings = client._load_local_settings()
        assert settings["active_tenant_id"] == disk_tenant