Skip to content

Commit

Permalink
fix: adding missing tests related to subtype addition
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas committed Sep 2, 2024
1 parent b06bfcc commit 93fc2c4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/hrflow_connectors/core/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,9 +774,11 @@ class ConnectorModel(BaseModel):
def check_subtype(cls, value: str) -> str:
cleaned_value = value.lower()
if cleaned_value != value:
raise ValueError("ConnectorModel's `subtype` must be lowercase.")
raise ValueError(f"ConnectorModel's `subtype` {value} must be lowercase.")
if " " in cleaned_value:
raise ValueError("ConnectorModel's `subtype` must not contain any spaces.")
raise ValueError(
f"ConnectorModel's `subtype` {value} must not contain any spaces."
)
return cleaned_value

def logo(self, connectors_directory: Path) -> str:
Expand Down
38 changes: 38 additions & 0 deletions tests/core/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1688,3 +1688,41 @@ def new_format(*args, **kwargs):
assert str(excinfo.value) == (
"Duplicate action name {} in `with_parameters_override` and `with_actions`"
).format(parameters_action_name.name)


def test_connector_lowercase_subtype_constraint():
subtype = "SmartLeads"
with pytest.raises(ValidationError) as excinfo:
Connector(
name="SmartLeads",
type=ConnectorType.Other,
subtype=subtype,
description=DESCRIPTION,
url="https://www.smartleads.test/",
actions=[],
)
expected_error = (
"1 validation error for ConnectorModel"
"\nsubtype"
"\n ConnectorModel's `subtype` {} must be lowercase. (type=value_error)"
.format(subtype)
)
assert str(excinfo.value) == expected_error


def test_connector_space_subtype_constraint():
subtype = "smart leads"
with pytest.raises(ValidationError) as excinfo:
Connector(
name="SmartLeads",
type=ConnectorType.Other,
subtype=subtype,
description=DESCRIPTION,
url="https://www.smartleads.test/",
actions=[],
)
expected_error = (
"1 validation error for ConnectorModel\nsubtype\n ConnectorModel's `subtype`"
" {} must not contain any spaces. (type=value_error)".format(subtype)
)
assert str(excinfo.value) == expected_error

0 comments on commit 93fc2c4

Please sign in to comment.