diff --git a/ibutsu_client/models/account_recovery.py b/ibutsu_client/models/account_recovery.py index d212dad..c115f43 100644 --- a/ibutsu_client/models/account_recovery.py +++ b/ibutsu_client/models/account_recovery.py @@ -39,8 +39,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/account_registration.py b/ibutsu_client/models/account_registration.py index bda4405..9caf0db 100644 --- a/ibutsu_client/models/account_registration.py +++ b/ibutsu_client/models/account_registration.py @@ -40,8 +40,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/account_reset.py b/ibutsu_client/models/account_reset.py index 67973b6..cecc9a5 100644 --- a/ibutsu_client/models/account_reset.py +++ b/ibutsu_client/models/account_reset.py @@ -40,8 +40,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/artifact.py b/ibutsu_client/models/artifact.py index a0fff64..0560095 100644 --- a/ibutsu_client/models/artifact.py +++ b/ibutsu_client/models/artifact.py @@ -58,8 +58,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/artifact_list.py b/ibutsu_client/models/artifact_list.py index ed2a211..f052a52 100644 --- a/ibutsu_client/models/artifact_list.py +++ b/ibutsu_client/models/artifact_list.py @@ -43,8 +43,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/create_token.py b/ibutsu_client/models/create_token.py index 99963f9..aebc545 100644 --- a/ibutsu_client/models/create_token.py +++ b/ibutsu_client/models/create_token.py @@ -40,8 +40,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/credentials.py b/ibutsu_client/models/credentials.py index c6b377f..0f4b736 100644 --- a/ibutsu_client/models/credentials.py +++ b/ibutsu_client/models/credentials.py @@ -40,8 +40,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/dashboard.py b/ibutsu_client/models/dashboard.py index 2048025..94e75ee 100644 --- a/ibutsu_client/models/dashboard.py +++ b/ibutsu_client/models/dashboard.py @@ -58,8 +58,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/dashboard_list.py b/ibutsu_client/models/dashboard_list.py index 69af9e0..9176124 100644 --- a/ibutsu_client/models/dashboard_list.py +++ b/ibutsu_client/models/dashboard_list.py @@ -43,8 +43,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/group.py b/ibutsu_client/models/group.py index f9508c6..256d71b 100644 --- a/ibutsu_client/models/group.py +++ b/ibutsu_client/models/group.py @@ -41,8 +41,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/group_list.py b/ibutsu_client/models/group_list.py index cd41947..99182d8 100644 --- a/ibutsu_client/models/group_list.py +++ b/ibutsu_client/models/group_list.py @@ -43,8 +43,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/health_info.py b/ibutsu_client/models/health_info.py index 41a8c04..3185b8b 100644 --- a/ibutsu_client/models/health_info.py +++ b/ibutsu_client/models/health_info.py @@ -41,8 +41,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/login_config.py b/ibutsu_client/models/login_config.py index 1d7f0a2..6b0388c 100644 --- a/ibutsu_client/models/login_config.py +++ b/ibutsu_client/models/login_config.py @@ -43,8 +43,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/login_error.py b/ibutsu_client/models/login_error.py index 09ad52e..2c0bd88 100644 --- a/ibutsu_client/models/login_error.py +++ b/ibutsu_client/models/login_error.py @@ -44,8 +44,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/login_support.py b/ibutsu_client/models/login_support.py index 5b8e839..a53847a 100644 --- a/ibutsu_client/models/login_support.py +++ b/ibutsu_client/models/login_support.py @@ -63,8 +63,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/login_token.py b/ibutsu_client/models/login_token.py index 2409aa9..47c47be 100644 --- a/ibutsu_client/models/login_token.py +++ b/ibutsu_client/models/login_token.py @@ -41,8 +41,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/model_import.py b/ibutsu_client/models/model_import.py index ccca1b8..8d17b53 100644 --- a/ibutsu_client/models/model_import.py +++ b/ibutsu_client/models/model_import.py @@ -49,8 +49,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/pagination.py b/ibutsu_client/models/pagination.py index 9f74399..3d7b8b1 100644 --- a/ibutsu_client/models/pagination.py +++ b/ibutsu_client/models/pagination.py @@ -48,8 +48,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/project_list.py b/ibutsu_client/models/project_list.py index c42aeed..f2899e7 100644 --- a/ibutsu_client/models/project_list.py +++ b/ibutsu_client/models/project_list.py @@ -43,8 +43,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/result_list.py b/ibutsu_client/models/result_list.py index e8b4762..759fbee 100644 --- a/ibutsu_client/models/result_list.py +++ b/ibutsu_client/models/result_list.py @@ -43,8 +43,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/run_list.py b/ibutsu_client/models/run_list.py index 8deccf3..dc37ff9 100644 --- a/ibutsu_client/models/run_list.py +++ b/ibutsu_client/models/run_list.py @@ -43,8 +43,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/token.py b/ibutsu_client/models/token.py index 345ec76..d30d946 100644 --- a/ibutsu_client/models/token.py +++ b/ibutsu_client/models/token.py @@ -46,8 +46,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/token_list.py b/ibutsu_client/models/token_list.py index f3a4ad6..2f8745c 100644 --- a/ibutsu_client/models/token_list.py +++ b/ibutsu_client/models/token_list.py @@ -43,8 +43,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/update_run.py b/ibutsu_client/models/update_run.py index a9f3fdc..f296354 100644 --- a/ibutsu_client/models/update_run.py +++ b/ibutsu_client/models/update_run.py @@ -39,8 +39,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/user.py b/ibutsu_client/models/user.py index 72e026a..2e6bb48 100644 --- a/ibutsu_client/models/user.py +++ b/ibutsu_client/models/user.py @@ -56,8 +56,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/user_list.py b/ibutsu_client/models/user_list.py index bd88b51..2019553 100644 --- a/ibutsu_client/models/user_list.py +++ b/ibutsu_client/models/user_list.py @@ -43,8 +43,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/widget_config.py b/ibutsu_client/models/widget_config.py index b93ae34..6b5e37e 100644 --- a/ibutsu_client/models/widget_config.py +++ b/ibutsu_client/models/widget_config.py @@ -67,8 +67,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/widget_config_list.py b/ibutsu_client/models/widget_config_list.py index 573a2c6..bebd38d 100644 --- a/ibutsu_client/models/widget_config_list.py +++ b/ibutsu_client/models/widget_config_list.py @@ -43,8 +43,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/widget_param.py b/ibutsu_client/models/widget_param.py index 630d591..334544f 100644 --- a/ibutsu_client/models/widget_param.py +++ b/ibutsu_client/models/widget_param.py @@ -47,8 +47,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/widget_type.py b/ibutsu_client/models/widget_type.py index e6c97d9..ce5e8dc 100644 --- a/ibutsu_client/models/widget_type.py +++ b/ibutsu_client/models/widget_type.py @@ -53,8 +53,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/ibutsu_client/models/widget_type_list.py b/ibutsu_client/models/widget_type_list.py index b0335e0..8778663 100644 --- a/ibutsu_client/models/widget_type_list.py +++ b/ibutsu_client/models/widget_type_list.py @@ -43,8 +43,7 @@ def to_str(self) -> str: def to_json(self) -> str: """Returns the JSON representation of the model using alias""" - # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead - return json.dumps(self.to_dict()) + return self.model_dump_json(by_alias=True, exclude_none=True) @classmethod def from_json(cls, json_str: str) -> Self | None: diff --git a/test/test_account_recovery.py b/test/test_account_recovery.py index 4e846f9..ae6b096 100644 --- a/test/test_account_recovery.py +++ b/test/test_account_recovery.py @@ -9,43 +9,59 @@ Do not edit the class manually. """ -import unittest +import json + +import pytest +from pydantic import ValidationError from ibutsu_client.models.account_recovery import AccountRecovery -class TestAccountRecovery(unittest.TestCase): - """AccountRecovery unit test stubs""" - - def setUp(self): - pass - - def tearDown(self): - pass - - def make_instance(self, include_optional) -> AccountRecovery: - """Test AccountRecovery - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `AccountRecovery` - """ - model = AccountRecovery() - if include_optional: - return AccountRecovery( - email = 'user@domain.com' - ) - else: - return AccountRecovery( - email = 'user@domain.com', - ) - """ - - def testAccountRecovery(self): - """Test AccountRecovery""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) - - -if __name__ == "__main__": - unittest.main() +class TestAccountRecovery: + """AccountRecovery model tests""" + + def test_creation_empty(self): + with pytest.raises(ValidationError): + AccountRecovery() + + def test_creation_full(self): + model = AccountRecovery(email="test@example.com") + assert model.email == "test@example.com" + + def test_to_dict(self): + model = AccountRecovery(email="test@example.com") + d = model.to_dict() + assert d["email"] == "test@example.com" + + def test_to_json(self): + model = AccountRecovery(email="test@example.com") + j = model.to_json() + data = json.loads(j) + assert data["email"] == "test@example.com" + + def test_from_dict(self): + d = {"email": "test@example.com"} + model = AccountRecovery.from_dict(d) + assert model.email == "test@example.com" + + def test_from_json(self): + j = '{"email": "test@example.com"}' + model = AccountRecovery.from_json(j) + assert model.email == "test@example.com" + + def test_to_str(self): + model = AccountRecovery(email="test@example.com") + assert "test@example.com" in model.to_str() + + def test_from_dict_none(self): + assert AccountRecovery.from_dict(None) is None + + def test_from_dict_non_dict(self): + orig = AccountRecovery(email="test@example.com") + model = AccountRecovery.from_dict(orig) + assert model.email == "test@example.com" + + def test_none_values_excluded(self): + model = AccountRecovery(email="test@example.com") + d = model.to_dict() + assert "email" in d diff --git a/test/test_account_registration.py b/test/test_account_registration.py index 187dcba..cd43a1c 100644 --- a/test/test_account_registration.py +++ b/test/test_account_registration.py @@ -9,45 +9,60 @@ Do not edit the class manually. """ -import unittest +import json + +import pytest +from pydantic import ValidationError from ibutsu_client.models.account_registration import AccountRegistration -class TestAccountRegistration(unittest.TestCase): - """AccountRegistration unit test stubs""" - - def setUp(self): - pass - - def tearDown(self): - pass - - def make_instance(self, include_optional) -> AccountRegistration: - """Test AccountRegistration - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `AccountRegistration` - """ - model = AccountRegistration() - if include_optional: - return AccountRegistration( - email = 'user@domain.com', - password = 'supersecretpassword' - ) - else: - return AccountRegistration( - email = 'user@domain.com', - password = 'supersecretpassword', - ) - """ - - def testAccountRegistration(self): - """Test AccountRegistration""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) - - -if __name__ == "__main__": - unittest.main() +class TestAccountRegistration: + """AccountRegistration model tests""" + + def test_creation_empty(self): + with pytest.raises(ValidationError): + AccountRegistration() + + def test_creation_full(self): + model = AccountRegistration(email="test@example.com", password="pass") + assert model.email == "test@example.com" + assert model.password == "pass" + + def test_to_dict(self): + model = AccountRegistration(email="test@example.com", password="pass") + d = model.to_dict() + assert d["email"] == "test@example.com" + + def test_to_json(self): + model = AccountRegistration(email="test@example.com", password="pass") + j = model.to_json() + data = json.loads(j) + assert data["email"] == "test@example.com" + + def test_from_dict(self): + d = {"email": "test@example.com", "password": "pass"} + model = AccountRegistration.from_dict(d) + assert model.email == "test@example.com" + + def test_from_json(self): + j = '{"email": "test@example.com", "password": "pass"}' + model = AccountRegistration.from_json(j) + assert model.email == "test@example.com" + + def test_to_str(self): + model = AccountRegistration(email="test@example.com", password="pass") + assert "test@example.com" in model.to_str() + + def test_from_dict_none(self): + assert AccountRegistration.from_dict(None) is None + + def test_from_dict_non_dict(self): + orig = AccountRegistration(email="test@example.com", password="pass") + model = AccountRegistration.from_dict(orig) + assert model.email == "test@example.com" + + def test_none_values_excluded(self): + model = AccountRegistration(email="test@example.com", password="pass") + d = model.to_dict() + assert "email" in d diff --git a/test/test_account_reset.py b/test/test_account_reset.py index 4487e70..35ffcfc 100644 --- a/test/test_account_reset.py +++ b/test/test_account_reset.py @@ -9,45 +9,58 @@ Do not edit the class manually. """ -import unittest +import json from ibutsu_client.models.account_reset import AccountReset -class TestAccountReset(unittest.TestCase): - """AccountReset unit test stubs""" - - def setUp(self): - pass - - def tearDown(self): - pass - - def make_instance(self, include_optional) -> AccountReset: - """Test AccountReset - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `AccountReset` - """ - model = AccountReset() - if include_optional: - return AccountReset( - activation_code = 'YjdmYWFkMTItNzkxZC00MjE4LTgwZGItOWFlOWM2Y2RhOTM5', - password = 'supersecretpassword' - ) - else: - return AccountReset( - activation_code = 'YjdmYWFkMTItNzkxZC00MjE4LTgwZGItOWFlOWM2Y2RhOTM5', - password = 'supersecretpassword', - ) - """ - - def testAccountReset(self): - """Test AccountReset""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) - - -if __name__ == "__main__": - unittest.main() +class TestAccountReset: + """AccountReset model tests""" + + def test_creation_empty(self): + model = AccountReset(activation_code="abc", password="pass") + assert model.activation_code == "abc" + assert model.password == "pass" + + def test_creation_full(self): + model = AccountReset(activation_code="abc", password="pass") + assert model.activation_code == "abc" + assert model.password == "pass" + + def test_to_dict(self): + model = AccountReset(activation_code="abc", password="pass") + d = model.to_dict() + assert d["activation_code"] == "abc" + + def test_to_json(self): + model = AccountReset(activation_code="abc", password="pass") + j = model.to_json() + data = json.loads(j) + assert data["activation_code"] == "abc" + + def test_from_dict(self): + d = {"activation_code": "abc", "password": "pass"} + model = AccountReset.from_dict(d) + assert model.activation_code == "abc" + + def test_from_json(self): + j = '{"activation_code": "abc", "password": "pass"}' + model = AccountReset.from_json(j) + assert model.activation_code == "abc" + + def test_to_str(self): + model = AccountReset(activation_code="abc", password="pass") + assert "abc" in model.to_str() + + def test_from_dict_none(self): + assert AccountReset.from_dict(None) is None + + def test_from_dict_non_dict(self): + orig = AccountReset(activation_code="abc", password="pass") + model = AccountReset.from_dict(orig) + assert model.activation_code == "abc" + + def test_none_values_excluded(self): + model = AccountReset(activation_code="abc", password="pass") + d = model.to_dict() + assert "activation_code" in d diff --git a/test/test_artifact.py b/test/test_artifact.py index 520a394..fcab217 100644 --- a/test/test_artifact.py +++ b/test/test_artifact.py @@ -9,47 +9,108 @@ Do not edit the class manually. """ -import unittest +import json +from uuid import uuid4 from ibutsu_client.models.artifact import Artifact -class TestArtifact(unittest.TestCase): - """Artifact unit test stubs""" - - def setUp(self): - pass - - def tearDown(self): - pass - - def make_instance(self, include_optional) -> Artifact: - """Test Artifact - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `Artifact` - """ - model = Artifact() - if include_optional: - return Artifact( - id = '22785097-a256-4aad-874b-9c204caba341', - result_id = 'a16ad60e-bf23-4195-99dc-594858ad3e5e', - run_id = '04af3d2a-55c5-4562-9ed6-3bf30ac6753e', - filename = '', - additional_metadata = None, - upload_date = '' - ) - else: - return Artifact( +class TestArtifact: + """Artifact model tests""" + + def test_artifact_creation_empty(self): + """Test Artifact creation with no parameters""" + artifact = Artifact() + assert artifact.id is None + assert artifact.filename is None + + def test_artifact_creation_full(self): + """Test Artifact creation with all parameters""" + artifact_id = uuid4() + result_id = uuid4() + run_id = uuid4() + + artifact = Artifact( + id=artifact_id, + result_id=result_id, + run_id=run_id, + filename="test_file.txt", + additional_metadata={"size": 1024}, + upload_date="2023-01-01T12:00:00Z", ) - """ - def testArtifact(self): - """Test Artifact""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) + assert artifact.id == artifact_id + assert artifact.result_id == result_id + assert artifact.run_id == run_id + assert artifact.filename == "test_file.txt" + assert artifact.additional_metadata == {"size": 1024} + + def test_artifact_to_dict(self): + """Test Artifact to_dict conversion""" + artifact = Artifact(filename="dict_file.txt") + artifact_dict = artifact.to_dict() + + assert isinstance(artifact_dict, dict) + assert artifact_dict["filename"] == "dict_file.txt" + + def test_artifact_to_json(self): + """Test Artifact to_json conversion""" + artifact = Artifact(filename="json_file.txt") + artifact_json = artifact.to_json() + + assert isinstance(artifact_json, str) + parsed = json.loads(artifact_json) + assert parsed["filename"] == "json_file.txt" + + def test_artifact_from_dict(self): + """Test Artifact from_dict creation""" + artifact_dict = {"filename": "from_dict.txt", "additional_metadata": {"key": "val"}} + artifact = Artifact.from_dict(artifact_dict) + + assert isinstance(artifact, Artifact) + assert artifact.filename == "from_dict.txt" + assert artifact.additional_metadata == {"key": "val"} + + def test_artifact_from_json(self): + """Test Artifact from_json creation""" + artifact_json = '{"filename": "from_json.txt"}' + artifact = Artifact.from_json(artifact_json) + + assert isinstance(artifact, Artifact) + assert artifact.filename == "from_json.txt" + + def test_artifact_to_str(self): + """Test Artifact to_str representation""" + artifact = Artifact(filename="str_file.txt") + artifact_str = artifact.to_str() + + assert isinstance(artifact_str, str) + assert "str_file.txt" in artifact_str + + def test_artifact_none_values_excluded(self): + """Test that None values are excluded from dict""" + artifact = Artifact(filename="none_file.txt") + artifact_dict = artifact.to_dict() + + assert "filename" in artifact_dict + assert "upload_date" not in artifact_dict + + def test_artifact_from_dict_none(self): + """Test Artifact.from_dict with None returns None""" + artifact = Artifact.from_dict(None) + assert artifact is None + + def test_artifact_from_dict_non_dict(self): + """Test from_dict with a non-dict object""" + art_obj = Artifact(filename="test_obj") + new_art = Artifact.from_dict(art_obj) + assert new_art.filename == "test_obj" + def test_artifact_roundtrip_json(self): + """Test Artifact can be serialized and deserialized""" + original = Artifact(filename="roundtrip.txt", result_id=uuid4()) + json_str = original.to_json() + restored = Artifact.from_json(json_str) -if __name__ == "__main__": - unittest.main() + assert restored.filename == original.filename + assert restored.result_id == original.result_id diff --git a/test/test_artifact_list.py b/test/test_artifact_list.py index a313fd0..d57a180 100644 --- a/test/test_artifact_list.py +++ b/test/test_artifact_list.py @@ -9,45 +9,139 @@ Do not edit the class manually. """ -import unittest +import json +from uuid import uuid4 +from ibutsu_client.models.artifact import Artifact from ibutsu_client.models.artifact_list import ArtifactList +from ibutsu_client.models.pagination import Pagination -class TestArtifactList(unittest.TestCase): - """ArtifactList unit test stubs""" - - def setUp(self): - pass - - def tearDown(self): - pass - - def make_instance(self, include_optional) -> ArtifactList: - """Test ArtifactList - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `ArtifactList` - """ - model = ArtifactList() - if include_optional: - return ArtifactList( - artifacts = [ - {"filename":"filename","result_id":"a16ad60e-bf23-4195-99dc-594858ad3e5e","id":"22785097-a256-4aad-874b-9c204caba341","additional_metadata":{"key":"{}"},"upload_date":"2021-03-08T14:48:51+00:00"} - ], - pagination = {"page":2,"pageSize":25,"totalPages":10,"totalItems":243} - ) - else: - return ArtifactList( - ) - """ - - def testArtifactList(self): - """Test ArtifactList""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) - - -if __name__ == "__main__": - unittest.main() +class TestArtifactList: + """ArtifactList model tests""" + + def test_artifact_list_creation_empty(self): + """Test ArtifactList creation with no parameters""" + artifact_list = ArtifactList() + assert artifact_list.artifacts is None + assert artifact_list.pagination is None + + def test_artifact_list_creation_full(self): + """Test ArtifactList creation with all parameters""" + artifact = Artifact(filename="test.txt") + pagination = Pagination(page=1, page_size=10) + + artifact_list = ArtifactList(artifacts=[artifact], pagination=pagination) + + assert len(artifact_list.artifacts) == 1 + assert artifact_list.artifacts[0].filename == "test.txt" + assert artifact_list.pagination.page == 1 + + def test_artifact_list_to_dict(self): + """Test ArtifactList to_dict conversion""" + artifact = Artifact(filename="dict.txt") + pagination = Pagination(page=1) + artifact_list = ArtifactList(artifacts=[artifact], pagination=pagination) + + artifact_list_dict = artifact_list.to_dict() + + assert isinstance(artifact_list_dict, dict) + assert "artifacts" in artifact_list_dict + assert len(artifact_list_dict["artifacts"]) == 1 + assert artifact_list_dict["artifacts"][0]["filename"] == "dict.txt" + assert "pagination" in artifact_list_dict + assert artifact_list_dict["pagination"]["page"] == 1 + + def test_artifact_list_to_json(self): + """Test ArtifactList to_json conversion""" + artifact = Artifact(filename="json.txt") + artifact_list = ArtifactList(artifacts=[artifact]) + artifact_list_json = artifact_list.to_json() + + assert isinstance(artifact_list_json, str) + parsed = json.loads(artifact_list_json) + assert len(parsed["artifacts"]) == 1 + assert parsed["artifacts"][0]["filename"] == "json.txt" + + def test_artifact_list_from_dict(self): + """Test ArtifactList from_dict creation""" + artifact_dict = {"filename": "from_dict.txt"} + pagination_dict = {"page": 2} + list_dict = {"artifacts": [artifact_dict], "pagination": pagination_dict} + + artifact_list = ArtifactList.from_dict(list_dict) + + assert isinstance(artifact_list, ArtifactList) + assert len(artifact_list.artifacts) == 1 + assert isinstance(artifact_list.artifacts[0], Artifact) + assert artifact_list.artifacts[0].filename == "from_dict.txt" + assert isinstance(artifact_list.pagination, Pagination) + assert artifact_list.pagination.page == 2 + + def test_artifact_list_from_json(self): + """Test ArtifactList from_json creation""" + json_str = '{"artifacts": [{"filename": "from_json.txt"}], "pagination": {"page": 3}}' + artifact_list = ArtifactList.from_json(json_str) + + assert isinstance(artifact_list, ArtifactList) + assert artifact_list.artifacts[0].filename == "from_json.txt" + assert artifact_list.pagination.page == 3 + + def test_artifact_list_to_str(self): + """Test ArtifactList to_str representation""" + artifact_list = ArtifactList() + list_str = artifact_list.to_str() + + assert isinstance(list_str, str) + + def test_artifact_list_none_values_excluded(self): + """Test that None values are excluded from dict""" + artifact_list = ArtifactList(artifacts=[]) + list_dict = artifact_list.to_dict() + + assert "artifacts" in list_dict # Empty list is not None + assert "pagination" not in list_dict + + def test_artifact_list_from_dict_none(self): + """Test ArtifactList.from_dict with None returns None""" + artifact_list = ArtifactList.from_dict(None) + assert artifact_list is None + + def test_artifact_list_from_dict_non_dict(self): + """Test from_dict with a non-dict object""" + # This might be tricky because from_dict has specific logic for artifacts list + # But model_validate might handle it if the object has attributes matching fields + # However, the custom from_dict in ArtifactList assumes obj is a dict (obj["artifacts"]) + # Let's check the code. + # Code check: + # if not isinstance(obj, dict): + # return cls.model_validate(obj) + # So if not dict, it bypasses the manual list comprehension. + # So testing this path is valid. + + artifact = Artifact(filename="test_obj") + list_obj = ArtifactList(artifacts=[artifact]) + new_list = ArtifactList.from_dict(list_obj) + assert len(new_list.artifacts) == 1 + assert new_list.artifacts[0].filename == "test_obj" + + def test_artifact_list_multiple_items(self): + """Test ArtifactList to_dict with multiple items""" + art1 = Artifact(filename="1.txt") + art2 = Artifact(filename="2.txt") + artifact_list = ArtifactList(artifacts=[art1, art2]) + + list_dict = artifact_list.to_dict() + assert len(list_dict["artifacts"]) == 2 + + def test_artifact_list_roundtrip_json(self): + """Test ArtifactList can be serialized and deserialized""" + artifact = Artifact(filename="roundtrip.txt", result_id=uuid4()) + pagination = Pagination(page=1) + original = ArtifactList(artifacts=[artifact], pagination=pagination) + + json_str = original.to_json() + restored = ArtifactList.from_json(json_str) + + assert restored.artifacts[0].filename == original.artifacts[0].filename + assert restored.pagination.page == original.pagination.page diff --git a/test/test_create_token.py b/test/test_create_token.py index 870b075..cea796e 100644 --- a/test/test_create_token.py +++ b/test/test_create_token.py @@ -9,45 +9,61 @@ Do not edit the class manually. """ -import unittest +import json + +import pytest +from pydantic import ValidationError from ibutsu_client.models.create_token import CreateToken -class TestCreateToken(unittest.TestCase): - """CreateToken unit test stubs""" - - def setUp(self): - pass - - def tearDown(self): - pass - - def make_instance(self, include_optional) -> CreateToken: - """Test CreateToken - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `CreateToken` - """ - model = CreateToken() - if include_optional: - return CreateToken( - name = 'My user token', - expires = '2038-12-31T23:59:59+0000' - ) - else: - return CreateToken( - name = 'My user token', - expires = '2038-12-31T23:59:59+0000', - ) - """ - - def testCreateToken(self): - """Test CreateToken""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) - - -if __name__ == "__main__": - unittest.main() +class TestCreateToken: + """CreateToken model tests""" + + def test_creation_empty(self): + with pytest.raises(ValidationError): + CreateToken() + + def test_creation_full(self): + model = CreateToken(name="token1", expires="2023-12-31") + assert model.name == "token1" + assert model.expires == "2023-12-31" + + def test_to_dict(self): + model = CreateToken(name="token1", expires="2023-12-31") + d = model.to_dict() + assert d["name"] == "token1" + + def test_to_json(self): + model = CreateToken(name="token1", expires="2023-12-31") + j = model.to_json() + data = json.loads(j) + assert data["name"] == "token1" + + def test_from_dict(self): + d = {"name": "token1", "expires": "2023-12-31"} + model = CreateToken.from_dict(d) + assert model.name == "token1" + + def test_from_json(self): + j = '{"name": "token1", "expires": "2023-12-31"}' + model = CreateToken.from_json(j) + assert model.name == "token1" + + def test_to_str(self): + model = CreateToken(name="token1", expires="2023-12-31") + assert "token1" in model.to_str() + + def test_from_dict_none(self): + assert CreateToken.from_dict(None) is None + + def test_from_dict_non_dict(self): + orig = CreateToken(name="token1", expires="2023-12-31") + model = CreateToken.from_dict(orig) + assert model.name == "token1" + + def test_explicit_nones(self): + # Assuming CreateToken handles explicit None for nullable fields + model = CreateToken(name="token1", expires=None) + d = model.to_dict() + assert d["expires"] is None diff --git a/test/test_credentials.py b/test/test_credentials.py index 119ddf1..ae752d8 100644 --- a/test/test_credentials.py +++ b/test/test_credentials.py @@ -9,45 +9,61 @@ Do not edit the class manually. """ -import unittest +import json + +import pytest +from pydantic import ValidationError from ibutsu_client.models.credentials import Credentials -class TestCredentials(unittest.TestCase): - """Credentials unit test stubs""" - - def setUp(self): - pass - - def tearDown(self): - pass - - def make_instance(self, include_optional) -> Credentials: - """Test Credentials - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `Credentials` - """ - model = Credentials() - if include_optional: - return Credentials( - email = 'me@example.com', - password = 'mysupersecretpassword' - ) - else: - return Credentials( - email = 'me@example.com', - password = 'mysupersecretpassword', - ) - """ - - def testCredentials(self): - """Test Credentials""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) - - -if __name__ == "__main__": - unittest.main() +class TestCredentials: + """Credentials model tests""" + + def test_creation_empty(self): + with pytest.raises(ValidationError): + Credentials() + + def test_creation_full(self): + model = Credentials(email="test@example.com", password="pass") + assert model.email == "test@example.com" + assert model.password == "pass" + + def test_to_dict(self): + model = Credentials(email="test@example.com", password="pass") + d = model.to_dict() + assert d["email"] == "test@example.com" + + def test_to_json(self): + model = Credentials(email="test@example.com", password="pass") + j = model.to_json() + data = json.loads(j) + assert data["email"] == "test@example.com" + + def test_from_dict(self): + d = {"email": "test@example.com", "password": "pass"} + model = Credentials.from_dict(d) + assert model.email == "test@example.com" + + def test_from_json(self): + j = '{"email": "test@example.com", "password": "pass"}' + model = Credentials.from_json(j) + assert model.email == "test@example.com" + + def test_to_str(self): + model = Credentials(email="test@example.com", password="pass") + assert "test@example.com" in model.to_str() + + def test_from_dict_none(self): + assert Credentials.from_dict(None) is None + + def test_from_dict_non_dict(self): + orig = Credentials(email="test@example.com", password="pass") + model = Credentials.from_dict(orig) + assert model.email == "test@example.com" + + def test_none_values_excluded(self): + model = Credentials(email="test@example.com", password="pass") + d = model.to_dict() + assert "email" in d + assert "password" in d diff --git a/test/test_dashboard.py b/test/test_dashboard.py index cb9c9ac..41aa081 100644 --- a/test/test_dashboard.py +++ b/test/test_dashboard.py @@ -9,47 +9,109 @@ Do not edit the class manually. """ -import unittest +import json +from uuid import uuid4 from ibutsu_client.models.dashboard import Dashboard -class TestDashboard(unittest.TestCase): - """Dashboard unit test stubs""" - - def setUp(self): - pass - - def tearDown(self): - pass - - def make_instance(self, include_optional) -> Dashboard: - """Test Dashboard - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `Dashboard` - """ - model = Dashboard() - if include_optional: - return Dashboard( - id = '62faa4ce-d264-46c2-813e-579949c8ab9b', - title = 'My Dashboard', - description = 'A dashboard for me', - filters = '', - project_id = '44941c55-9736-42f6-acce-ca3c4739d0f3', - user_id = '90be2a4a-1a4d-4779-b40f-f08ccd7101d5' - ) - else: - return Dashboard( +class TestDashboard: + """Dashboard model tests""" + + def test_dashboard_creation_empty(self): + """Test Dashboard creation with no parameters""" + dashboard = Dashboard() + assert dashboard.id is None + assert dashboard.title is None + + def test_dashboard_creation_full(self): + """Test Dashboard creation with all parameters""" + dashboard_id = uuid4() + project_id = uuid4() + user_id = uuid4() + + dashboard = Dashboard( + id=dashboard_id, + title="My Dashboard", + description="A description", + filters="key=value", + project_id=project_id, + user_id=user_id, ) - """ - def testDashboard(self): - """Test Dashboard""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) + assert dashboard.id == dashboard_id + assert dashboard.title == "My Dashboard" + assert dashboard.description == "A description" + assert dashboard.filters == "key=value" + assert dashboard.project_id == project_id + assert dashboard.user_id == user_id + + def test_dashboard_to_dict(self): + """Test Dashboard to_dict conversion""" + dashboard = Dashboard(title="Dict Dashboard") + dashboard_dict = dashboard.to_dict() + + assert isinstance(dashboard_dict, dict) + assert dashboard_dict["title"] == "Dict Dashboard" + + def test_dashboard_to_json(self): + """Test Dashboard to_json conversion""" + dashboard = Dashboard(title="JSON Dashboard") + dashboard_json = dashboard.to_json() + + assert isinstance(dashboard_json, str) + parsed = json.loads(dashboard_json) + assert parsed["title"] == "JSON Dashboard" + + def test_dashboard_from_dict(self): + """Test Dashboard from_dict creation""" + dashboard_dict = {"title": "From Dict", "description": "Desc"} + dashboard = Dashboard.from_dict(dashboard_dict) + + assert isinstance(dashboard, Dashboard) + assert dashboard.title == "From Dict" + assert dashboard.description == "Desc" + + def test_dashboard_from_json(self): + """Test Dashboard from_json creation""" + dashboard_json = '{"title": "From JSON"}' + dashboard = Dashboard.from_json(dashboard_json) + + assert isinstance(dashboard, Dashboard) + assert dashboard.title == "From JSON" + + def test_dashboard_to_str(self): + """Test Dashboard to_str representation""" + dashboard = Dashboard(title="Str Dashboard") + dashboard_str = dashboard.to_str() + + assert isinstance(dashboard_str, str) + assert "Str Dashboard" in dashboard_str + + def test_dashboard_none_values_excluded(self): + """Test that None values are excluded from dict""" + dashboard = Dashboard(title="None Dashboard") + dashboard_dict = dashboard.to_dict() + + assert "title" in dashboard_dict + assert "description" not in dashboard_dict + + def test_dashboard_from_dict_none(self): + """Test Dashboard.from_dict with None returns None""" + dashboard = Dashboard.from_dict(None) + assert dashboard is None + + def test_dashboard_from_dict_non_dict(self): + """Test from_dict with a non-dict object""" + dash_obj = Dashboard(title="test_obj") + new_dash = Dashboard.from_dict(dash_obj) + assert new_dash.title == "test_obj" + def test_dashboard_roundtrip_json(self): + """Test Dashboard can be serialized and deserialized""" + original = Dashboard(title="Roundtrip", user_id=uuid4()) + json_str = original.to_json() + restored = Dashboard.from_json(json_str) -if __name__ == "__main__": - unittest.main() + assert restored.title == original.title + assert restored.user_id == original.user_id diff --git a/test/test_dashboard_list.py b/test/test_dashboard_list.py index 8220077..be634b4 100644 --- a/test/test_dashboard_list.py +++ b/test/test_dashboard_list.py @@ -9,45 +9,96 @@ Do not edit the class manually. """ -import unittest +import json +from uuid import uuid4 +from ibutsu_client.models.dashboard import Dashboard from ibutsu_client.models.dashboard_list import DashboardList +from ibutsu_client.models.pagination import Pagination -class TestDashboardList(unittest.TestCase): - """DashboardList unit test stubs""" +class TestDashboardList: + """DashboardList model tests""" - def setUp(self): - pass + def test_creation_empty(self): + model = DashboardList() + assert model.dashboards is None + assert model.pagination is None + + def test_creation_full(self): + item = Dashboard(title="d1") + pagination = Pagination(page=1) + model = DashboardList(dashboards=[item], pagination=pagination) + assert len(model.dashboards) == 1 + assert model.pagination.page == 1 + + def test_to_dict(self): + item = Dashboard(title="d1") + model = DashboardList(dashboards=[item]) + data = model.to_dict() + assert "dashboards" in data + assert len(data["dashboards"]) == 1 + assert data["dashboards"][0]["title"] == "d1" + + def test_to_dict_with_pagination(self): + item = Dashboard(title="d1") + pagination = Pagination(page=1) + model = DashboardList(dashboards=[item], pagination=pagination) + data = model.to_dict() + assert "pagination" in data + assert data["pagination"]["page"] == 1 + + def test_to_json(self): + item = Dashboard(title="d1") + model = DashboardList(dashboards=[item]) + json_str = model.to_json() + data = json.loads(json_str) + assert len(data["dashboards"]) == 1 + + def test_from_dict(self): + item_dict = {"title": "d1"} + data = {"dashboards": [item_dict], "pagination": {"page": 2}} + model = DashboardList.from_dict(data) + assert len(model.dashboards) == 1 + assert model.pagination.page == 2 - def tearDown(self): - pass + def test_from_json(self): + json_str = '{"dashboards": [{"title": "d1"}], "pagination": {"page": 3}}' + model = DashboardList.from_json(json_str) + assert len(model.dashboards) == 1 - def make_instance(self, include_optional) -> DashboardList: - """Test DashboardList - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `DashboardList` - """ + def test_multiple_items(self): + i1 = Dashboard(title="d1") + i2 = Dashboard(title="d2") + model = DashboardList(dashboards=[i1, i2]) + data = model.to_dict() + assert len(data["dashboards"]) == 2 + + def test_roundtrip_json(self): + item = Dashboard(title="d1", id=uuid4()) + original = DashboardList(dashboards=[item]) + json_str = original.to_json() + restored = DashboardList.from_json(json_str) + assert len(restored.dashboards) == 1 + assert restored.dashboards[0].id == original.dashboards[0].id + + def test_to_str(self): model = DashboardList() - if include_optional: - return DashboardList( - dashboards = [ - {"id":"62faa4ce-d264-46c2-813e-579949c8ab9b","title":"My Dashboard","description":"A dashboard for me","filters":"","project_id":"44941c55-9736-42f6-acce-ca3c4739d0f3","user_id":"90be2a4a-1a4d-4779-b40f-f08ccd7101d5"} - ], - pagination = {"page":2,"pageSize":25,"totalPages":10,"totalItems":243} - ) - else: - return DashboardList( - ) - """ - - def testDashboardList(self): - """Test DashboardList""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) - - -if __name__ == "__main__": - unittest.main() + s = model.to_str() + assert isinstance(s, str) + + def test_from_dict_none(self): + model = DashboardList.from_dict(None) + assert model is None + + def test_from_dict_non_dict(self): + item = Dashboard(title="d1") + orig = DashboardList(dashboards=[item]) + model = DashboardList.from_dict(orig) + assert len(model.dashboards) == 1 + + def test_list_none_values_excluded(self): + model = DashboardList(dashboards=[]) + data = model.to_dict() + assert "dashboards" in data + assert "pagination" not in data diff --git a/test/test_group.py b/test/test_group.py index ba30792..c085e91 100644 --- a/test/test_group.py +++ b/test/test_group.py @@ -9,43 +9,95 @@ Do not edit the class manually. """ -import unittest +import json +from uuid import uuid4 from ibutsu_client.models.group import Group -class TestGroup(unittest.TestCase): - """Group unit test stubs""" - - def setUp(self): - pass - - def tearDown(self): - pass - - def make_instance(self, include_optional) -> Group: - """Test Group - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `Group` - """ - model = Group() - if include_optional: - return Group( - id = 'a16ad60e-bf23-4195-99dc-594858ad3e5e', - name = 'Group A' - ) - else: - return Group( - ) - """ - - def testGroup(self): - """Test Group""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) - - -if __name__ == "__main__": - unittest.main() +class TestGroup: + """Group model tests""" + + def test_group_creation_empty(self): + """Test Group creation with no parameters""" + group = Group() + assert group.id is None + assert group.name is None + + def test_group_creation_full(self): + """Test Group creation with all parameters""" + group_id = uuid4() + + group = Group(id=group_id, name="My Group") + + assert group.id == group_id + assert group.name == "My Group" + + def test_group_to_dict(self): + """Test Group to_dict conversion""" + group = Group(name="Dict Group") + group_dict = group.to_dict() + + assert isinstance(group_dict, dict) + assert group_dict["name"] == "Dict Group" + + def test_group_to_json(self): + """Test Group to_json conversion""" + group = Group(name="JSON Group") + group_json = group.to_json() + + assert isinstance(group_json, str) + parsed = json.loads(group_json) + assert parsed["name"] == "JSON Group" + + def test_group_from_dict(self): + """Test Group from_dict creation""" + group_dict = {"name": "From Dict"} + group = Group.from_dict(group_dict) + + assert isinstance(group, Group) + assert group.name == "From Dict" + + def test_group_from_json(self): + """Test Group from_json creation""" + group_json = '{"name": "From JSON"}' + group = Group.from_json(group_json) + + assert isinstance(group, Group) + assert group.name == "From JSON" + + def test_group_to_str(self): + """Test Group to_str representation""" + group = Group(name="Str Group") + group_str = group.to_str() + + assert isinstance(group_str, str) + assert "Str Group" in group_str + + def test_group_none_values_excluded(self): + """Test that None values are excluded from dict""" + group = Group(name="None Group") + group_dict = group.to_dict() + + assert "name" in group_dict + assert "id" not in group_dict + + def test_group_from_dict_none(self): + """Test Group.from_dict with None returns None""" + group = Group.from_dict(None) + assert group is None + + def test_group_from_dict_non_dict(self): + """Test from_dict with a non-dict object""" + group_obj = Group(name="test_obj") + new_group = Group.from_dict(group_obj) + assert new_group.name == "test_obj" + + def test_group_roundtrip_json(self): + """Test Group can be serialized and deserialized""" + original = Group(name="Roundtrip", id=uuid4()) + json_str = original.to_json() + restored = Group.from_json(json_str) + + assert restored.name == original.name + assert restored.id == original.id diff --git a/test/test_group_list.py b/test/test_group_list.py index 3fb19cf..e7fd209 100644 --- a/test/test_group_list.py +++ b/test/test_group_list.py @@ -9,45 +9,95 @@ Do not edit the class manually. """ -import unittest +import json +from uuid import uuid4 +from ibutsu_client.models.group import Group from ibutsu_client.models.group_list import GroupList +from ibutsu_client.models.pagination import Pagination -class TestGroupList(unittest.TestCase): - """GroupList unit test stubs""" +class TestGroupList: + """GroupList model tests""" - def setUp(self): - pass + def test_creation_empty(self): + model = GroupList() + assert model.groups is None + assert model.pagination is None + + def test_creation_full(self): + item = Group(name="g1") + pagination = Pagination(page=1) + model = GroupList(groups=[item], pagination=pagination) + assert len(model.groups) == 1 + assert model.pagination.page == 1 + + def test_to_dict(self): + item = Group(name="g1") + model = GroupList(groups=[item]) + data = model.to_dict() + assert "groups" in data + assert len(data["groups"]) == 1 + + def test_to_dict_with_pagination(self): + item = Group(name="g1") + pagination = Pagination(page=1) + model = GroupList(groups=[item], pagination=pagination) + data = model.to_dict() + assert "pagination" in data + assert data["pagination"]["page"] == 1 + + def test_to_json(self): + item = Group(name="g1") + model = GroupList(groups=[item]) + json_str = model.to_json() + data = json.loads(json_str) + assert len(data["groups"]) == 1 + + def test_from_dict(self): + item_dict = {"name": "g1"} + data = {"groups": [item_dict], "pagination": {"page": 2}} + model = GroupList.from_dict(data) + assert len(model.groups) == 1 + assert model.pagination.page == 2 - def tearDown(self): - pass + def test_from_json(self): + json_str = '{"groups": [{"name": "g1"}], "pagination": {"page": 3}}' + model = GroupList.from_json(json_str) + assert len(model.groups) == 1 - def make_instance(self, include_optional) -> GroupList: - """Test GroupList - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `GroupList` - """ + def test_multiple_items(self): + i1 = Group(name="g1") + i2 = Group(name="g2") + model = GroupList(groups=[i1, i2]) + data = model.to_dict() + assert len(data["groups"]) == 2 + + def test_roundtrip_json(self): + item = Group(name="g1", id=uuid4()) + original = GroupList(groups=[item]) + json_str = original.to_json() + restored = GroupList.from_json(json_str) + assert len(restored.groups) == 1 + assert restored.groups[0].id == original.groups[0].id + + def test_to_str(self): model = GroupList() - if include_optional: - return GroupList( - groups = [ - {"id":"a16ad60e-bf23-4195-99dc-594858ad3e5e","name":"Example group"} - ], - pagination = {"page":2,"pageSize":25,"totalPages":10,"totalItems":243} - ) - else: - return GroupList( - ) - """ - - def testGroupList(self): - """Test GroupList""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) - - -if __name__ == "__main__": - unittest.main() + s = model.to_str() + assert isinstance(s, str) + + def test_from_dict_none(self): + model = GroupList.from_dict(None) + assert model is None + + def test_from_dict_non_dict(self): + item = Group(name="g1") + orig = GroupList(groups=[item]) + model = GroupList.from_dict(orig) + assert len(model.groups) == 1 + + def test_list_none_values_excluded(self): + model = GroupList(groups=[]) + data = model.to_dict() + assert "groups" in data + assert "pagination" not in data diff --git a/test/test_health_info.py b/test/test_health_info.py index 542ff66..9ed9773 100644 --- a/test/test_health_info.py +++ b/test/test_health_info.py @@ -9,44 +9,59 @@ Do not edit the class manually. """ -import unittest +import json from ibutsu_client.models.health_info import HealthInfo -class TestHealthInfo(unittest.TestCase): - """HealthInfo unit test stubs""" +class TestHealthInfo: + """HealthInfo model tests""" - def setUp(self): - pass + def test_creation_empty(self): + model = HealthInfo() + assert model.frontend is None + assert model.backend is None - def tearDown(self): - pass + def test_creation_full(self): + model = HealthInfo(frontend="up", backend="down") + assert model.frontend == "up" + assert model.backend == "down" - def make_instance(self, include_optional) -> HealthInfo: - """Test HealthInfo - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `HealthInfo` - """ - model = HealthInfo() - if include_optional: - return HealthInfo( - frontend = 'http://localhost:3000', - backend = 'http://localhost:8080', - api_ui = 'http://localhost:8080/api/ui/' - ) - else: - return HealthInfo( - ) - """ - - def testHealthInfo(self): - """Test HealthInfo""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) - - -if __name__ == "__main__": - unittest.main() + def test_to_dict(self): + model = HealthInfo(frontend="up") + d = model.to_dict() + assert d["frontend"] == "up" + + def test_to_json(self): + model = HealthInfo(frontend="up") + j = model.to_json() + data = json.loads(j) + assert data["frontend"] == "up" + + def test_from_dict(self): + d = {"frontend": "up"} + model = HealthInfo.from_dict(d) + assert model.frontend == "up" + + def test_from_json(self): + j = '{"frontend": "up"}' + model = HealthInfo.from_json(j) + assert model.frontend == "up" + + def test_to_str(self): + model = HealthInfo(frontend="up") + assert "up" in model.to_str() + + def test_from_dict_none(self): + assert HealthInfo.from_dict(None) is None + + def test_from_dict_non_dict(self): + orig = HealthInfo(frontend="up") + model = HealthInfo.from_dict(orig) + assert model.frontend == "up" + + def test_none_values_excluded(self): + model = HealthInfo(frontend="up") + d = model.to_dict() + assert "frontend" in d + assert "backend" not in d diff --git a/test/test_login_config.py b/test/test_login_config.py index b8923bc..3e8b4a6 100644 --- a/test/test_login_config.py +++ b/test/test_login_config.py @@ -9,44 +9,56 @@ Do not edit the class manually. """ -import unittest +import json from ibutsu_client.models.login_config import LoginConfig -class TestLoginConfig(unittest.TestCase): - """LoginConfig unit test stubs""" +class TestLoginConfig: + """LoginConfig model tests""" - def setUp(self): - pass + def test_creation_empty(self): + model = LoginConfig() + assert model.client_id is None - def tearDown(self): - pass + def test_creation_full(self): + model = LoginConfig(client_id="id") + assert model.client_id == "id" - def make_instance(self, include_optional) -> LoginConfig: - """Test LoginConfig - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `LoginConfig` - """ - model = LoginConfig() - if include_optional: - return LoginConfig( - client_id = 'ff542f48922114019fc5befd0fa0e107b494c365fa4f8af09f3fcb2eb6dc0f77', - redirect_uri = '/api/login/oauth', - scope = 'read:user' - ) - else: - return LoginConfig( - ) - """ - - def testLoginConfig(self): - """Test LoginConfig""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) - - -if __name__ == "__main__": - unittest.main() + def test_to_dict(self): + model = LoginConfig(client_id="id") + d = model.to_dict() + assert d["client_id"] == "id" + + def test_to_json(self): + model = LoginConfig(client_id="id") + j = model.to_json() + data = json.loads(j) + assert data["client_id"] == "id" + + def test_from_dict(self): + d = {"client_id": "id"} + model = LoginConfig.from_dict(d) + assert model.client_id == "id" + + def test_from_json(self): + j = '{"client_id": "id"}' + model = LoginConfig.from_json(j) + assert model.client_id == "id" + + def test_to_str(self): + model = LoginConfig(client_id="id") + assert "id" in model.to_str() + + def test_from_dict_none(self): + assert LoginConfig.from_dict(None) is None + + def test_from_dict_non_dict(self): + orig = LoginConfig(client_id="id") + model = LoginConfig.from_dict(orig) + assert model.client_id == "id" + + def test_none_values_excluded(self): + model = LoginConfig(client_id="id") + d = model.to_dict() + assert "client_id" in d diff --git a/test/test_login_error.py b/test/test_login_error.py index 4f7632c..c656ad2 100644 --- a/test/test_login_error.py +++ b/test/test_login_error.py @@ -9,43 +9,58 @@ Do not edit the class manually. """ -import unittest +import json from ibutsu_client.models.login_error import LoginError -class TestLoginError(unittest.TestCase): - """LoginError unit test stubs""" +class TestLoginError: + """LoginError model tests""" - def setUp(self): - pass + def test_creation_empty(self): + model = LoginError() + assert model.message is None - def tearDown(self): - pass + def test_creation_full(self): + model = LoginError(message="err", code="404") + assert model.message == "err" + assert model.code == "404" - def make_instance(self, include_optional) -> LoginError: - """Test LoginError - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `LoginError` - """ - model = LoginError() - if include_optional: - return LoginError( - code = 'ERR01', - message = 'Username or password was invalid' - ) - else: - return LoginError( - ) - """ - - def testLoginError(self): - """Test LoginError""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) - - -if __name__ == "__main__": - unittest.main() + def test_to_dict(self): + model = LoginError(message="err") + d = model.to_dict() + assert d["message"] == "err" + + def test_to_json(self): + model = LoginError(message="err") + j = model.to_json() + data = json.loads(j) + assert data["message"] == "err" + + def test_from_dict(self): + d = {"message": "err"} + model = LoginError.from_dict(d) + assert model.message == "err" + + def test_from_json(self): + j = '{"message": "err"}' + model = LoginError.from_json(j) + assert model.message == "err" + + def test_to_str(self): + model = LoginError(message="err") + assert "err" in model.to_str() + + def test_from_dict_none(self): + assert LoginError.from_dict(None) is None + + def test_from_dict_non_dict(self): + orig = LoginError(message="err") + model = LoginError.from_dict(orig) + assert model.message == "err" + + def test_none_values_excluded(self): + model = LoginError(message="err") + d = model.to_dict() + assert "message" in d + assert "code" not in d diff --git a/test/test_login_support.py b/test/test_login_support.py index 57fd2fa..c0aea3f 100644 --- a/test/test_login_support.py +++ b/test/test_login_support.py @@ -9,47 +9,58 @@ Do not edit the class manually. """ -import unittest +import json from ibutsu_client.models.login_support import LoginSupport -class TestLoginSupport(unittest.TestCase): - """LoginSupport unit test stubs""" +class TestLoginSupport: + """LoginSupport model tests""" - def setUp(self): - pass + def test_creation_empty(self): + model = LoginSupport() + assert model.user is None - def tearDown(self): - pass + def test_creation_full(self): + model = LoginSupport(user=True, github=False) + assert model.user is True + assert model.github is False - def make_instance(self, include_optional) -> LoginSupport: - """Test LoginSupport - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `LoginSupport` - """ - model = LoginSupport() - if include_optional: - return LoginSupport( - user = True, - keycloak = True, - google = True, - github = True, - facebook = True, - gitlab = True - ) - else: - return LoginSupport( - ) - """ - - def testLoginSupport(self): - """Test LoginSupport""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) - - -if __name__ == "__main__": - unittest.main() + def test_to_dict(self): + model = LoginSupport(user=True) + d = model.to_dict() + assert d["user"] is True + + def test_to_json(self): + model = LoginSupport(user=True) + j = model.to_json() + data = json.loads(j) + assert data["user"] is True + + def test_from_dict(self): + d = {"user": True} + model = LoginSupport.from_dict(d) + assert model.user is True + + def test_from_json(self): + j = '{"user": true}' + model = LoginSupport.from_json(j) + assert model.user is True + + def test_to_str(self): + model = LoginSupport(user=True) + assert "user" in model.to_str() + + def test_from_dict_none(self): + assert LoginSupport.from_dict(None) is None + + def test_from_dict_non_dict(self): + orig = LoginSupport(user=True) + model = LoginSupport.from_dict(orig) + assert model.user is True + + def test_none_values_excluded(self): + model = LoginSupport(user=True) + d = model.to_dict() + assert "user" in d + assert "google" not in d diff --git a/test/test_login_token.py b/test/test_login_token.py index 8946232..5cbe9b7 100644 --- a/test/test_login_token.py +++ b/test/test_login_token.py @@ -9,42 +9,56 @@ Do not edit the class manually. """ -import unittest +import json from ibutsu_client.models.login_token import LoginToken -class TestLoginToken(unittest.TestCase): - """LoginToken unit test stubs""" +class TestLoginToken: + """LoginToken model tests""" - def setUp(self): - pass + def test_creation_empty(self): + model = LoginToken() + assert model.token is None - def tearDown(self): - pass + def test_creation_full(self): + model = LoginToken(token="abc") + assert model.token == "abc" - def make_instance(self, include_optional) -> LoginToken: - """Test LoginToken - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `LoginToken` - """ - model = LoginToken() - if include_optional: - return LoginToken( - token = 'eyJhbGciOiJIUzI1NiJ9.SGVsbG8sIHdvcmxkIQ.onO9Ihudz3WkiauDO2Uhyuz0Y18UASXlSc1eS0NkWyA' - ) - else: - return LoginToken( - ) - """ - - def testLoginToken(self): - """Test LoginToken""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) - - -if __name__ == "__main__": - unittest.main() + def test_to_dict(self): + model = LoginToken(token="abc") + d = model.to_dict() + assert d["token"] == "abc" + + def test_to_json(self): + model = LoginToken(token="abc") + j = model.to_json() + data = json.loads(j) + assert data["token"] == "abc" + + def test_from_dict(self): + d = {"token": "abc"} + model = LoginToken.from_dict(d) + assert model.token == "abc" + + def test_from_json(self): + j = '{"token": "abc"}' + model = LoginToken.from_json(j) + assert model.token == "abc" + + def test_to_str(self): + model = LoginToken(token="abc") + assert "abc" in model.to_str() + + def test_from_dict_none(self): + assert LoginToken.from_dict(None) is None + + def test_from_dict_non_dict(self): + orig = LoginToken(token="abc") + model = LoginToken.from_dict(orig) + assert model.token == "abc" + + def test_none_values_excluded(self): + model = LoginToken(token="abc") + d = model.to_dict() + assert "token" in d diff --git a/test/test_model_import.py b/test/test_model_import.py index 5faf76a..2fd606f 100644 --- a/test/test_model_import.py +++ b/test/test_model_import.py @@ -9,46 +9,59 @@ Do not edit the class manually. """ -import unittest +import json from ibutsu_client.models.model_import import ModelImport -class TestModelImport(unittest.TestCase): - """ModelImport unit test stubs""" +class TestModelImport: + """ModelImport model tests""" - def setUp(self): - pass + def test_creation_empty(self): + model = ModelImport() + assert model.format is None + assert model.filename is None - def tearDown(self): - pass + def test_creation_full(self): + model = ModelImport(format="xml", filename="f.xml") + assert model.format == "xml" + assert model.filename == "f.xml" - def make_instance(self, include_optional) -> ModelImport: - """Test ModelImport - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `ModelImport` - """ - model = ModelImport() - if include_optional: - return ModelImport( - id = 'e56740ba-0dbb-43ac-a556-364eefbf1f62', - status = 'done', - filename = 'test-run.xml', - format = 'JUnit', - run_id = '64c2ab9e-cd64-4815-bf73-83b00c2e650f' - ) - else: - return ModelImport( - ) - """ - - def testModelImport(self): - """Test ModelImport""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) - - -if __name__ == "__main__": - unittest.main() + def test_to_dict(self): + model = ModelImport(format="xml") + d = model.to_dict() + assert d["format"] == "xml" + + def test_to_json(self): + model = ModelImport(format="xml") + j = model.to_json() + data = json.loads(j) + assert data["format"] == "xml" + + def test_from_dict(self): + d = {"format": "xml"} + model = ModelImport.from_dict(d) + assert model.format == "xml" + + def test_from_json(self): + j = '{"format": "xml"}' + model = ModelImport.from_json(j) + assert model.format == "xml" + + def test_to_str(self): + model = ModelImport(format="xml") + assert "xml" in model.to_str() + + def test_from_dict_none(self): + assert ModelImport.from_dict(None) is None + + def test_from_dict_non_dict(self): + orig = ModelImport(format="xml") + model = ModelImport.from_dict(orig) + assert model.format == "xml" + + def test_none_values_excluded(self): + model = ModelImport(format="xml") + d = model.to_dict() + assert "format" in d + assert "filename" not in d diff --git a/test/test_pagination.py b/test/test_pagination.py index 74f4541..0abfa6f 100644 --- a/test/test_pagination.py +++ b/test/test_pagination.py @@ -9,45 +9,101 @@ Do not edit the class manually. """ -import unittest +import json from ibutsu_client.models.pagination import Pagination -class TestPagination(unittest.TestCase): - """Pagination unit test stubs""" - - def setUp(self): - pass - - def tearDown(self): - pass - - def make_instance(self, include_optional) -> Pagination: - """Test Pagination - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `Pagination` - """ - model = Pagination() - if include_optional: - return Pagination( - page = 2, - page_size = 25, - total_pages = 10, - total_items = 243 - ) - else: - return Pagination( - ) - """ - - def testPagination(self): - """Test Pagination""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) - - -if __name__ == "__main__": - unittest.main() +class TestPagination: + """Pagination model tests""" + + def test_pagination_creation_empty(self): + """Test Pagination creation with no parameters""" + pagination = Pagination() + assert pagination.page is None + assert pagination.page_size is None + + def test_pagination_creation_full(self): + """Test Pagination creation with all parameters""" + pagination = Pagination(page=1, page_size=25, total_pages=10, total_items=243) + + assert pagination.page == 1 + assert pagination.page_size == 25 + assert pagination.total_pages == 10 + assert pagination.total_items == 243 + + def test_pagination_to_dict_aliases(self): + """Test Pagination to_dict conversion uses aliases""" + pagination = Pagination(page=1, page_size=10) + pagination_dict = pagination.to_dict() + + assert isinstance(pagination_dict, dict) + assert "page" in pagination_dict + assert "pageSize" in pagination_dict + assert "page_size" not in pagination_dict + assert pagination_dict["pageSize"] == 10 + + def test_pagination_to_json(self): + """Test Pagination to_json conversion""" + pagination = Pagination(page=2) + pagination_json = pagination.to_json() + + assert isinstance(pagination_json, str) + parsed = json.loads(pagination_json) + assert parsed["page"] == 2 + + def test_pagination_from_dict(self): + """Test Pagination from_dict creation with aliases""" + # Pydantic V2 from_dict/model_validate should handle aliases if populate_by_name is True (it is) + # But input dict usually comes from API response which uses aliases (camelCase) + pagination_dict = {"page": 3, "pageSize": 50, "totalPages": 5, "totalItems": 250} + pagination = Pagination.from_dict(pagination_dict) + + assert isinstance(pagination, Pagination) + assert pagination.page == 3 + assert pagination.page_size == 50 + + def test_pagination_from_json(self): + """Test Pagination from_json creation""" + pagination_json = '{"page": 4, "pageSize": 100}' + pagination = Pagination.from_json(pagination_json) + + assert isinstance(pagination, Pagination) + assert pagination.page == 4 + assert pagination.page_size == 100 + + def test_pagination_to_str(self): + """Test Pagination to_str representation""" + pagination = Pagination(page=5) + pagination_str = pagination.to_str() + + assert isinstance(pagination_str, str) + assert "page" in pagination_str + + def test_pagination_none_values_excluded(self): + """Test that None values are excluded from dict""" + pagination = Pagination(page=6) + pagination_dict = pagination.to_dict() + + assert "page" in pagination_dict + assert "pageSize" not in pagination_dict + + def test_pagination_from_dict_none(self): + """Test Pagination.from_dict with None returns None""" + pagination = Pagination.from_dict(None) + assert pagination is None + + def test_pagination_from_dict_non_dict(self): + """Test from_dict with a non-dict object""" + pag_obj = Pagination(page=7) + new_pag = Pagination.from_dict(pag_obj) + assert new_pag.page == 7 + + def test_pagination_roundtrip_json(self): + """Test Pagination can be serialized and deserialized""" + original = Pagination(page=8, page_size=20) + json_str = original.to_json() + restored = Pagination.from_json(json_str) + + assert restored.page == original.page + assert restored.page_size == original.page_size diff --git a/test/test_project.py b/test/test_project.py index c24cc42..1e80533 100644 --- a/test/test_project.py +++ b/test/test_project.py @@ -9,46 +9,118 @@ Do not edit the class manually. """ -import unittest +import json +from uuid import uuid4 from ibutsu_client.models.project import Project -class TestProject(unittest.TestCase): - """Project unit test stubs""" - - def setUp(self): - pass - - def tearDown(self): - pass - - def make_instance(self, include_optional) -> Project: - """Test Project - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `Project` - """ - model = Project() - if include_optional: - return Project( - id = '44941c55-9736-42f6-acce-ca3c4739d0f3', - name = 'my-project', - title = 'My project', - owner_id = '6b8b01ad-a17e-4ca1-8df5-fadb41439567', - group_id = 'a16ad60e-bf23-4195-99dc-594858ad3e5e' - ) - else: - return Project( +class TestProject: + """Project model tests""" + + def test_project_creation_empty(self): + """Test Project creation with no parameters""" + project = Project() + assert project.id is None + assert project.name is None + + def test_project_creation_full(self): + """Test Project creation with all parameters""" + project_id = uuid4() + owner_id = uuid4() + group_id = uuid4() + + project = Project( + id=project_id, + name="my-project", + title="My Project", + owner_id=owner_id, + group_id=group_id, ) - """ - def testProject(self): - """Test Project""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) + assert project.id == project_id + assert project.name == "my-project" + assert project.title == "My Project" + assert project.owner_id == owner_id + assert project.group_id == group_id + + def test_project_to_dict(self): + """Test Project to_dict conversion""" + project = Project(name="dict_project", title="Dict Project") + project_dict = project.to_dict() + + assert isinstance(project_dict, dict) + assert project_dict["name"] == "dict_project" + assert project_dict["title"] == "Dict Project" + + def test_project_to_json(self): + """Test Project to_json conversion""" + project = Project(name="json_project") + project_json = project.to_json() + + assert isinstance(project_json, str) + parsed = json.loads(project_json) + assert parsed["name"] == "json_project" + + def test_project_from_dict(self): + """Test Project from_dict creation""" + project_dict = {"name": "from_dict", "title": "From Dict"} + project = Project.from_dict(project_dict) + + assert isinstance(project, Project) + assert project.name == "from_dict" + assert project.title == "From Dict" + + def test_project_from_json(self): + """Test Project from_json creation""" + project_json = '{"name": "from_json"}' + project = Project.from_json(project_json) + + assert isinstance(project, Project) + assert project.name == "from_json" + + def test_project_to_str(self): + """Test Project to_str representation""" + project = Project(name="str_project") + project_str = project.to_str() + + assert isinstance(project_str, str) + assert "str_project" in project_str + + def test_project_none_values_excluded(self): + """Test that None values are excluded from dict""" + project = Project(name="none_project") + project_dict = project.to_dict() + + assert "name" in project_dict + assert "title" not in project_dict + + def test_project_explicit_nones(self): + """Test explicit None values are preserved in to_dict if set""" + project = Project(owner_id=None, group_id=None) + project_dict = project.to_dict() + + assert "owner_id" in project_dict + assert project_dict["owner_id"] is None + assert "group_id" in project_dict + assert project_dict["group_id"] is None + + def test_project_from_dict_none(self): + """Test Project.from_dict with None returns None""" + project = Project.from_dict(None) + assert project is None + + def test_project_from_dict_non_dict(self): + """Test from_dict with a non-dict object""" + proj_obj = Project(name="test_obj") + new_proj = Project.from_dict(proj_obj) + assert new_proj.name == "test_obj" + def test_project_roundtrip_json(self): + """Test Project can be serialized and deserialized""" + original = Project(name="roundtrip", title="Roundtrip") + json_str = original.to_json() + restored = Project.from_json(json_str) -if __name__ == "__main__": - unittest.main() + assert restored.name == original.name + assert restored.title == original.title diff --git a/test/test_project_list.py b/test/test_project_list.py index 6b4b657..73d151f 100644 --- a/test/test_project_list.py +++ b/test/test_project_list.py @@ -9,45 +9,95 @@ Do not edit the class manually. """ -import unittest +import json +from uuid import uuid4 +from ibutsu_client.models.pagination import Pagination +from ibutsu_client.models.project import Project from ibutsu_client.models.project_list import ProjectList -class TestProjectList(unittest.TestCase): - """ProjectList unit test stubs""" +class TestProjectList: + """ProjectList model tests""" - def setUp(self): - pass + def test_creation_empty(self): + model = ProjectList() + assert model.projects is None + assert model.pagination is None + + def test_creation_full(self): + item = Project(name="p1") + pagination = Pagination(page=1) + model = ProjectList(projects=[item], pagination=pagination) + assert len(model.projects) == 1 + assert model.pagination.page == 1 + + def test_to_dict(self): + item = Project(name="p1") + model = ProjectList(projects=[item]) + data = model.to_dict() + assert "projects" in data + assert len(data["projects"]) == 1 + + def test_to_dict_with_pagination(self): + item = Project(name="p1") + pagination = Pagination(page=1) + model = ProjectList(projects=[item], pagination=pagination) + data = model.to_dict() + assert "pagination" in data + assert data["pagination"]["page"] == 1 + + def test_to_json(self): + item = Project(name="p1") + model = ProjectList(projects=[item]) + json_str = model.to_json() + data = json.loads(json_str) + assert len(data["projects"]) == 1 + + def test_from_dict(self): + item_dict = {"name": "p1"} + data = {"projects": [item_dict], "pagination": {"page": 2}} + model = ProjectList.from_dict(data) + assert len(model.projects) == 1 + assert model.pagination.page == 2 - def tearDown(self): - pass + def test_from_json(self): + json_str = '{"projects": [{"name": "p1"}], "pagination": {"page": 3}}' + model = ProjectList.from_json(json_str) + assert len(model.projects) == 1 - def make_instance(self, include_optional) -> ProjectList: - """Test ProjectList - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `ProjectList` - """ + def test_multiple_items(self): + i1 = Project(name="p1") + i2 = Project(name="p2") + model = ProjectList(projects=[i1, i2]) + data = model.to_dict() + assert len(data["projects"]) == 2 + + def test_roundtrip_json(self): + item = Project(name="p1", id=uuid4()) + original = ProjectList(projects=[item]) + json_str = original.to_json() + restored = ProjectList.from_json(json_str) + assert len(restored.projects) == 1 + assert restored.projects[0].id == original.projects[0].id + + def test_to_str(self): model = ProjectList() - if include_optional: - return ProjectList( - projects = [ - {"id":"44941c55-9736-42f6-acce-ca3c4739d0f3","name":"my-project","title":"My Project","owner_id":"6b8b01ad-a17e-4ca1-8df5-fadb41439567","group_id":"a16ad60e-bf23-4195-99dc-594858ad3e5e"} - ], - pagination = {"page":2,"pageSize":25,"totalPages":10,"totalItems":243} - ) - else: - return ProjectList( - ) - """ - - def testProjectList(self): - """Test ProjectList""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) - - -if __name__ == "__main__": - unittest.main() + s = model.to_str() + assert isinstance(s, str) + + def test_from_dict_none(self): + model = ProjectList.from_dict(None) + assert model is None + + def test_from_dict_non_dict(self): + item = Project(name="p1") + orig = ProjectList(projects=[item]) + model = ProjectList.from_dict(orig) + assert len(model.projects) == 1 + + def test_list_none_values_excluded(self): + model = ProjectList(projects=[]) + data = model.to_dict() + assert "projects" in data + assert "pagination" not in data diff --git a/test/test_result.py b/test/test_result.py index 610dded..7fe1ae7 100644 --- a/test/test_result.py +++ b/test/test_result.py @@ -9,53 +9,169 @@ Do not edit the class manually. """ -import unittest +import json +from uuid import uuid4 + +import pytest from ibutsu_client.models.result import Result -class TestResult(unittest.TestCase): - """Result unit test stubs""" - - def setUp(self): - pass - - def tearDown(self): - pass - - def make_instance(self, include_optional) -> Result: - """Test Result - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `Result` - """ - model = Result() - if include_optional: - return Result( - id = 'a16ad60e-bf23-4195-99dc-594858ad3e5e', - test_id = 'test_click_on_button', - start_time = '', - duration = 1.337, - result = 'passed', - component = 'login', - env = 'qa', - run_id = '64c2ab9e-cd64-4815-bf73-83b00c2e650f', - project_id = '44941c55-9736-42f6-acce-ca3c4739d0f3', - metadata = {"jenkins":{"job_name":"test-jenkins-job","build_number":123},"project":"insights-qe","commit_hash":"F4BA3E12"}, - params = {"provider":"vmware","ip_stack":"ipv4"}, - source = '' - ) - else: - return Result( +class TestResult: + """Result model tests""" + + def test_result_creation_empty(self): + """Test Result creation with no parameters""" + result = Result() + assert result.id is None + assert result.test_id is None + assert result.result is None + + def test_result_creation_with_required(self): + """Test Result creation with required params only (none are strictly required in init)""" + result = Result(test_id="test_case_1") + assert result.test_id == "test_case_1" + + def test_result_creation_full(self): + """Test Result creation with all parameters""" + run_id = uuid4() + project_id = uuid4() + result_id = uuid4() + + result = Result( + id=result_id, + test_id="test_full_create", + start_time="2023-01-01T12:00:00Z", + duration=10.5, + result="passed", + component="backend", + env="ci", + run_id=run_id, + project_id=project_id, + metadata={"key": "value"}, + params={"param1": "value1"}, + source="jenkins", ) - """ - def testResult(self): - """Test Result""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) + assert result.id == result_id + assert result.test_id == "test_full_create" + assert result.duration == 10.5 + assert result.result == "passed" + assert result.metadata == {"key": "value"} + + def test_result_validate_enum_valid(self): + """Test valid enum values for result field""" + valid_results = [ + "passed", + "failed", + "error", + "skipped", + "xpassed", + "xfailed", + "manual", + "blocked", + ] + for res in valid_results: + r = Result(result=res) + assert r.result == res + + def test_result_validate_enum_invalid(self): + """Test invalid enum values for result field raises ValueError""" + with pytest.raises(ValueError, match="must be one of enum values"): + Result(result="invalid_status") + + def test_result_to_dict(self): + """Test Result to_dict conversion""" + result = Result(test_id="test_dict", result="passed") + result_dict = result.to_dict() + + assert isinstance(result_dict, dict) + assert result_dict["test_id"] == "test_dict" + assert result_dict["result"] == "passed" + + def test_result_to_json(self): + """Test Result to_json conversion""" + result = Result(test_id="test_json", result="failed") + result_json = result.to_json() + + assert isinstance(result_json, str) + parsed = json.loads(result_json) + assert parsed["test_id"] == "test_json" + assert parsed["result"] == "failed" + + def test_result_from_dict(self): + """Test Result from_dict creation""" + result_dict = {"test_id": "test_from_dict", "result": "error"} + result = Result.from_dict(result_dict) + + assert isinstance(result, Result) + assert result.test_id == "test_from_dict" + assert result.result == "error" + + def test_result_from_json(self): + """Test Result from_json creation""" + result_json = '{"test_id": "test_from_json", "result": "skipped"}' + result = Result.from_json(result_json) + + assert isinstance(result, Result) + assert result.test_id == "test_from_json" + assert result.result == "skipped" + + def test_result_to_str(self): + """Test Result to_str representation""" + result = Result(test_id="test_str") + result_str = result.to_str() + + assert isinstance(result_str, str) + assert "test_str" in result_str + + def test_result_none_values_excluded(self): + """Test that None values are excluded from dict""" + result = Result(test_id="test_none") + result_dict = result.to_dict() + + assert "test_id" in result_dict + assert "duration" not in result_dict + + def test_result_from_dict_none(self): + """Test Result.from_dict with None returns None""" + result = Result.from_dict(None) + assert result is None + + def test_result_none_result(self): + """Test result field can be explicitly None""" + result = Result(result=None) + assert result.result is None + + def test_result_explicit_nones(self): + """Test explicit None values are preserved in to_dict if set""" + # By default unset optional fields are not in model_fields_set and excluded by exclude_none=True + # But if we explicitly set them to None, the custom to_dict logic should include them + result = Result(component=None, env=None, run_id=None, project_id=None) + result_dict = result.to_dict() + + assert "component" in result_dict + assert result_dict["component"] is None + assert "env" in result_dict + assert result_dict["env"] is None + assert "run_id" in result_dict + assert result_dict["run_id"] is None + assert "project_id" in result_dict + assert result_dict["project_id"] is None + + def test_result_from_dict_non_dict(self): + """Test from_dict with a non-dict object (e.g. another model instance or compatible object)""" + # This hits the path where obj is not a dict + # model_validate can accept the object itself if it's compatible + res_obj = Result(test_id="test_obj") + new_res = Result.from_dict(res_obj) + assert new_res.test_id == "test_obj" + def test_result_roundtrip_json(self): + """Test Result can be serialized and deserialized""" + original = Result(test_id="test_roundtrip", result="passed") + json_str = original.to_json() + restored = Result.from_json(json_str) -if __name__ == "__main__": - unittest.main() + assert restored.test_id == original.test_id + assert restored.result == original.result diff --git a/test/test_result_list.py b/test/test_result_list.py index 3082af3..1b4afa0 100644 --- a/test/test_result_list.py +++ b/test/test_result_list.py @@ -9,45 +9,95 @@ Do not edit the class manually. """ -import unittest +import json +from uuid import uuid4 +from ibutsu_client.models.pagination import Pagination +from ibutsu_client.models.result import Result from ibutsu_client.models.result_list import ResultList -class TestResultList(unittest.TestCase): - """ResultList unit test stubs""" +class TestResultList: + """ResultList model tests""" - def setUp(self): - pass + def test_creation_empty(self): + model = ResultList() + assert model.results is None + assert model.pagination is None + + def test_creation_full(self): + item = Result(test_id="t1") + pagination = Pagination(page=1) + model = ResultList(results=[item], pagination=pagination) + assert len(model.results) == 1 + assert model.pagination.page == 1 + + def test_to_dict(self): + item = Result(test_id="t1") + model = ResultList(results=[item]) + data = model.to_dict() + assert "results" in data + assert len(data["results"]) == 1 + + def test_to_dict_with_pagination(self): + item = Result(test_id="t1") + pagination = Pagination(page=1) + model = ResultList(results=[item], pagination=pagination) + data = model.to_dict() + assert "pagination" in data + assert data["pagination"]["page"] == 1 + + def test_to_json(self): + item = Result(test_id="t1") + model = ResultList(results=[item]) + json_str = model.to_json() + data = json.loads(json_str) + assert len(data["results"]) == 1 + + def test_from_dict(self): + item_dict = {"test_id": "t1"} + data = {"results": [item_dict], "pagination": {"page": 2}} + model = ResultList.from_dict(data) + assert len(model.results) == 1 + assert model.pagination.page == 2 - def tearDown(self): - pass + def test_from_json(self): + json_str = '{"results": [{"test_id": "t1"}], "pagination": {"page": 3}}' + model = ResultList.from_json(json_str) + assert len(model.results) == 1 - def make_instance(self, include_optional) -> ResultList: - """Test ResultList - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `ResultList` - """ + def test_multiple_items(self): + i1 = Result(test_id="t1") + i2 = Result(test_id="t2") + model = ResultList(results=[i1, i2]) + data = model.to_dict() + assert len(data["results"]) == 2 + + def test_roundtrip_json(self): + item = Result(test_id="t1", id=uuid4()) + original = ResultList(results=[item]) + json_str = original.to_json() + restored = ResultList.from_json(json_str) + assert len(restored.results) == 1 + assert restored.results[0].id == original.results[0].id + + def test_to_str(self): model = ResultList() - if include_optional: - return ResultList( - results = [ - {"id":"a16ad60e-bf23-4195-99dc-594858ad3e5e","duration":6.027456183070403,"result":"passed","project_id":"9212ac64-348f-4c1c-90f7-fd0a45bcb47c","component":"login","env":"qa","metadata":{"jenkins":{"build_number":123,"job_name":"test-jenkins-job"},"project":"insights-qe","commit_hash":"F4BA3E12"},"start_time":"2020-05-15T16:18:32.014053","source":"source","params":{"provider":"vmware","ip_stack":"ipv4"},"test_id":"test_click_on_button"} - ], - pagination = {"page":2,"pageSize":25,"totalPages":10,"totalItems":243} - ) - else: - return ResultList( - ) - """ - - def testResultList(self): - """Test ResultList""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) - - -if __name__ == "__main__": - unittest.main() + s = model.to_str() + assert isinstance(s, str) + + def test_from_dict_none(self): + model = ResultList.from_dict(None) + assert model is None + + def test_from_dict_non_dict(self): + item = Result(test_id="t1") + orig = ResultList(results=[item]) + model = ResultList.from_dict(orig) + assert len(model.results) == 1 + + def test_list_none_values_excluded(self): + model = ResultList(results=[]) + data = model.to_dict() + assert "results" in data + assert "pagination" not in data diff --git a/test/test_run.py b/test/test_run.py index a3d9c51..bd0c629 100644 --- a/test/test_run.py +++ b/test/test_run.py @@ -9,51 +9,133 @@ Do not edit the class manually. """ -import unittest +import json +from uuid import uuid4 from ibutsu_client.models.run import Run -class TestRun(unittest.TestCase): - """Run unit test stubs""" - - def setUp(self): - pass - - def tearDown(self): - pass - - def make_instance(self, include_optional) -> Run: - """Test Run - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `Run` - """ - model = Run() - if include_optional: - return Run( - id = '64c2ab9e-cd64-4815-bf73-83b00c2e650f', - created = '2020-05-15T16:18:32.014053', - duration = 154.778524555, - source = 'my-tests', - start_time = '2020-05-15T16:18:32.014053', - component = 'login', - env = 'qa', - project_id = '44941c55-9736-42f6-acce-ca3c4739d0f3', - summary = None, - metadata = None - ) - else: - return Run( +class TestRun: + """Run model tests""" + + def test_run_creation_empty(self): + """Test Run creation with no parameters""" + run = Run() + assert run.id is None + assert run.source is None + + def test_run_creation_with_required(self): + """Test Run creation with required params only (none are strictly required in init)""" + run = Run(source="test_source") + assert run.source == "test_source" + + def test_run_creation_full(self): + """Test Run creation with all parameters""" + run_id = uuid4() + project_id = uuid4() + + run = Run( + id=run_id, + created="2023-01-01T12:00:00Z", + duration=100.5, + source="jenkins", + start_time="2023-01-01T11:00:00Z", + component="backend", + env="prod", + project_id=project_id, + summary={"passed": 10, "failed": 0}, + metadata={"key": "value"}, ) - """ - def testRun(self): - """Test Run""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) + assert run.id == run_id + assert run.source == "jenkins" + assert run.duration == 100.5 + assert run.component == "backend" + assert run.metadata == {"key": "value"} + + def test_run_to_dict(self): + """Test Run to_dict conversion""" + run = Run(source="test_dict", component="comp") + run_dict = run.to_dict() + + assert isinstance(run_dict, dict) + assert run_dict["source"] == "test_dict" + assert run_dict["component"] == "comp" + + def test_run_to_json(self): + """Test Run to_json conversion""" + run = Run(source="test_json") + run_json = run.to_json() + + assert isinstance(run_json, str) + parsed = json.loads(run_json) + assert parsed["source"] == "test_json" + + def test_run_from_dict(self): + """Test Run from_dict creation""" + run_dict = {"source": "test_from_dict", "component": "comp_from_dict"} + run = Run.from_dict(run_dict) + + assert isinstance(run, Run) + assert run.source == "test_from_dict" + assert run.component == "comp_from_dict" + + def test_run_from_json(self): + """Test Run from_json creation""" + run_json = '{"source": "test_from_json"}' + run = Run.from_json(run_json) + + assert isinstance(run, Run) + assert run.source == "test_from_json" + + def test_run_to_str(self): + """Test Run to_str representation""" + run = Run(source="test_str") + run_str = run.to_str() + + assert isinstance(run_str, str) + assert "test_str" in run_str + + def test_run_none_values_excluded(self): + """Test that None values are excluded from dict""" + run = Run(source="test_none") + run_dict = run.to_dict() + + assert "source" in run_dict + assert "duration" not in run_dict + + def test_run_explicit_nones(self): + """Test explicit None values are preserved in to_dict if set""" + run = Run(source=None, component=None, env=None, project_id=None, metadata=None) + run_dict = run.to_dict() + + assert "source" in run_dict + assert run_dict["source"] is None + assert "component" in run_dict + assert run_dict["component"] is None + assert "env" in run_dict + assert run_dict["env"] is None + assert "project_id" in run_dict + assert run_dict["project_id"] is None + assert "metadata" in run_dict + assert run_dict["metadata"] is None + + def test_run_from_dict_none(self): + """Test Run.from_dict with None returns None""" + run = Run.from_dict(None) + assert run is None + + def test_run_from_dict_non_dict(self): + """Test from_dict with a non-dict object""" + run_obj = Run(source="test_obj") + new_run = Run.from_dict(run_obj) + assert new_run.source == "test_obj" + def test_run_roundtrip_json(self): + """Test Run can be serialized and deserialized""" + original = Run(source="test_roundtrip", component="comp") + json_str = original.to_json() + restored = Run.from_json(json_str) -if __name__ == "__main__": - unittest.main() + assert restored.source == original.source + assert restored.component == original.component diff --git a/test/test_run_list.py b/test/test_run_list.py index 6bd2c1f..12cd987 100644 --- a/test/test_run_list.py +++ b/test/test_run_list.py @@ -9,45 +9,95 @@ Do not edit the class manually. """ -import unittest +import json +from uuid import uuid4 +from ibutsu_client.models.pagination import Pagination +from ibutsu_client.models.run import Run from ibutsu_client.models.run_list import RunList -class TestRunList(unittest.TestCase): - """RunList unit test stubs""" +class TestRunList: + """RunList model tests""" - def setUp(self): - pass + def test_creation_empty(self): + model = RunList() + assert model.runs is None + assert model.pagination is None + + def test_creation_full(self): + item = Run(source="s1") + pagination = Pagination(page=1) + model = RunList(runs=[item], pagination=pagination) + assert len(model.runs) == 1 + assert model.pagination.page == 1 + + def test_to_dict(self): + item = Run(source="s1") + model = RunList(runs=[item]) + data = model.to_dict() + assert "runs" in data + assert len(data["runs"]) == 1 + + def test_to_dict_with_pagination(self): + item = Run(source="s1") + pagination = Pagination(page=1) + model = RunList(runs=[item], pagination=pagination) + data = model.to_dict() + assert "pagination" in data + assert data["pagination"]["page"] == 1 + + def test_to_json(self): + item = Run(source="s1") + model = RunList(runs=[item]) + json_str = model.to_json() + data = json.loads(json_str) + assert len(data["runs"]) == 1 + + def test_from_dict(self): + item_dict = {"source": "s1"} + data = {"runs": [item_dict], "pagination": {"page": 2}} + model = RunList.from_dict(data) + assert len(model.runs) == 1 + assert model.pagination.page == 2 - def tearDown(self): - pass + def test_from_json(self): + json_str = '{"runs": [{"source": "s1"}], "pagination": {"page": 3}}' + model = RunList.from_json(json_str) + assert len(model.runs) == 1 - def make_instance(self, include_optional) -> RunList: - """Test RunList - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `RunList` - """ + def test_multiple_items(self): + i1 = Run(source="s1") + i2 = Run(source="s2") + model = RunList(runs=[i1, i2]) + data = model.to_dict() + assert len(data["runs"]) == 2 + + def test_roundtrip_json(self): + item = Run(source="s1", id=uuid4()) + original = RunList(runs=[item]) + json_str = original.to_json() + restored = RunList.from_json(json_str) + assert len(restored.runs) == 1 + assert restored.runs[0].id == original.runs[0].id + + def test_to_str(self): model = RunList() - if include_optional: - return RunList( - runs = [ - {"id":"64c2ab9e-cd64-4815-bf73-83b00c2e650f","created":"2020-05-15T16:18:32.014053","duration":540.05433,"source":"my-tests","start_time":"2020-05-15T16:18:32.014053","component":"login","env":"qa","summary":{"errors":1,"failures":3,"skips":0,"xfailures":0,"xpasses":1,"tests":548},"metadata":{"component":"login","env":"qa"}} - ], - pagination = {"page":2,"pageSize":25,"totalPages":10,"totalItems":243} - ) - else: - return RunList( - ) - """ - - def testRunList(self): - """Test RunList""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) - - -if __name__ == "__main__": - unittest.main() + s = model.to_str() + assert isinstance(s, str) + + def test_from_dict_none(self): + model = RunList.from_dict(None) + assert model is None + + def test_from_dict_non_dict(self): + item = Run(source="s1") + orig = RunList(runs=[item]) + model = RunList.from_dict(orig) + assert len(model.runs) == 1 + + def test_list_none_values_excluded(self): + model = RunList(runs=[]) + data = model.to_dict() + assert "runs" in data + assert "pagination" not in data diff --git a/test/test_token.py b/test/test_token.py index 77ea8a0..15d741c 100644 --- a/test/test_token.py +++ b/test/test_token.py @@ -9,50 +9,139 @@ Do not edit the class manually. """ -import unittest +import json +from uuid import uuid4 from ibutsu_client.models.token import Token -class TestToken(unittest.TestCase): - """Token unit test stubs""" - - def setUp(self): - pass - - def tearDown(self): - pass - - def make_instance(self, include_optional) -> Token: - """Test Token - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `Token` - """ - model = Token() - if include_optional: - return Token( - id = 'e2772010-bc06-47ed-8b6b-767ab87427cc', - user_id = '81e2c9d6-1593-4559-af4f-90f6f1f8fa03', - name = 'My user token', - expires = '2038-12-31T23:59:59+0000', - token = '64ad787a-5aa8-48fa-842e-6e3b9631308a' - ) - else: - return Token( - id = 'e2772010-bc06-47ed-8b6b-767ab87427cc', - user_id = '81e2c9d6-1593-4559-af4f-90f6f1f8fa03', - name = 'My user token', - token = '64ad787a-5aa8-48fa-842e-6e3b9631308a', +class TestToken: + """Token model tests""" + + def test_token_creation_empty(self): + """Test Token creation with no parameters - fail as required fields exist""" + # Token requires id, user_id, name, token. + # But Pydantic init usually allows missing if validated later? + # However, defaults are NOT set for these fields in the model definition provided earlier. + # id: UUID = Field(...) + # So init without them might raise ValidationError if strict, + # but Pydantic V2 usually requires them if no default. + # Let's try initializing with required fields. + + def test_token_creation_required(self): + """Test Token creation with required parameters""" + uid = uuid4() + user_id = uuid4() + token = Token(id=uid, user_id=user_id, name="mytoken", token="abc") + + assert token.id == uid + assert token.name == "mytoken" + + def test_token_creation_full(self): + """Test Token creation with all parameters""" + uid = uuid4() + user_id = uuid4() + + token = Token(id=uid, user_id=user_id, name="fulltoken", expires="2023-12-31", token="xyz") + + assert token.id == uid + assert token.expires == "2023-12-31" + + def test_token_to_dict(self): + """Test Token to_dict conversion""" + uid = uuid4() + user_id = uuid4() + token = Token(id=uid, user_id=user_id, name="dicttoken", token="abc") + token_dict = token.to_dict() + + assert isinstance(token_dict, dict) + assert token_dict["name"] == "dicttoken" + + def test_token_to_json(self): + """Test Token to_json conversion""" + uid = uuid4() + user_id = uuid4() + token = Token(id=uid, user_id=user_id, name="jsontoken", token="abc") + token_json = token.to_json() + + assert isinstance(token_json, str) + parsed = json.loads(token_json) + assert parsed["name"] == "jsontoken" + + def test_token_from_dict(self): + """Test Token from_dict creation""" + uid = str(uuid4()) + user_id = str(uuid4()) + token_dict = {"id": uid, "user_id": user_id, "name": "from_dict", "token": "abc"} + token = Token.from_dict(token_dict) + + assert isinstance(token, Token) + assert str(token.id) == uid + assert token.name == "from_dict" + + def test_token_from_json(self): + """Test Token from_json creation""" + uid = str(uuid4()) + user_id = str(uuid4()) + # Construct JSON manually + token_json = json.dumps( + {"id": uid, "user_id": user_id, "name": "from_json", "token": "abc"} ) - """ + token = Token.from_json(token_json) + + assert isinstance(token, Token) + assert token.name == "from_json" + + def test_token_to_str(self): + """Test Token to_str representation""" + uid = uuid4() + user_id = uuid4() + token = Token(id=uid, user_id=user_id, name="strtoken", token="abc") + token_str = token.to_str() + + assert isinstance(token_str, str) + assert "strtoken" in token_str + + def test_token_none_values_excluded(self): + """Test that None values are excluded from dict""" + uid = uuid4() + user_id = uuid4() + token = Token(id=uid, user_id=user_id, name="nonetoken", token="abc") + token_dict = token.to_dict() + + assert "name" in token_dict + assert "expires" not in token_dict + + def test_token_explicit_nones(self): + """Test explicit None values are preserved in to_dict if set""" + uid = uuid4() + user_id = uuid4() + token = Token(id=uid, user_id=user_id, name="explicitnone", token="abc", expires=None) + token_dict = token.to_dict() + + assert "expires" in token_dict + assert token_dict["expires"] is None + + def test_token_from_dict_none(self): + """Test Token.from_dict with None returns None""" + token = Token.from_dict(None) + assert token is None - def testToken(self): - """Test Token""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) + def test_token_from_dict_non_dict(self): + """Test from_dict with a non-dict object""" + uid = uuid4() + user_id = uuid4() + token_obj = Token(id=uid, user_id=user_id, name="test_obj", token="abc") + new_token = Token.from_dict(token_obj) + assert new_token.name == "test_obj" + def test_token_roundtrip_json(self): + """Test Token can be serialized and deserialized""" + uid = uuid4() + user_id = uuid4() + original = Token(id=uid, user_id=user_id, name="roundtrip", token="abc") + json_str = original.to_json() + restored = Token.from_json(json_str) -if __name__ == "__main__": - unittest.main() + assert restored.name == original.name + assert restored.id == original.id diff --git a/test/test_token_list.py b/test/test_token_list.py index b2906d9..c7ec8ae 100644 --- a/test/test_token_list.py +++ b/test/test_token_list.py @@ -9,45 +9,105 @@ Do not edit the class manually. """ -import unittest +import json +from uuid import uuid4 +from ibutsu_client.models.pagination import Pagination +from ibutsu_client.models.token import Token from ibutsu_client.models.token_list import TokenList -class TestTokenList(unittest.TestCase): - """TokenList unit test stubs""" +class TestTokenList: + """TokenList model tests""" - def setUp(self): - pass + def test_creation_empty(self): + model = TokenList() + assert model.tokens is None + assert model.pagination is None + + def test_creation_full(self): + uid = uuid4() + item = Token(name="t1", token="abc", id=uid, user_id=uid) + pagination = Pagination(page=1) + model = TokenList(tokens=[item], pagination=pagination) + assert len(model.tokens) == 1 + assert model.pagination.page == 1 + + def test_to_dict(self): + uid = uuid4() + item = Token(name="t1", token="abc", id=uid, user_id=uid) + model = TokenList(tokens=[item]) + data = model.to_dict() + assert "tokens" in data + assert len(data["tokens"]) == 1 + + def test_to_dict_with_pagination(self): + uid = uuid4() + item = Token(name="t1", token="abc", id=uid, user_id=uid) + pagination = Pagination(page=1) + model = TokenList(tokens=[item], pagination=pagination) + data = model.to_dict() + assert "pagination" in data + assert data["pagination"]["page"] == 1 + + def test_to_json(self): + uid = uuid4() + item = Token(name="t1", token="abc", id=uid, user_id=uid) + model = TokenList(tokens=[item]) + json_str = model.to_json() + data = json.loads(json_str) + assert len(data["tokens"]) == 1 + + def test_from_dict(self): + uid = str(uuid4()) + item_dict = {"name": "t1", "token": "abc", "id": uid, "user_id": uid} + data = {"tokens": [item_dict], "pagination": {"page": 2}} + model = TokenList.from_dict(data) + assert len(model.tokens) == 1 + assert model.pagination.page == 2 - def tearDown(self): - pass + def test_from_json(self): + uid = str(uuid4()) + json_str = f'{{"tokens": [{{"name": "t1", "token": "abc", "id": "{uid}", "user_id": "{uid}"}}], "pagination": {{"page": 3}}}}' + model = TokenList.from_json(json_str) + assert len(model.tokens) == 1 - def make_instance(self, include_optional) -> TokenList: - """Test TokenList - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `TokenList` - """ + def test_multiple_items(self): + uid1 = uuid4() + uid2 = uuid4() + i1 = Token(name="t1", token="abc", id=uid1, user_id=uid1) + i2 = Token(name="t2", token="xyz", id=uid2, user_id=uid2) + model = TokenList(tokens=[i1, i2]) + data = model.to_dict() + assert len(data["tokens"]) == 2 + + def test_roundtrip_json(self): + uid = uuid4() + item = Token(name="t1", token="abc", id=uid, user_id=uid) + original = TokenList(tokens=[item]) + json_str = original.to_json() + restored = TokenList.from_json(json_str) + assert len(restored.tokens) == 1 + assert restored.tokens[0].id == original.tokens[0].id + + def test_to_str(self): model = TokenList() - if include_optional: - return TokenList( - tokens = [ - {"id":"e2772010-bc06-47ed-8b6b-767ab87427cc","user_id":"81e2c9d6-1593-4559-af4f-90f6f1f8fa03","name":"My user token","expires":"2038-12-31T23:59:59+0000","token":"64ad787a-5aa8-48fa-842e-6e3b9631308a"} - ], - pagination = {"page":2,"pageSize":25,"totalPages":10,"totalItems":243} - ) - else: - return TokenList( - ) - """ - - def testTokenList(self): - """Test TokenList""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) - - -if __name__ == "__main__": - unittest.main() + s = model.to_str() + assert isinstance(s, str) + + def test_from_dict_none(self): + model = TokenList.from_dict(None) + assert model is None + + def test_from_dict_non_dict(self): + uid = uuid4() + item = Token(name="t1", token="abc", id=uid, user_id=uid) + orig = TokenList(tokens=[item]) + model = TokenList.from_dict(orig) + assert len(model.tokens) == 1 + + def test_list_none_values_excluded(self): + model = TokenList(tokens=[]) + data = model.to_dict() + assert "tokens" in data + assert "pagination" not in data diff --git a/test/test_update_run.py b/test/test_update_run.py index 10e7d49..f730978 100644 --- a/test/test_update_run.py +++ b/test/test_update_run.py @@ -9,42 +9,56 @@ Do not edit the class manually. """ -import unittest +import json from ibutsu_client.models.update_run import UpdateRun -class TestUpdateRun(unittest.TestCase): - """UpdateRun unit test stubs""" +class TestUpdateRun: + """UpdateRun model tests""" - def setUp(self): - pass + def test_creation_empty(self): + model = UpdateRun() + assert model.metadata is None - def tearDown(self): - pass + def test_creation_full(self): + model = UpdateRun(metadata={"k": "v"}) + assert model.metadata == {"k": "v"} - def make_instance(self, include_optional) -> UpdateRun: - """Test UpdateRun - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `UpdateRun` - """ - model = UpdateRun() - if include_optional: - return UpdateRun( - metadata = None - ) - else: - return UpdateRun( - ) - """ - - def testUpdateRun(self): - """Test UpdateRun""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) - - -if __name__ == "__main__": - unittest.main() + def test_to_dict(self): + model = UpdateRun(metadata={"k": "v"}) + d = model.to_dict() + assert d["metadata"] == {"k": "v"} + + def test_to_json(self): + model = UpdateRun(metadata={"k": "v"}) + j = model.to_json() + data = json.loads(j) + assert data["metadata"] == {"k": "v"} + + def test_from_dict(self): + d = {"metadata": {"k": "v"}} + model = UpdateRun.from_dict(d) + assert model.metadata == {"k": "v"} + + def test_from_json(self): + j = '{"metadata": {"k": "v"}}' + model = UpdateRun.from_json(j) + assert model.metadata == {"k": "v"} + + def test_to_str(self): + model = UpdateRun(metadata={"k": "v"}) + assert "metadata" in model.to_str() + + def test_from_dict_none(self): + assert UpdateRun.from_dict(None) is None + + def test_from_dict_non_dict(self): + orig = UpdateRun(metadata={"k": "v"}) + model = UpdateRun.from_dict(orig) + assert model.metadata == {"k": "v"} + + def test_none_values_excluded(self): + model = UpdateRun(metadata={"k": "v"}) + d = model.to_dict() + assert "metadata" in d diff --git a/test/test_user.py b/test/test_user.py index 2e2d1f9..6ba4434 100644 --- a/test/test_user.py +++ b/test/test_user.py @@ -9,48 +9,117 @@ Do not edit the class manually. """ -import unittest +import json +from uuid import uuid4 from ibutsu_client.models.user import User -class TestUser(unittest.TestCase): - """User unit test stubs""" - - def setUp(self): - pass - - def tearDown(self): - pass - - def make_instance(self, include_optional) -> User: - """Test User - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `User` - """ - model = User() - if include_optional: - return User( - id = '81e2c9d6-1593-4559-af4f-90f6f1f8fa03', - email = 'user@domain.com', - name = 'Namey McNameface', - is_superadmin = False, - is_active = True, - group_id = 'a16ad60e-bf23-4195-99dc-594858ad3e5e' - ) - else: - return User( - email = 'user@domain.com', +class TestUser: + """User model tests""" + + def test_user_creation_required(self): + """Test User creation with required parameters""" + user = User(email="test@example.com") + assert user.email == "test@example.com" + + def test_user_creation_full(self): + """Test User creation with all parameters""" + uid = uuid4() + group_id = uuid4() + + user = User( + id=uid, + email="full@example.com", + name="Full User", + is_superadmin=True, + is_active=True, + group_id=group_id, ) - """ - def testUser(self): - """Test User""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) + assert user.id == uid + assert user.email == "full@example.com" + assert user.name == "Full User" + assert user.is_superadmin is True + assert user.group_id == group_id + + def test_user_to_dict(self): + """Test User to_dict conversion""" + user = User(email="dict@example.com") + user_dict = user.to_dict() + + assert isinstance(user_dict, dict) + assert user_dict["email"] == "dict@example.com" + + def test_user_to_json(self): + """Test User to_json conversion""" + user = User(email="json@example.com") + user_json = user.to_json() + + assert isinstance(user_json, str) + parsed = json.loads(user_json) + assert parsed["email"] == "json@example.com" + + def test_user_from_dict(self): + """Test User from_dict creation""" + user_dict = {"email": "from_dict@example.com", "name": "From Dict"} + user = User.from_dict(user_dict) + + assert isinstance(user, User) + assert user.email == "from_dict@example.com" + assert user.name == "From Dict" + + def test_user_from_json(self): + """Test User from_json creation""" + user_json = '{"email": "from_json@example.com"}' + user = User.from_json(user_json) + + assert isinstance(user, User) + assert user.email == "from_json@example.com" + + def test_user_to_str(self): + """Test User to_str representation""" + user = User(email="str@example.com") + user_str = user.to_str() + + assert isinstance(user_str, str) + assert "str@example.com" in user_str + + def test_user_none_values_excluded(self): + """Test that None values are excluded from dict""" + user = User(email="none@example.com") + user_dict = user.to_dict() + + assert "email" in user_dict + assert "name" not in user_dict + + def test_user_explicit_nones(self): + """Test explicit None values are preserved in to_dict if set""" + user = User(email="explicit@example.com", name=None, group_id=None) + user_dict = user.to_dict() + + assert "name" in user_dict + assert user_dict["name"] is None + assert "group_id" in user_dict + assert user_dict["group_id"] is None + + def test_user_from_dict_none(self): + """Test User.from_dict with None returns None""" + user = User.from_dict(None) + assert user is None + + def test_user_from_dict_non_dict(self): + """Test from_dict with a non-dict object""" + user_obj = User(email="obj@example.com") + new_user = User.from_dict(user_obj) + assert new_user.email == "obj@example.com" + def test_user_roundtrip_json(self): + """Test User can be serialized and deserialized""" + uid = uuid4() + original = User(id=uid, email="roundtrip@example.com") + json_str = original.to_json() + restored = User.from_json(json_str) -if __name__ == "__main__": - unittest.main() + assert restored.email == original.email + assert restored.id == original.id diff --git a/test/test_user_list.py b/test/test_user_list.py index 724e52e..fd3a7ac 100644 --- a/test/test_user_list.py +++ b/test/test_user_list.py @@ -9,45 +9,95 @@ Do not edit the class manually. """ -import unittest +import json +from uuid import uuid4 +from ibutsu_client.models.pagination import Pagination +from ibutsu_client.models.user import User from ibutsu_client.models.user_list import UserList -class TestUserList(unittest.TestCase): - """UserList unit test stubs""" +class TestUserList: + """UserList model tests""" - def setUp(self): - pass + def test_creation_empty(self): + model = UserList() + assert model.users is None + assert model.pagination is None + + def test_creation_full(self): + item = User(email="e1") + pagination = Pagination(page=1) + model = UserList(users=[item], pagination=pagination) + assert len(model.users) == 1 + assert model.pagination.page == 1 + + def test_to_dict(self): + item = User(email="e1") + model = UserList(users=[item]) + data = model.to_dict() + assert "users" in data + assert len(data["users"]) == 1 + + def test_to_dict_with_pagination(self): + item = User(email="e1") + pagination = Pagination(page=1) + model = UserList(users=[item], pagination=pagination) + data = model.to_dict() + assert "pagination" in data + assert data["pagination"]["page"] == 1 + + def test_to_json(self): + item = User(email="e1") + model = UserList(users=[item]) + json_str = model.to_json() + data = json.loads(json_str) + assert len(data["users"]) == 1 + + def test_from_dict(self): + item_dict = {"email": "e1"} + data = {"users": [item_dict], "pagination": {"page": 2}} + model = UserList.from_dict(data) + assert len(model.users) == 1 + assert model.pagination.page == 2 - def tearDown(self): - pass + def test_from_json(self): + json_str = '{"users": [{"email": "e1"}], "pagination": {"page": 3}}' + model = UserList.from_json(json_str) + assert len(model.users) == 1 - def make_instance(self, include_optional) -> UserList: - """Test UserList - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `UserList` - """ + def test_multiple_items(self): + i1 = User(email="e1") + i2 = User(email="e2") + model = UserList(users=[i1, i2]) + data = model.to_dict() + assert len(data["users"]) == 2 + + def test_roundtrip_json(self): + item = User(email="e1", id=uuid4()) + original = UserList(users=[item]) + json_str = original.to_json() + restored = UserList.from_json(json_str) + assert len(restored.users) == 1 + assert restored.users[0].id == original.users[0].id + + def test_to_str(self): model = UserList() - if include_optional: - return UserList( - users = [ - {"id":"81e2c9d6-1593-4559-af4f-90f6f1f8fa03","email":"user@domain.com","name":"Namey McNameface","is_superadmin":false,"is_active":true,"group_id":"a16ad60e-bf23-4195-99dc-594858ad3e5e"} - ], - pagination = {"page":2,"pageSize":25,"totalPages":10,"totalItems":243} - ) - else: - return UserList( - ) - """ - - def testUserList(self): - """Test UserList""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) - - -if __name__ == "__main__": - unittest.main() + s = model.to_str() + assert isinstance(s, str) + + def test_from_dict_none(self): + model = UserList.from_dict(None) + assert model is None + + def test_from_dict_non_dict(self): + item = User(email="e1") + orig = UserList(users=[item]) + model = UserList.from_dict(orig) + assert len(model.users) == 1 + + def test_list_none_values_excluded(self): + model = UserList(users=[]) + data = model.to_dict() + assert "users" in data + assert "pagination" not in data diff --git a/test/test_widget_config.py b/test/test_widget_config.py index 4b25019..ec092f1 100644 --- a/test/test_widget_config.py +++ b/test/test_widget_config.py @@ -9,48 +9,107 @@ Do not edit the class manually. """ -import unittest +import json +from uuid import uuid4 from ibutsu_client.models.widget_config import WidgetConfig -class TestWidgetConfig(unittest.TestCase): - """WidgetConfig unit test stubs""" - - def setUp(self): - pass - - def tearDown(self): - pass - - def make_instance(self, include_optional) -> WidgetConfig: - """Test WidgetConfig - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `WidgetConfig` - """ - model = WidgetConfig() - if include_optional: - return WidgetConfig( - id = 'afbcf5c7-1ffd-4367-b228-5a868c29e0ef', - type = 'widget', - widget = 'jenkins-heatmap', - project_id = '44941c55-9736-42f6-acce-ca3c4739d0f3', - weight = 0, - params = {"job_name":"integration_tests","builds":5,"group_field":"metadata.component","sort_field":"starttime"}, - title = 'Job Health' - ) - else: - return WidgetConfig( +class TestWidgetConfig: + """WidgetConfig model tests""" + + def test_widget_config_creation_empty(self): + """Test WidgetConfig creation with no parameters""" + widget_config = WidgetConfig() + assert widget_config.id is None + + def test_widget_config_creation_full(self): + """Test WidgetConfig creation with all parameters""" + wid = uuid4() + project_id = uuid4() + + widget_config = WidgetConfig( + id=wid, + type="widget", + widget="my-widget", + project_id=project_id, + weight=10, + params={"p1": "v1"}, + title="My Widget", ) - """ - def testWidgetConfig(self): - """Test WidgetConfig""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) + assert widget_config.id == wid + assert widget_config.type == "widget" + assert widget_config.weight == 10 + assert widget_config.params == {"p1": "v1"} + + def test_widget_config_to_dict(self): + """Test WidgetConfig to_dict conversion""" + widget_config = WidgetConfig(title="Dict Widget") + config_dict = widget_config.to_dict() + + assert isinstance(config_dict, dict) + assert config_dict["title"] == "Dict Widget" + + def test_widget_config_to_json(self): + """Test WidgetConfig to_json conversion""" + widget_config = WidgetConfig(title="JSON Widget") + config_json = widget_config.to_json() + + assert isinstance(config_json, str) + parsed = json.loads(config_json) + assert parsed["title"] == "JSON Widget" + + def test_widget_config_from_dict(self): + """Test WidgetConfig from_dict creation""" + config_dict = {"title": "From Dict", "type": "view"} + widget_config = WidgetConfig.from_dict(config_dict) + + assert isinstance(widget_config, WidgetConfig) + assert widget_config.title == "From Dict" + assert widget_config.type == "view" + + def test_widget_config_from_json(self): + """Test WidgetConfig from_json creation""" + config_json = '{"title": "From JSON"}' + widget_config = WidgetConfig.from_json(config_json) + + assert isinstance(widget_config, WidgetConfig) + assert widget_config.title == "From JSON" + + def test_widget_config_to_str(self): + """Test WidgetConfig to_str representation""" + widget_config = WidgetConfig(title="Str Widget") + config_str = widget_config.to_str() + + assert isinstance(config_str, str) + assert "Str Widget" in config_str + + def test_widget_config_none_values_excluded(self): + """Test that None values are excluded from dict""" + widget_config = WidgetConfig(title="None Widget") + config_dict = widget_config.to_dict() + + assert "title" in config_dict + assert "weight" not in config_dict + + def test_widget_config_from_dict_none(self): + """Test WidgetConfig.from_dict with None returns None""" + widget_config = WidgetConfig.from_dict(None) + assert widget_config is None + + def test_widget_config_from_dict_non_dict(self): + """Test from_dict with a non-dict object""" + config_obj = WidgetConfig(title="test_obj") + new_config = WidgetConfig.from_dict(config_obj) + assert new_config.title == "test_obj" + def test_widget_config_roundtrip_json(self): + """Test WidgetConfig can be serialized and deserialized""" + wid = uuid4() + original = WidgetConfig(id=wid, title="Roundtrip") + json_str = original.to_json() + restored = WidgetConfig.from_json(json_str) -if __name__ == "__main__": - unittest.main() + assert restored.title == original.title + assert restored.id == original.id diff --git a/test/test_widget_config_list.py b/test/test_widget_config_list.py index 76b489b..1a454fc 100644 --- a/test/test_widget_config_list.py +++ b/test/test_widget_config_list.py @@ -9,45 +9,95 @@ Do not edit the class manually. """ -import unittest +import json +from uuid import uuid4 +from ibutsu_client.models.pagination import Pagination +from ibutsu_client.models.widget_config import WidgetConfig from ibutsu_client.models.widget_config_list import WidgetConfigList -class TestWidgetConfigList(unittest.TestCase): - """WidgetConfigList unit test stubs""" +class TestWidgetConfigList: + """WidgetConfigList model tests""" - def setUp(self): - pass + def test_creation_empty(self): + model = WidgetConfigList() + assert model.widgets is None + assert model.pagination is None + + def test_creation_full(self): + item = WidgetConfig(title="w1") + pagination = Pagination(page=1) + model = WidgetConfigList(widgets=[item], pagination=pagination) + assert len(model.widgets) == 1 + assert model.pagination.page == 1 + + def test_to_dict(self): + item = WidgetConfig(title="w1") + model = WidgetConfigList(widgets=[item]) + data = model.to_dict() + assert "widgets" in data + assert len(data["widgets"]) == 1 + + def test_to_dict_with_pagination(self): + item = WidgetConfig(title="w1") + pagination = Pagination(page=1) + model = WidgetConfigList(widgets=[item], pagination=pagination) + data = model.to_dict() + assert "pagination" in data + assert data["pagination"]["page"] == 1 + + def test_to_json(self): + item = WidgetConfig(title="w1") + model = WidgetConfigList(widgets=[item]) + json_str = model.to_json() + data = json.loads(json_str) + assert len(data["widgets"]) == 1 + + def test_from_dict(self): + item_dict = {"title": "w1"} + data = {"widgets": [item_dict], "pagination": {"page": 2}} + model = WidgetConfigList.from_dict(data) + assert len(model.widgets) == 1 + assert model.pagination.page == 2 - def tearDown(self): - pass + def test_from_json(self): + json_str = '{"widgets": [{"title": "w1"}], "pagination": {"page": 3}}' + model = WidgetConfigList.from_json(json_str) + assert len(model.widgets) == 1 - def make_instance(self, include_optional) -> WidgetConfigList: - """Test WidgetConfigList - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `WidgetConfigList` - """ + def test_multiple_items(self): + i1 = WidgetConfig(title="w1") + i2 = WidgetConfig(title="w2") + model = WidgetConfigList(widgets=[i1, i2]) + data = model.to_dict() + assert len(data["widgets"]) == 2 + + def test_roundtrip_json(self): + item = WidgetConfig(title="w1", id=uuid4()) + original = WidgetConfigList(widgets=[item]) + json_str = original.to_json() + restored = WidgetConfigList.from_json(json_str) + assert len(restored.widgets) == 1 + assert restored.widgets[0].id == original.widgets[0].id + + def test_to_str(self): model = WidgetConfigList() - if include_optional: - return WidgetConfigList( - widgets = [ - {"id":"afbcf5c7-1ffd-4367-b228-5a868c29e0ef","type":"widget","widget":"jenkins-heatmap","project_id":"44941c55-9736-42f6-acce-ca3c4739d0f3","weight":0,"params":{"job_name":"integration_tests","builds":5,"group_field":"metadata.component","sort_field":"starttime"},"title":"Jenkins Pipeline Health"} - ], - pagination = {"page":2,"pageSize":25,"totalPages":10,"totalItems":243} - ) - else: - return WidgetConfigList( - ) - """ - - def testWidgetConfigList(self): - """Test WidgetConfigList""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) - - -if __name__ == "__main__": - unittest.main() + s = model.to_str() + assert isinstance(s, str) + + def test_from_dict_none(self): + model = WidgetConfigList.from_dict(None) + assert model is None + + def test_from_dict_non_dict(self): + item = WidgetConfig(title="w1") + orig = WidgetConfigList(widgets=[item]) + model = WidgetConfigList.from_dict(orig) + assert len(model.widgets) == 1 + + def test_list_none_values_excluded(self): + model = WidgetConfigList(widgets=[]) + data = model.to_dict() + assert "widgets" in data + assert "pagination" not in data diff --git a/test/test_widget_param.py b/test/test_widget_param.py index 82f6c6e..02efac0 100644 --- a/test/test_widget_param.py +++ b/test/test_widget_param.py @@ -9,44 +9,94 @@ Do not edit the class manually. """ -import unittest +import json from ibutsu_client.models.widget_param import WidgetParam -class TestWidgetParam(unittest.TestCase): - """WidgetParam unit test stubs""" - - def setUp(self): - pass - - def tearDown(self): - pass - - def make_instance(self, include_optional) -> WidgetParam: - """Test WidgetParam - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `WidgetParam` - """ - model = WidgetParam() - if include_optional: - return WidgetParam( - name = 'job_name', - description = 'The Jenkins job name', - type = 'string' - ) - else: - return WidgetParam( - ) - """ - - def testWidgetParam(self): - """Test WidgetParam""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) - - -if __name__ == "__main__": - unittest.main() +class TestWidgetParam: + """WidgetParam model tests""" + + def test_widget_param_creation_empty(self): + """Test WidgetParam creation with no parameters""" + widget_param = WidgetParam() + assert widget_param.name is None + assert widget_param.type is None + + def test_widget_param_creation_full(self): + """Test WidgetParam creation with all parameters""" + widget_param = WidgetParam(name="param1", description="A parameter", type="string") + + assert widget_param.name == "param1" + assert widget_param.description == "A parameter" + assert widget_param.type == "string" + + def test_widget_param_to_dict(self): + """Test WidgetParam to_dict conversion""" + widget_param = WidgetParam(name="dict_param") + param_dict = widget_param.to_dict() + + assert isinstance(param_dict, dict) + assert param_dict["name"] == "dict_param" + + def test_widget_param_to_json(self): + """Test WidgetParam to_json conversion""" + widget_param = WidgetParam(name="json_param") + param_json = widget_param.to_json() + + assert isinstance(param_json, str) + parsed = json.loads(param_json) + assert parsed["name"] == "json_param" + + def test_widget_param_from_dict(self): + """Test WidgetParam from_dict creation""" + param_dict = {"name": "from_dict", "type": "integer"} + widget_param = WidgetParam.from_dict(param_dict) + + assert isinstance(widget_param, WidgetParam) + assert widget_param.name == "from_dict" + assert widget_param.type == "integer" + + def test_widget_param_from_json(self): + """Test WidgetParam from_json creation""" + param_json = '{"name": "from_json"}' + widget_param = WidgetParam.from_json(param_json) + + assert isinstance(widget_param, WidgetParam) + assert widget_param.name == "from_json" + + def test_widget_param_to_str(self): + """Test WidgetParam to_str representation""" + widget_param = WidgetParam(name="str_param") + param_str = widget_param.to_str() + + assert isinstance(param_str, str) + assert "str_param" in param_str + + def test_widget_param_none_values_excluded(self): + """Test that None values are excluded from dict""" + widget_param = WidgetParam(name="none_param") + param_dict = widget_param.to_dict() + + assert "name" in param_dict + assert "description" not in param_dict + + def test_widget_param_from_dict_none(self): + """Test WidgetParam.from_dict with None returns None""" + widget_param = WidgetParam.from_dict(None) + assert widget_param is None + + def test_widget_param_from_dict_non_dict(self): + """Test from_dict with a non-dict object""" + param_obj = WidgetParam(name="test_obj") + new_param = WidgetParam.from_dict(param_obj) + assert new_param.name == "test_obj" + + def test_widget_param_roundtrip_json(self): + """Test WidgetParam can be serialized and deserialized""" + original = WidgetParam(name="roundtrip", type="integer") + json_str = original.to_json() + restored = WidgetParam.from_json(json_str) + + assert restored.name == original.name + assert restored.type == original.type diff --git a/test/test_widget_type.py b/test/test_widget_type.py index fc1fd57..7664c33 100644 --- a/test/test_widget_type.py +++ b/test/test_widget_type.py @@ -9,46 +9,116 @@ Do not edit the class manually. """ -import unittest +import json +from ibutsu_client.models.widget_param import WidgetParam from ibutsu_client.models.widget_type import WidgetType -class TestWidgetType(unittest.TestCase): - """WidgetType unit test stubs""" - - def setUp(self): - pass - - def tearDown(self): - pass - - def make_instance(self, include_optional) -> WidgetType: - """Test WidgetType - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `WidgetType` - """ - model = WidgetType() - if include_optional: - return WidgetType( - id = 'heatmap', - title = 'Heatmap', - description = 'A heatmap of runs and trends', - params = [{"name":"job_name","description":"The Jenkins job name","type":"string"},{"name":"builds","description":"The number of Jenkins builds to analyze","type":"integer"},{"name":"group_field","description":"The field in a result to group by","type":"string"},{"name":"sort_field","description":"The field to sort results by","type":"string"}], - type = 'widget' - ) - else: - return WidgetType( +class TestWidgetType: + """WidgetType model tests""" + + def test_widget_type_creation_empty(self): + """Test WidgetType creation with no parameters""" + widget_type = WidgetType() + assert widget_type.id is None + + def test_widget_type_creation_full(self): + """Test WidgetType creation with all parameters""" + param = WidgetParam(name="p1") + + widget_type = WidgetType( + id="wt1", title="Widget Type 1", description="Desc", params=[param], type="view" ) - """ - def testWidgetType(self): - """Test WidgetType""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) + assert widget_type.id == "wt1" + assert widget_type.title == "Widget Type 1" + assert len(widget_type.params) == 1 + assert widget_type.params[0].name == "p1" + + def test_widget_type_to_dict(self): + """Test WidgetType to_dict conversion""" + param = WidgetParam(name="p_dict") + widget_type = WidgetType(id="wt_dict", params=[param]) + type_dict = widget_type.to_dict() + + assert isinstance(type_dict, dict) + assert type_dict["id"] == "wt_dict" + assert len(type_dict["params"]) == 1 + assert type_dict["params"][0]["name"] == "p_dict" + + def test_widget_type_to_json(self): + """Test WidgetType to_json conversion""" + widget_type = WidgetType(id="wt_json") + type_json = widget_type.to_json() + + assert isinstance(type_json, str) + parsed = json.loads(type_json) + assert parsed["id"] == "wt_json" + + def test_widget_type_from_dict(self): + """Test WidgetType from_dict creation""" + param_dict = {"name": "p_from_dict"} + type_dict = {"id": "wt_from_dict", "params": [param_dict]} + widget_type = WidgetType.from_dict(type_dict) + + assert isinstance(widget_type, WidgetType) + assert widget_type.id == "wt_from_dict" + assert len(widget_type.params) == 1 + assert isinstance(widget_type.params[0], WidgetParam) + assert widget_type.params[0].name == "p_from_dict" + + def test_widget_type_from_json(self): + """Test WidgetType from_json creation""" + type_json = '{"id": "wt_from_json", "params": [{"name": "p_json"}]}' + widget_type = WidgetType.from_json(type_json) + + assert isinstance(widget_type, WidgetType) + assert widget_type.id == "wt_from_json" + assert widget_type.params[0].name == "p_json" + + def test_widget_type_to_str(self): + """Test WidgetType to_str representation""" + widget_type = WidgetType(id="wt_str") + type_str = widget_type.to_str() + + assert isinstance(type_str, str) + assert "wt_str" in type_str + + def test_widget_type_none_values_excluded(self): + """Test that None values are excluded from dict""" + widget_type = WidgetType(id="wt_none") + type_dict = widget_type.to_dict() + + assert "id" in type_dict + assert "title" not in type_dict + + def test_widget_type_from_dict_none(self): + """Test WidgetType.from_dict with None returns None""" + widget_type = WidgetType.from_dict(None) + assert widget_type is None + + def test_widget_type_from_dict_non_dict(self): + """Test from_dict with a non-dict object""" + type_obj = WidgetType(id="test_obj") + new_type = WidgetType.from_dict(type_obj) + assert new_type.id == "test_obj" + + def test_widget_type_roundtrip_json(self): + """Test WidgetType can be serialized and deserialized""" + param = WidgetParam(name="p_roundtrip") + original = WidgetType(id="wt_roundtrip", params=[param]) + json_str = original.to_json() + restored = WidgetType.from_json(json_str) + + assert restored.id == original.id + assert restored.params[0].name == original.params[0].name + def test_widget_type_multiple_items(self): + """Test WidgetType params list with multiple items""" + p1 = WidgetParam(name="p1") + p2 = WidgetParam(name="p2") + widget_type = WidgetType(params=[p1, p2]) -if __name__ == "__main__": - unittest.main() + type_dict = widget_type.to_dict() + assert len(type_dict["params"]) == 2 diff --git a/test/test_widget_type_list.py b/test/test_widget_type_list.py index 75c1670..9ad3e11 100644 --- a/test/test_widget_type_list.py +++ b/test/test_widget_type_list.py @@ -9,45 +9,94 @@ Do not edit the class manually. """ -import unittest +import json +from ibutsu_client.models.pagination import Pagination +from ibutsu_client.models.widget_type import WidgetType from ibutsu_client.models.widget_type_list import WidgetTypeList -class TestWidgetTypeList(unittest.TestCase): - """WidgetTypeList unit test stubs""" +class TestWidgetTypeList: + """WidgetTypeList model tests""" - def setUp(self): - pass + def test_creation_empty(self): + model = WidgetTypeList() + assert model.types is None + assert model.pagination is None + + def test_creation_full(self): + item = WidgetType(id="wt1") + pagination = Pagination(page=1) + model = WidgetTypeList(types=[item], pagination=pagination) + assert len(model.types) == 1 + assert model.pagination.page == 1 + + def test_to_dict(self): + item = WidgetType(id="wt1") + model = WidgetTypeList(types=[item]) + data = model.to_dict() + assert "types" in data + assert len(data["types"]) == 1 + + def test_to_dict_with_pagination(self): + item = WidgetType(id="wt1") + pagination = Pagination(page=1) + model = WidgetTypeList(types=[item], pagination=pagination) + data = model.to_dict() + assert "pagination" in data + assert data["pagination"]["page"] == 1 + + def test_to_json(self): + item = WidgetType(id="wt1") + model = WidgetTypeList(types=[item]) + json_str = model.to_json() + data = json.loads(json_str) + assert len(data["types"]) == 1 + + def test_from_dict(self): + item_dict = {"id": "wt1"} + data = {"types": [item_dict], "pagination": {"page": 2}} + model = WidgetTypeList.from_dict(data) + assert len(model.types) == 1 + assert model.pagination.page == 2 - def tearDown(self): - pass + def test_from_json(self): + json_str = '{"types": [{"id": "wt1"}], "pagination": {"page": 3}}' + model = WidgetTypeList.from_json(json_str) + assert len(model.types) == 1 - def make_instance(self, include_optional) -> WidgetTypeList: - """Test WidgetTypeList - include_optional is a boolean, when False only required - params are included, when True both required and - optional params are included""" - # uncomment below to create an instance of `WidgetTypeList` - """ + def test_multiple_items(self): + i1 = WidgetType(id="wt1") + i2 = WidgetType(id="wt2") + model = WidgetTypeList(types=[i1, i2]) + data = model.to_dict() + assert len(data["types"]) == 2 + + def test_roundtrip_json(self): + item = WidgetType(id="wt1", title="Type 1") + original = WidgetTypeList(types=[item]) + json_str = original.to_json() + restored = WidgetTypeList.from_json(json_str) + assert len(restored.types) == 1 + assert restored.types[0].id == original.types[0].id + + def test_to_str(self): model = WidgetTypeList() - if include_optional: - return WidgetTypeList( - types = [ - {"id":"jenkins-heatmap","title":"Jenkins Pipeline Heatmap","description":"A heatmap of test runs and trends from a Jenkins pipeline","params":[{"name":"job_name","description":"The Jenkins job name","type":"string"},{"name":"builds","description":"The number of Jenkins builds to analyze","type":"integer"},{"name":"group_field","description":"The field in a result to group by","type":"string"},{"name":"sort_field","description":"The field to sort results by","type":"string"}],"type":"widget"} - ], - pagination = {"page":2,"pageSize":25,"totalPages":10,"totalItems":243} - ) - else: - return WidgetTypeList( - ) - """ - - def testWidgetTypeList(self): - """Test WidgetTypeList""" - # inst_req_only = self.make_instance(include_optional=False) - # inst_req_and_optional = self.make_instance(include_optional=True) - - -if __name__ == "__main__": - unittest.main() + s = model.to_str() + assert isinstance(s, str) + + def test_from_dict_none(self): + model = WidgetTypeList.from_dict(None) + assert model is None + + def test_from_dict_non_dict(self): + item = WidgetType(id="wt1") + orig = WidgetTypeList(types=[item]) + model = WidgetTypeList.from_dict(orig) + assert len(model.types) == 1 + + def test_list_none_values_excluded(self): + model = WidgetTypeList(types=[]) + data = model.to_dict() + assert "types" in data + assert "pagination" not in data