Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ def begin_recognize_custom_forms(self, model_id, form, **kwargs):
:caption: Recognize fields and values from a custom form.
"""

if not model_id:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious - don't we have match conditions for delete operations in form?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you show me where you see that?

raise ValueError("model_id cannot be None or empty.")

cls = kwargs.pop("cls", None)
polling_interval = kwargs.pop("polling_interval", POLLING_INTERVAL)
content_type = kwargs.pop("content_type", None)
Expand Down Expand Up @@ -323,6 +326,9 @@ def begin_recognize_custom_forms_from_url(self, model_id, form_url, **kwargs):
:raises ~azure.core.exceptions.HttpResponseError:
"""

if not model_id:
raise ValueError("model_id cannot be None or empty.")

cls = kwargs.pop("cls", None)
polling_interval = kwargs.pop("polling_interval", POLLING_INTERVAL)
include_text_content = kwargs.pop("include_text_content", False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ def delete_model(self, model_id, **kwargs):
:caption: Delete a custom model.
"""

if not model_id:
raise ValueError("model_id cannot be None or empty.")

self._client.delete_custom_model(
model_id=model_id,
error_map=error_map,
Expand Down Expand Up @@ -245,6 +248,10 @@ def get_custom_model(self, model_id, **kwargs):
:dedent: 8
:caption: Get a custom model with a model ID.
"""

if not model_id:
raise ValueError("model_id cannot be None or empty.")

response = self._client.get_custom_model(model_id=model_id, include_keys=True, error_map=error_map, **kwargs)
return CustomFormModel._from_generated(response)

Expand Down Expand Up @@ -318,6 +325,9 @@ def begin_copy_model(
:caption: Copy a model from the source resource to the target resource
"""

if not model_id:
raise ValueError("model_id cannot be None or empty.")

polling_interval = kwargs.pop("polling_interval", POLLING_INTERVAL)

def _copy_callback(raw_response, _, headers): # pylint: disable=unused-argument
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ async def recognize_custom_forms(
:caption: Recognize fields and values from a custom form.
"""

if not model_id:
raise ValueError("model_id cannot be None or empty.")

cls = kwargs.pop("cls", None)
polling_interval = kwargs.pop("polling_interval", POLLING_INTERVAL)
content_type = kwargs.pop("content_type", None)
Expand Down Expand Up @@ -339,6 +342,9 @@ async def recognize_custom_forms_from_url(
:raises ~azure.core.exceptions.HttpResponseError:
"""

if not model_id:
raise ValueError("model_id cannot be None or empty.")

cls = kwargs.pop("cls", None)
polling_interval = kwargs.pop("polling_interval", POLLING_INTERVAL)
include_text_content = kwargs.pop("include_text_content", False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ async def delete_model(self, model_id: str, **kwargs: Any) -> None:
:dedent: 12
:caption: Delete a custom model.
"""

if not model_id:
raise ValueError("model_id cannot be None or empty.")

return await self._client.delete_custom_model(
model_id=model_id,
error_map=error_map,
Expand Down Expand Up @@ -248,6 +252,10 @@ async def get_custom_model(self, model_id: str, **kwargs: Any) -> CustomFormMode
:dedent: 12
:caption: Get a custom model with a model ID.
"""

if not model_id:
raise ValueError("model_id cannot be None or empty.")

response = await self._client.get_custom_model(
model_id=model_id,
include_keys=True,
Expand Down Expand Up @@ -327,6 +335,10 @@ async def copy_model(
:dedent: 8
:caption: Copy a model from the source resource to the target resource
"""

if not model_id:
raise ValueError("model_id cannot be None or empty.")

polling_interval = kwargs.pop("polling_interval", POLLING_INTERVAL)

def _copy_callback(raw_response, _, headers): # pylint: disable=unused-argument
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@

class TestCopyModel(FormRecognizerTest):

@GlobalFormRecognizerAccountPreparer()
@GlobalTrainingAccountPreparer()
def test_copy_model_none_model_id(self, client, container_sas_url):
with self.assertRaises(ValueError):
client.begin_copy_model(model_id=None, target={})

@GlobalFormRecognizerAccountPreparer()
@GlobalTrainingAccountPreparer()
def test_copy_model_empty_model_id(self, client, container_sas_url):
with self.assertRaises(ValueError):
client.begin_copy_model(model_id="", target={})

@GlobalFormRecognizerAccountPreparer()
@GlobalTrainingAccountPreparer(copy=True)
def test_copy_model_successful(self, client, container_sas_url, location, resource_id):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@

class TestCopyModelAsync(AsyncFormRecognizerTest):

@GlobalFormRecognizerAccountPreparer()
@GlobalTrainingAccountPreparer()
async def test_copy_model_none_model_id(self, client, container_sas_url):
with self.assertRaises(ValueError):
await client.copy_model(model_id=None, target={})

@GlobalFormRecognizerAccountPreparer()
@GlobalTrainingAccountPreparer()
async def test_copy_model_empty_model_id(self, client, container_sas_url):
with self.assertRaises(ValueError):
await client.copy_model(model_id="", target={})

@GlobalFormRecognizerAccountPreparer()
@GlobalTrainingAccountPreparer(copy=True)
async def test_copy_model_successful(self, client, container_sas_url, location, resource_id):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@

class TestCustomForms(FormRecognizerTest):

@GlobalFormRecognizerAccountPreparer()
def test_custom_form_none_model_id(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
client = FormRecognizerClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key))
with self.assertRaises(ValueError):
client.begin_recognize_custom_forms(model_id=None, form=b"xx")

@GlobalFormRecognizerAccountPreparer()
def test_custom_form_empty_model_id(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
client = FormRecognizerClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key))
with self.assertRaises(ValueError):
client.begin_recognize_custom_forms(model_id="", form=b"xx")

@GlobalFormRecognizerAccountPreparer()
def test_custom_form_bad_endpoint(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
with open(self.form_jpg, "rb") as fd:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@

class TestCustomFormsAsync(AsyncFormRecognizerTest):

@GlobalFormRecognizerAccountPreparer()
async def test_custom_form_none_model_id(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
client = FormRecognizerClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key))
with self.assertRaises(ValueError):
await client.recognize_custom_forms(model_id=None, form=b"xx")

@GlobalFormRecognizerAccountPreparer()
async def test_custom_form_empty_model_id(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
client = FormRecognizerClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key))
with self.assertRaises(ValueError):
await client.recognize_custom_forms(model_id="", form=b"xx")

@GlobalFormRecognizerAccountPreparer()
async def test_custom_form_bad_endpoint(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
with open(self.form_jpg, "rb") as fd:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@

class TestCustomFormsFromUrl(FormRecognizerTest):

@GlobalFormRecognizerAccountPreparer()
def test_custom_form_none_model_id(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
client = FormRecognizerClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key))
with self.assertRaises(ValueError):
client.begin_recognize_custom_forms_from_url(model_id=None, form_url="https://badurl.jpg")

@GlobalFormRecognizerAccountPreparer()
def test_custom_form_empty_model_id(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
client = FormRecognizerClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key))
with self.assertRaises(ValueError):
client.begin_recognize_custom_forms_from_url(model_id="", form_url="https://badurl.jpg")

