Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tupyy committed Mar 1, 2024
1 parent b76b24b commit ea36107
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/unit/plugins/module_utils/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,37 @@ def test_get_record_by_sys_id(self, client):

assert dict(a=3, b="sys_id") == record
client.get.assert_called_with("api/now/table/my_table/sys_id")

def test_get_record_by_sys_id_must_exists(self, client):
client.get.return_value = Response(
200, '{"result": {"a": 3, "b": "sys_id"}}', {"X-Total-Count": "1"}
)
t = table.TableClient(client)

record = t.get_record_by_sys_id("my_table", "sys_id", True)

assert dict(a=3, b="sys_id") == record
client.get.assert_called_with("api/now/table/my_table/sys_id")

def test_get_record_by_sys_id_no_record(self, client):
client.get.return_value = Response(
404, '{"error": {"message": "no record found"}}', {}
)
t = table.TableClient(client)

record = t.get_record_by_sys_id("my_table", "sys_id")

assert not record
client.get.assert_called_with("api/now/table/my_table/sys_id")

def test_get_record_by_sys_id_no_record_must_exists(self, client):
client.get.return_value = Response(
404, '{"error": {"message": "no record found"}}', {}
)
t = table.TableClient(client)

with pytest.raises(errors.ServiceNowError, match="No"):
t.get_record_by_sys_id("my_table", "sys_id", True)


class TestTableCreateRecord:
Expand Down

0 comments on commit ea36107

Please sign in to comment.