Skip to content

Commit

Permalink
Use provided _xpath_to_dict. Improves coverage as well
Browse files Browse the repository at this point in the history
  • Loading branch information
matiboy committed Apr 30, 2016
1 parent 16af359 commit ba1918a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
18 changes: 9 additions & 9 deletions pyexchange/exchange2010/__init__.py
Expand Up @@ -986,12 +986,12 @@ def _send_delete_request(self):
return self.service.send(soap_request.delete_attachment(self.id))

def _parse_response_for_get_attachment(self, root):
try:
self._name = root.xpath(u'//t:Name', namespaces=soap_request.NAMESPACES)[0].text
except IndexError:
raise ValueError('Unable to get item from Exchange')

try:
self._content = root.xpath(u'//t:Content', namespaces=soap_request.NAMESPACES)[0].text
except IndexError:
raise ValueError('Unable to get item from Exchange')
as_dict = self.service._xpath_to_dict(element=root, property_map={
u'_name': {
'xpath': u'//t:Name'
},
u'_content': {
'xpath': u'//t:Content'
}
}, namespace_map=soap_request.NAMESPACES)
self.__dict__.update(as_dict)
14 changes: 14 additions & 0 deletions tests/exchange2010/test_add_attachment.py
Expand Up @@ -66,6 +66,20 @@ def test_can_add_from_file_like_object(self):
)
self.event.add_attachment(ATTACHMENT_NAME, file=READABLE_FILE)

@httprettified
def test_can_add_from_file_path(self):
HTTPretty.register_uri(
HTTPretty.POST, FAKE_EXCHANGE_URL,
body=CREATE_ATTACHMENT_RESPONSE.encode('utf-8'),
content_type='text/xml; charset=utf-8',
)
# Create temp file
import tempfile
with tempfile.NamedTemporaryFile(delete=True) as t:
t.write(b'some stuff')
t.seek(0)
self.event.add_attachment(ATTACHMENT_NAME, file=t.name)

@httprettified
def test_should_call_update_key_if_not_available(self):
# TODO pick a mock library instead
Expand Down

0 comments on commit ba1918a

Please sign in to comment.