Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Zimbra-Community/python-zimbra
Browse files Browse the repository at this point in the history
  • Loading branch information
dploeger committed Jan 8, 2014
2 parents 35e476d + 9ab3131 commit 9bb630f
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 4 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Ignore local test configuration

build/
dist/
*.egg-info/
tests/config.ini
*.pyc
*.pyc
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include LICENSE
include README
recursive-include pythonzimbra/exceptions *
recursive-include pythonzimbra/tools *
14 changes: 13 additions & 1 deletion pythonzimbra/tools/xmlserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,20 @@ def dom_to_dict(root_node):
else:

subnode_dict = dom_to_dict(child)
new_val = subnode_dict[child.tagName]

node_dict[child.tagName] = subnode_dict[child.tagName]
# If we have several child with same name, put them in a list.

if node_dict.has_key(child.tagName):
prev_val = node_dict[child.tagName]

if type(prev_val) != list:
node_dict[child.tagName] = [prev_val]

node_dict[child.tagName].append(new_val)

else:
node_dict[child.tagName] = new_val

return root_dict

Expand Down
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[egg_info]
tag_build =
tag_date = 0
tag_svn_revision = 0

32 changes: 32 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python
import os
from setuptools import setup

README = open(os.path.join(os.path.dirname(__file__), 'README.md')).read()

# allow setup.py to be run from any path
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))

setup(
name='python-zimbra',
version='1.0-git',
packages=['pythonzimbra'],
include_package_data=True,
license='specific',
description='Python classes to access Zimbra SOAP backend with a few utilities.',
long_description=README,
url='https://github.com/Zimbra-Community/python-zimbra',
author='Dennis Ploeger',
author_email='[email protected]',
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'Operating System :: POSIX',
'Operating System :: MacOS :: MacOS X',
'Programming Language :: Python',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Topic :: Software Development :: Libraries :: Application Frameworks',
'Topic :: Software Development :: Libraries'
],
)
35 changes: 34 additions & 1 deletion tests/test_response_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ class TestResponseXml(TestCase):
""" The result we test against (coming from a GetVersionInfoRequest by
running zmsoap -z --json -t admin GetVersionInfoRequest -vv) """


tested_server_result_multi_value = \
'<soap:Envelope xmlns:soap="http://www.w3' \
'.org/2003/05/soap-envelope"><soap:Header><context' \
' xmlns="urn:zimbra"/></soap:Header><soap:Body' \
'><GetAllDomainsResponse> ' \
'<domain id="b37d6b9" name="client1.unbound.example.fr"></domain>' \
'<domain id="444d6b9" name="client1.unbound.example.fr"></domain>' \
'</GetAllDomainsResponse></soap:Body' \
'></soap:Envelope>'\


""" This one is a stripped version of a GetAlDomains """

response = None

""" Our response object """
Expand All @@ -38,6 +52,9 @@ def setUp(self):
self.response = ResponseXml()
self.response.set_response(self.tested_server_result)

self.response_multi = ResponseXml()
self.response_multi.set_response(self.tested_server_result_multi_value)

def test_get_body(self):

""" Checks the body against a pickled expectation
Expand Down Expand Up @@ -103,4 +120,20 @@ def test_get_response(self):
self.assertEqual(
expected_result,
pickle.dumps(self.response.get_response())
)
)


def test_get_response_multi(self):
""" For cases where we have several tags with the same name.
In that case, for a given tag name as a key, we want a list of dicts
containing the content of each tag, instead of a single dict.
"""

resp = self.response_multi.get_response()
gad_resp = resp['GetAllDomainsResponse']

self.assertTrue(gad_resp.has_key('domain'))
self.assertTrue(gad_resp['domain'])
self.assertIsInstance(gad_resp['domain'], list)
self.assertEqual(len(gad_resp['domain']), 2)

0 comments on commit 9bb630f

Please sign in to comment.