Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getting a calendar event list with Exchange 14.2.247.0 … #24

Merged
merged 3 commits into from
Oct 31, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions pyexchange/base/soap.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging

from lxml import etree
from lxml.builder import ElementMaker
from datetime import datetime
from pytz import utc

Expand All @@ -15,6 +16,7 @@
SOAP_NS = u'http://schemas.xmlsoap.org/soap/envelope/'

SOAP_NAMESPACES = {u's': SOAP_NS}
S = ElementMaker(namespace=SOAP_NS, nsmap=SOAP_NAMESPACES)

log = logging.getLogger('pyexchange')

Expand Down Expand Up @@ -64,10 +66,7 @@ def _send_soap_request(self, xml, headers=None, retries=2, timeout=30, encoding=
return response

def _wrap_soap_xml_request(self, exchange_xml):
root = etree.Element(u"{%s}Envelope" % SOAP_NS)
body = etree.SubElement(root, u"{%s}Body" % SOAP_NS)
body.append(exchange_xml)

root = S.Envelope(S.Body(exchange_xml))
return root

def _parse_date(self, date_string):
Expand Down
1 change: 1 addition & 0 deletions pyexchange/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def send(self, body, headers=None, retries=2, timeout=30, encoding=u"utf-8"):
response = self.session.post(self.url, data=body, headers=headers)
response.raise_for_status()
except requests.exceptions.RequestException as err:
log.debug(err.response.content)
raise FailedExchangeException(u'Unable to connect to Exchange: %s' % err)

log.info(u'Got response: {code}'.format(code=response.status_code))
Expand Down
4 changes: 2 additions & 2 deletions pyexchange/exchange2010/soap_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def get_item(exchange_id, format=u"Default"):
return root

def get_calendar_items(format=u"Default", start=None, end=None, max_entries=999999):
start = start.strftime(EXCHANGE_DATE_FORMAT)
end = end.strftime(EXCHANGE_DATE_FORMAT)
start = start.strftime(EXCHANGE_DATETIME_FORMAT)
end = end.strftime(EXCHANGE_DATETIME_FORMAT)

root = M.FindItem(
{u'Traversal': u'Shallow'},
Expand Down
2 changes: 1 addition & 1 deletion tests/exchange2010/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pytz import utc
from collections import namedtuple
from pyexchange.base.calendar import ExchangeEventOrganizer, ExchangeEventResponse, RESPONSE_ACCEPTED, RESPONSE_DECLINED, RESPONSE_TENTATIVE, RESPONSE_UNKNOWN
from pyexchange.exchange2010.soap_request import EXCHANGE_DATE_FORMAT # noqa
from pyexchange.exchange2010.soap_request import EXCHANGE_DATE_FORMAT, EXCHANGE_DATETIME_FORMAT # noqa

# don't remove this - a few tests import stuff this way
from ..fixtures import * # noqa
Expand Down
4 changes: 4 additions & 0 deletions tests/exchange2010/test_list_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def setUp(self):
def test_canary(self):
assert self.event_list is not None

def test_dates_are_in_datetime_format(self):
assert 'StartDate="%s"' % TEST_EVENT_LIST_START.strftime(EXCHANGE_DATETIME_FORMAT) in HTTPretty.last_request.body.decode('utf-8')
assert 'EndDate="%s"' % TEST_EVENT_LIST_END.strftime(EXCHANGE_DATETIME_FORMAT) in HTTPretty.last_request.body.decode('utf-8')

def test_event_count(self):
assert self.event_list.count == 3

Expand Down