@GlobalFormRecognizerAccountPreparer()
def test_custom_form_url_bad_endpoint(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
with self.assertRaises(ServiceRequestError):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@

class TestCustomFormsFromUrlAsync(AsyncFormRecognizerTest):

@GlobalFormRecognizerAccountPreparer()
async def test_custom_form_none_model_id(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
client = FormRecognizerClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key))
with self.assertRaises(ValueError):
await client.recognize_custom_forms_from_url(model_id=None, form_url="https://badurl.jpg")

@GlobalFormRecognizerAccountPreparer()
async def test_custom_form_empty_model_id(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
client = FormRecognizerClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key))
with self.assertRaises(ValueError):
await client.recognize_custom_forms_from_url(model_id="", form_url="https://badurl.jpg")

@GlobalFormRecognizerAccountPreparer()
async def test_custom_form_url_bad_endpoint(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
with self.assertRaises(ServiceRequestError):
Expand Down
24 changes: 24 additions & 0 deletions sdk/formrecognizer/azure-ai-formrecognizer/tests/test_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ def test_get_model_auth_bad_key(self, resource_group, location, form_recognizer_
with self.assertRaises(ClientAuthenticationError):
result = client.get_custom_model("xx")

@GlobalFormRecognizerAccountPreparer()
def test_get_model_empty_model_id(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
client = FormTrainingClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key))
with self.assertRaises(ValueError):
result = client.get_custom_model("")

@GlobalFormRecognizerAccountPreparer()
def test_get_model_none_model_id(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
client = FormTrainingClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key))
with self.assertRaises(ValueError):
result = client.get_custom_model(None)

@GlobalFormRecognizerAccountPreparer()
def test_list_model_auth_bad_key(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
client = FormTrainingClient(form_recognizer_account, AzureKeyCredential("xxxx"))
Expand All @@ -44,6 +56,18 @@ def test_delete_model_auth_bad_key(self, resource_group, location, form_recogniz
with self.assertRaises(ClientAuthenticationError):
client.delete_model("xx")

@GlobalFormRecognizerAccountPreparer()
def test_delete_model_none_model_id(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
client = FormTrainingClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key))
with self.assertRaises(ValueError):
result = client.delete_model(None)

@GlobalFormRecognizerAccountPreparer()
def test_delete_model_empty_model_id(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
client = FormTrainingClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key))
with self.assertRaises(ValueError):
result = client.delete_model("")

@GlobalFormRecognizerAccountPreparer()
def test_account_properties(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
client = FormTrainingClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ async def test_get_model_auth_bad_key(self, resource_group, location, form_recog
with self.assertRaises(ClientAuthenticationError):
result = await client.get_custom_model("xx")

@GlobalFormRecognizerAccountPreparer()
async def test_get_model_empty_model_id(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
client = FormTrainingClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key))
with self.assertRaises(ValueError):
result = await client.get_custom_model("")

@GlobalFormRecognizerAccountPreparer()
async def test_get_model_none_model_id(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
client = FormTrainingClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key))
with self.assertRaises(ValueError):
result = await client.get_custom_model(None)

@GlobalFormRecognizerAccountPreparer()
async def test_list_model_auth_bad_key(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
client = FormTrainingClient(form_recognizer_account, AzureKeyCredential("xxxx"))
Expand All @@ -45,6 +57,18 @@ async def test_delete_model_auth_bad_key(self, resource_group, location, form_re
with self.assertRaises(ClientAuthenticationError):
result = await client.delete_model("xx")

@GlobalFormRecognizerAccountPreparer()
async def test_delete_model_none_model_id(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
client = FormTrainingClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key))
with self.assertRaises(ValueError):
result = await client.delete_model(None)

@GlobalFormRecognizerAccountPreparer()
async def test_delete_model_empty_model_id(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
client = FormTrainingClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key))
with self.assertRaises(ValueError):
result = await client.delete_model("")

@GlobalFormRecognizerAccountPreparer()
async def test_account_properties(self, resource_group, location, form_recognizer_account, form_recognizer_account_key):
client = FormTrainingClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key))
Expand Down