/
test_get_attachment.py
57 lines (48 loc) · 1.88 KB
/
test_get_attachment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
(c) 2013 LinkedIn Corp. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");?you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software?distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
"""
import unittest
from httpretty import HTTPretty, httprettified
from pyexchange import Exchange2010Service
from pyexchange.exchange2010 import Exchange2010Attachment
from pyexchange.connection import ExchangeNTLMAuthConnection
from pyexchange.exceptions import * # noqa
from .fixtures import * # noqa
config = {
"username": FAKE_EXCHANGE_USERNAME,
"password": FAKE_EXCHANGE_PASSWORD,
"url": FAKE_EXCHANGE_URL,
}
class Test_GettingAnAttachment(unittest.TestCase):
calendar = None
@classmethod
def setUpClass(cls):
cls.service = Exchange2010Service(
connection=ExchangeNTLMAuthConnection(
**config
)
)
@httprettified
def test_can_get_attachment(self):
HTTPretty.register_uri(
HTTPretty.POST, FAKE_EXCHANGE_URL,
body=GET_ATTACHMENT_RESPONSE.encode('utf-8'),
content_type='text/xml; charset=utf-8',
)
att = Exchange2010Attachment(self.service, ATTACHMENT_DETAILS.id)
assert att.content == ATTACHMENT_DETAILS.content
assert att.name == ATTACHMENT_DETAILS.name
@httprettified
def test_gets_sort_of_lazy_loaded(self):
HTTPretty.register_uri(
HTTPretty.POST, FAKE_EXCHANGE_URL,
body=GET_ATTACHMENT_RESPONSE.encode('utf-8'),
content_type='text/xml; charset=utf-8',
)
att = Exchange2010Attachment(self.service, ATTACHMENT_DETAILS.id)
assert att._loaded is False
# Simply causes to load
att.content
assert att._loaded is True