Skip to content

Commit

Permalink
Validated all models.
Browse files Browse the repository at this point in the history
  • Loading branch information
Knucklessg1 committed May 13, 2024
1 parent 4c95b6e commit fa9827e
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 9 deletions.
10 changes: 5 additions & 5 deletions servicenow_api/servicenow_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ApplicationServiceModel(BaseModel):
- ValueError: If 'application_id' is provided and not a string.
"""

application_id: str = None
application_id: Optional[str] = None

@field_validator("application_id")
def validate_string_parameters(cls, v):
Expand Down Expand Up @@ -67,7 +67,7 @@ class CMDBModel(BaseModel):
- ValueError: If 'cmdb_id' is provided and not a string.
"""

cmdb_id: str = None
cmdb_id: Optional[str] = None

@field_validator("cmdb_id")
def validate_string_parameters(cls, v):
Expand Down Expand Up @@ -179,7 +179,7 @@ def validate_string_parameters(cls, v):
return v

@field_validator("sys_ids")
def validate_string_parameters(cls, v):
def validate_sys_ids_parameters(cls, v):
"""
Validate specific string parameters to ensure they are a List
Expand Down Expand Up @@ -497,7 +497,7 @@ class ImportSetModel(BaseModel):
- data (Dict): Dictionary containing additional data.
"""

table: str = None
table: Optional[str] = None
import_set_sys_id: Optional[str] = None
data: Optional[Dict] = None

Expand Down Expand Up @@ -644,7 +644,7 @@ class TableModel(BaseModel):
The class includes field_validator functions for specific attribute validations.
"""

table: str = None
table: Optional[str] = None
table_record_sys_id: Optional[str] = None
name_value_pairs: Optional[Dict] = None
sysparm_display_value: Optional[str] = None
Expand Down
83 changes: 79 additions & 4 deletions test/test_servicenow_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,95 @@
else:
skip = False


reason = "do not run on MacOS or windows OR dependency is not installed OR " + reason


@pytest.mark.skipif(
sys.platform in ["darwin"] or skip,
reason=reason,
)
def test_servicenow_models():
# test Project model group_id
def test_servicenow_article():
article_sys_id = "asdofaisudfa098098as0df9a8s"
article = KnowledgeManagementModel(article_sys_id=article_sys_id)
assert article_sys_id == article.article_sys_id


@pytest.mark.skipif(
sys.platform in ["darwin"] or skip,
reason=reason,
)
def test_servicenow_change():
change_request_sys_id = "asdofaisudfa098098as0df9a8s"
change = ChangeManagementModel(change_request_sys_id=change_request_sys_id)
assert change_request_sys_id == change.change_request_sys_id


@pytest.mark.skipif(
sys.platform in ["darwin"] or skip,
reason=reason,
)
def test_servicenow_incident():
incident_id = "asdofaisudfa098098as0df9a8s"
incident = IncidentModel(incident_id=incident_id)
assert incident_id == incident.incident_id


@pytest.mark.skipif(
sys.platform in ["darwin"] or skip,
reason=reason,
)
def test_servicenow_cicd():
result_id = "asdofaisudfa098098as0df9a8s"
cicd = CICDModel(result_id=result_id)
assert result_id == cicd.result_id


@pytest.mark.skipif(
sys.platform in ["darwin"] or skip,
reason=reason,
)
def test_servicenow_application():
application_id = "asdofaisudfa098098as0df9a8s"
application = ApplicationServiceModel(application_id=application_id)
assert application_id == application.application_id


@pytest.mark.skipif(
sys.platform in ["darwin"] or skip,
reason=reason,
)
def test_servicenow_table():
table_name = "users"
table = TableModel(table=table_name)
assert table_name == table.table


@pytest.mark.skipif(
sys.platform in ["darwin"] or skip,
reason=reason,
)
def test_servicenow_import_set():
import_set_sys_id = "asdofaisudfa098098as0df9a8s"
import_set = ImportSetModel(import_set_sys_id=import_set_sys_id)
assert import_set_sys_id == import_set.import_set_sys_id


@pytest.mark.skipif(
sys.platform in ["darwin"] or skip,
reason=reason,
)
def test_servicenow_cmdb():
cmdb_id = "asdofaisudfa098098as0df9a8s"
cmdb = CMDBModel(cmdb_id=cmdb_id)
assert cmdb_id == cmdb.cmdb_id


if __name__ == "__main__":
test_servicenow_models()
test_servicenow_article()
test_servicenow_change()
test_servicenow_incident()
test_servicenow_cicd()
test_servicenow_application()
test_servicenow_table()
test_servicenow_import_set()
test_servicenow_cmdb()

0 comments on commit fa9827e

Please sign in to comment.