Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modified the asdict functionality to optionally recursively give suds…
… object (#92)
- Loading branch information
Showing
2 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import pytest | ||
if __name__ == "__main__": | ||
import testutils | ||
testutils.run_using_pytest(globals()) | ||
|
||
from suds.sudsobject import Object | ||
from suds.sudsobject import asdict, recursive_asdict | ||
|
||
|
||
# test_suds_functions.py | ||
|
||
def test_asdict(): | ||
# Create a suds object | ||
sobject = Object() | ||
sobject.name = "John Doe" | ||
sobject.age = 30 | ||
sobject.children = [] | ||
|
||
# Call the asdict function | ||
result = asdict(sobject) | ||
|
||
# Assert the expected result | ||
expected = { | ||
'name': 'John Doe', | ||
'age': 30, | ||
'children': [] | ||
} | ||
assert result == expected | ||
|
||
|
||
def test_recursive_asdict(): | ||
# Create a suds object with nested objects | ||
outer_object = Object() | ||
outer_object.name = "John Doe" | ||
outer_object.age = 30 | ||
outer_object.children = [] | ||
|
||
inner_object = Object() | ||
inner_object.name = "Jane Doe" | ||
inner_object.age = 25 | ||
inner_object.children = [] | ||
|
||
outer_object.children.append(inner_object) | ||
|
||
grandchild_object = Object() | ||
grandchild_object.name = "Baby Doe" | ||
grandchild_object.age = 1 | ||
|
||
inner_object.children.append(grandchild_object) | ||
|
||
# Call the recursive_asdict function | ||
result = asdict(outer_object,True) | ||
|
||
# Assert the expected result | ||
expected = { | ||
'name': 'John Doe', | ||
'age': 30, | ||
'children': [ | ||
{ | ||
'name': 'Jane Doe', | ||
'age': 25, | ||
'children': [ | ||
{ | ||
'name': 'Baby Doe', | ||
'age': 1 | ||
} | ||
] | ||
} | ||
] | ||
} | ||
assert result == expected | ||
|