Пример #1
0
def form_recognizer_account():
    test_case = AzureTestCase("__init__")
    rg_preparer = ResourceGroupPreparer(random_name_enabled=True,
                                        name_prefix='pycog',
                                        location=REGION)
    form_recognizer_preparer = CognitiveServicesAccountPreparer(
        random_name_enabled=True,
        kind="formrecognizer",
        name_prefix='pycog',
        location=REGION)

    try:
        rg_name, rg_kwargs = rg_preparer._prepare_create_resource(test_case)
        FormRecognizerTest._RESOURCE_GROUP = rg_kwargs['resource_group']
        try:
            form_recognizer_name, form_recognizer_kwargs = form_recognizer_preparer._prepare_create_resource(
                test_case, **rg_kwargs)
            if test_case.is_live:
                time.sleep(60)  # current ask until race condition bug fixed
            FormRecognizerTest._FORM_RECOGNIZER_ACCOUNT = form_recognizer_kwargs[
                'cognitiveservices_account']
            FormRecognizerTest._FORM_RECOGNIZER_KEY = form_recognizer_kwargs[
                'cognitiveservices_account_key']
            FormRecognizerTest._FORM_RECOGNIZER_NAME = form_recognizer_name
            yield
        finally:
            form_recognizer_preparer.remove_resource(
                form_recognizer_name,
                resource_group=rg_kwargs['resource_group'])
            FormRecognizerTest._FORM_RECOGNIZER_ACCOUNT = None
            FormRecognizerTest._FORM_RECOGNIZER_KEY = None

    finally:
        rg_preparer.remove_resource(rg_name)
        FormRecognizerTest._RESOURCE_GROUP = None
Пример #2
0
def form_recognizer_account():
    test_case = AzureTestCase("__init__")
    rg_preparer = ResourceGroupPreparer(random_name_enabled=True, name_prefix='pycog')
    form_recognizer_preparer = CognitiveServicesAccountPreparer(
        random_name_enabled=True,
        kind="formrecognizer",
        name_prefix='pycog',
        location="westus"
    )

    try:
        rg_name, rg_kwargs = rg_preparer._prepare_create_resource(test_case)
        FormRecognizerTest._RESOURCE_GROUP = rg_kwargs['resource_group']
        try:
            form_recognizer_name, form_recognizer_kwargs = form_recognizer_preparer._prepare_create_resource(
                test_case, **rg_kwargs)
            FormRecognizerTest._FORM_RECOGNIZER_ACCOUNT = form_recognizer_kwargs['cognitiveservices_account']
            FormRecognizerTest._FORM_RECOGNIZER_KEY = form_recognizer_kwargs['cognitiveservices_account_key']
            yield
        finally:
            form_recognizer_preparer.remove_resource(
                form_recognizer_name,
                resource_group=rg_kwargs['resource_group']
            )
            FormRecognizerTest._FORM_RECOGNIZER_ACCOUNT = None
            FormRecognizerTest._FORM_RECOGNIZER_KEY = None

    finally:
        rg_preparer.remove_resource(rg_name)
        FormRecognizerTest._RESOURCE_GROUP = None
def text_analytics_account():
    test_case = AzureTestCase("__init__")
    rg_preparer = ResourceGroupPreparer(random_name_enabled=True,
                                        name_prefix='pycog')
    text_analytics_preparer = CognitiveServicesAccountPreparer(
        random_name_enabled=True, name_prefix='pycog', location=REGION)

    try:
        rg_name, rg_kwargs = rg_preparer._prepare_create_resource(test_case)
        TextAnalyticsTest._RESOURCE_GROUP = rg_kwargs['resource_group']
        try:
            text_analytics_name, text_analytics_kwargs = text_analytics_preparer._prepare_create_resource(
                test_case, **rg_kwargs)
            TextAnalyticsTest._TEXT_ANALYTICS_ACCOUNT = text_analytics_kwargs[
                'cognitiveservices_account']
            TextAnalyticsTest._TEXT_ANALYTICS_KEY = text_analytics_kwargs[
                'cognitiveservices_account_key']
            yield
        finally:
            text_analytics_preparer.remove_resource(
                text_analytics_name,
                resource_group=rg_kwargs['resource_group'])
            TextAnalyticsTest._TEXT_ANALYTICS_ACCOUNT = None
            TextAnalyticsTest._TEXT_ANALYTICS_KEY = None
    finally:
        rg_preparer.remove_resource(rg_name)
        TextAnalyticsTest._RESOURCE_GROUP = None
Пример #4
0
def form_recognizer_account():
    # temp allow an existing resource to be used instead of creating an FR resource on the fly
    if ENDPOINT != "None":
        FormRecognizerTest._FORM_RECOGNIZER_ACCOUNT = ENDPOINT
        if REGION == "centraluseuap":
            FormRecognizerTest._FORM_RECOGNIZER_KEY = os.getenv(
                "AZURE_FORM_RECOGNIZER_PYTHON_CANARY_API_KEY")
        else:
            FormRecognizerTest._FORM_RECOGNIZER_KEY = os.getenv(
                "AZURE_FORM_RECOGNIZER_PYTHON_API_KEY")
        FormRecognizerTest._FORM_RECOGNIZER_NAME = NAME
        FormRecognizerTest._RESOURCE_GROUP = ResourceGroup(name=RESOURCE_GROUP)
        yield
    else:
        test_case = AzureTestCase("__init__")
        rg_preparer = ResourceGroupPreparer(random_name_enabled=True,
                                            name_prefix='pycog',
                                            location=REGION)
        form_recognizer_preparer = CognitiveServicesAccountPreparer(
            random_name_enabled=True,
            kind="formrecognizer",
            name_prefix='pycog',
            location=REGION)

        try:
            rg_name, rg_kwargs = rg_preparer._prepare_create_resource(
                test_case)
            FormRecognizerTest._RESOURCE_GROUP = rg_kwargs['resource_group']
            try:
                form_recognizer_name, form_recognizer_kwargs = form_recognizer_preparer._prepare_create_resource(
                    test_case, **rg_kwargs)
                if test_case.is_live:
                    time.sleep(
                        600)  # current ask until race condition bug fixed
                FormRecognizerTest._FORM_RECOGNIZER_ACCOUNT = form_recognizer_kwargs[
                    'cognitiveservices_account']
                FormRecognizerTest._FORM_RECOGNIZER_KEY = form_recognizer_kwargs[
                    'cognitiveservices_account_key']
                FormRecognizerTest._FORM_RECOGNIZER_NAME = form_recognizer_name
                yield
            finally:
                form_recognizer_preparer.remove_resource(
                    form_recognizer_name,
                    resource_group=rg_kwargs['resource_group'])
                FormRecognizerTest._FORM_RECOGNIZER_ACCOUNT = None
                FormRecognizerTest._FORM_RECOGNIZER_KEY = None

        finally:
            rg_preparer.remove_resource(rg_name)
            FormRecognizerTest._RESOURCE_GROUP = None