diff --git a/awacs/__init__.py b/awacs/__init__.py index 2f9e687c..f0dd93df 100644 --- a/awacs/__init__.py +++ b/awacs/__init__.py @@ -111,7 +111,7 @@ def JSONrepr(self) -> dict: self.validate() return self.resource - def to_json(self, indent: int = 4, sort_keys: bool = True) -> str: + def to_json(self, indent: Optional[int] = 4, sort_keys: bool = True) -> str: p = self.properties return json.dumps(p, cls=awsencode, indent=indent, sort_keys=sort_keys) @@ -149,7 +149,7 @@ def getdata(self, data: Union[AWSObject, T]) -> Union[str, None, T]: else: return data - def to_json(self, indent: int = 4, sort_keys: bool = True) -> str: + def to_json(self, indent: Optional[int] = 4, sort_keys: bool = True) -> str: p = self return json.dumps(p, cls=awsencode, indent=indent, sort_keys=sort_keys) diff --git a/tests/test_base.py b/tests/test_base.py index dc44a499..8e881edf 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -50,6 +50,22 @@ def test_invalid_property(self): "'statement'", ) + def test_to_json(self): + p = PolicyDocument(Version="2012-10-17", Statement=[]) + + self.assertEqual( + p.to_json(), + '{\n "Statement": [],\n "Version": "2012-10-17"\n}', + ) + + def test_to_json_indent_non(self): + p = PolicyDocument(Version="2012-10-17", Statement=[]) + + self.assertEqual( + p.to_json(indent=None), + '{"Statement": [], "Version": "2012-10-17"}', + ) + class TestAWSProperty(unittest.TestCase): def test_prop_value_type_mismatch_expect_list(self):