Beispiel #1
0
def test_register_failed_policy():
    """Protocol:
    - We call the provider and get a 409 provider error
    - Now we POST register provider and get "Registering"
    - This POST failed
    """

    provider_url = (
        "https://management.azure.com/"
        "subscriptions/12345678-9abc-def0-0000-000000000000/"
        "resourceGroups/clitest.rg000001/"
        "providers/Microsoft.Sql/servers/ygserver123?api-version=2014-04-01")

    provider_error = (
        '{"error":{"code":"MissingSubscriptionRegistration", '
        '"message":"The subscription registration is in \'Unregistered\' state. '
        'The subscription must be registered to use namespace \'Microsoft.Sql\'. '
        'See https://aka.ms/rps-not-found for how to register subscriptions."}}'
    )

    provider_success = '{"success": true}'

    httpretty.register_uri(httpretty.PUT,
                           provider_url,
                           responses=[
                               httpretty.Response(body=provider_error,
                                                  status=409),
                               httpretty.Response(body=provider_success),
                           ],
                           content_type="application/json")

    register_post_url = (
        "https://management.azure.com/"
        "subscriptions/12345678-9abc-def0-0000-000000000000/"
        "providers/Microsoft.Sql/register?api-version=2016-02-01")

    httpretty.register_uri(httpretty.POST,
                           register_post_url,
                           status=409,
                           content_type="application/json")

    request = HttpRequest("PUT", provider_url)
    policies = [
        ARMAutoResourceProviderRegistrationPolicy(),
    ]
    with Pipeline(RequestsTransport(), policies=policies) as pipeline:
        response = pipeline.run(request)

    assert response.http_response.status_code == 409
Beispiel #2
0
    def __init__(self, cli_ctx, credential, **kwargs):
        from azure.cli.core.auth.util import resource_to_scopes
        from azure.mgmt.core.policies import ARMAutoResourceProviderRegistrationPolicy
        base_url = cli_ctx.cloud.endpoints.resource_manager
        credential_scopes = resource_to_scopes(cli_ctx.cloud.endpoints.active_directory_resource_id)
        config = self._Configuration(
            credential=credential,
            credential_scopes=credential_scopes,
            **kwargs
        )

        per_call_policies = [ARMAutoResourceProviderRegistrationPolicy()]

        super().__init__(
            base_url=base_url,
            config=config,
            per_call_policies=per_call_policies
        )