def test_get_rooms_parsing(self): # Test static XML since server has no rooms xml = b'''\ <?xml version="1.0" ?> <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Body> <m:GetRoomsResponse ResponseClass="Success" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"> <m:ResponseCode>NoError</m:ResponseCode> <m:Rooms> <t:Room> <t:Id> <t:Name>room1</t:Name> <t:EmailAddress>[email protected]</t:EmailAddress> <t:RoutingType>SMTP</t:RoutingType> <t:MailboxType>Mailbox</t:MailboxType> </t:Id> </t:Room> <t:Room> <t:Id> <t:Name>room2</t:Name> <t:EmailAddress>[email protected]</t:EmailAddress> <t:RoutingType>SMTP</t:RoutingType> <t:MailboxType>Mailbox</t:MailboxType> </t:Id> </t:Room> </m:Rooms> </m:GetRoomsResponse> </s:Body> </s:Envelope>''' ws = GetRooms(self.account.protocol) self.assertSetEqual({r.email_address for r in ws.parse(xml)}, {'*****@*****.**', '*****@*****.**'})
def test_get_rooms(self): # The test server is not guaranteed to have any rooms or room lists which makes this test less useful roomlist = RoomList(email_address='*****@*****.**') ws = GetRooms(self.account.protocol) with self.assertRaises(ErrorNameResolutionNoResults): list(ws.call(roomlist=roomlist)) # Test shortcut with self.assertRaises(ErrorNameResolutionNoResults): list(self.account.protocol.get_rooms('*****@*****.**'))
def test_get_rooms_parsing(self): # Test static XML since server has no rooms ws = GetRooms(self.account.protocol) xml = b'''\ <?xml version="1.0" ?> <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Header> <h:ServerVersionInfo MajorBuildNumber="845" MajorVersion="15" MinorBuildNumber="22" MinorVersion="1" Version="V2016_10_10" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/> </s:Header> <s:Body> <m:GetRoomsResponse ResponseClass="Success" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"> <m:ResponseCode>NoError</m:ResponseCode> <m:Rooms> <t:Room> <t:Id> <t:Name>room1</t:Name> <t:EmailAddress>[email protected]</t:EmailAddress> <t:RoutingType>SMTP</t:RoutingType> <t:MailboxType>Mailbox</t:MailboxType> </t:Id> </t:Room> <t:Room> <t:Id> <t:Name>room2</t:Name> <t:EmailAddress>[email protected]</t:EmailAddress> <t:RoutingType>SMTP</t:RoutingType> <t:MailboxType>Mailbox</t:MailboxType> </t:Id> </t:Room> </m:Rooms> </m:GetRoomsResponse> </s:Body> </s:Envelope>''' header, body = ws._get_soap_parts(response=MockResponse(xml)) res = ws._get_elements_in_response(response=ws._get_soap_messages( body=body)) self.assertSetEqual( { Room.from_xml(elem=elem, account=None).email_address for elem in res }, {'*****@*****.**', '*****@*****.**'})
def test_invalid_server_version(self): # Test that we get a client-side error if we call a service that was only implemented in a later version version = mock_version(build=EXCHANGE_2007) account = mock_account(version=version, protocol=mock_protocol(version=version, service_endpoint='example.com')) with self.assertRaises(NotImplementedError): list(GetServerTimeZones(protocol=account.protocol).call()) with self.assertRaises(NotImplementedError): list(GetRoomLists(protocol=account.protocol).call()) with self.assertRaises(NotImplementedError): list(GetRooms(protocol=account.protocol).call('XXX'))
def booking_get(): # noqa: E501 # 获取所有的房间信息 db_session = None if "DEVMODE" in os.environ: if os.environ["DEVMODE"] == "True": db_session = orm.init_db(os.environ["DEV_DATABASEURI"]) else: db_session = orm.init_db(os.environ["DATABASEURI"]) else: db_session = orm.init_db(os.environ["DATABASEURI"]) validation_result = wxLogin.validateUser() if not validation_result["result"]: db_session.remove() return {"error": "Failed to validate access token"}, 401 response = [] roomLists = db_session.query(orm.Config_db).filter( orm.Config_db.name == 'roomLists').one_or_none().value roomDescriptions = db_session.query(orm.Config_db).filter( orm.Config_db.name == 'roomDescriptions').one_or_none().value try: for roomList in roomLists: roomsEWS = GetRooms(protocol=account.protocol).call( roomlist=RoomList(email_address=roomList['email'])) rooms = [] for room in roomsEWS: roomCode = room.email_address.split("@")[0] rooms.append({ 'name': room.name, 'roomCode': roomCode, 'email': room.email_address, 'description': roomDescriptions.get(roomCode, "") }) entry = {'listname': roomList['name'], 'rooms': rooms} response.append(entry) except Exception as e: db_session.remove() return { "error": str(e) }, 400, { "Authorization": validation_result["access_token"], "refresh_token": validation_result["refresh_token"] } db_session.remove() return response, 200, { "Authorization": validation_result["access_token"], "refresh_token": validation_result["refresh_token"] }
def miniprogram_booking_get(): db_session = None if "DEVMODE" in os.environ: if os.environ["DEVMODE"] == "True": db_session = orm.init_db(os.environ["DEV_DATABASEURI"]) else: db_session = orm.init_db(os.environ["DATABASEURI"]) else: db_session = orm.init_db(os.environ["DATABASEURI"]) if not weapp.getLearner(): db_session.remove() return {'code': -1001, 'message': '没有找到对应的Learner'}, 200 response = [] roomLists = json.loads(db_session.query(orm.Config_db).filter(orm.Config_db.name == 'roomLists').one_or_none().value) roomDescriptions = json.loads(db_session.query(orm.Config_db).filter(orm.Config_db.name == 'roomDescriptions').one_or_none().value) try: for roomList in roomLists: roomsEWS = GetRooms(protocol=account.protocol).call( roomlist=RoomList( email_address=roomList['email']) ) rooms = [] for room in roomsEWS: roomCode = room.email_address.split("@")[0] rooms.append({ 'name': room.name, 'roomCode': roomCode, 'email': room.email_address, 'description': roomDescriptions.get(roomCode, "") }) entry = { 'listname': roomList['name'], 'rooms': rooms } response.append(entry) except Exception as e: db_session.remove() return {'code': -2001, 'message': '获取房间列表失败', "log": str(e)}, 200 db_session.remove() return {'code': 0, 'data': response, 'message': '成功'}, 200
def test_get_rooms(self): # The test server is not guaranteed to have any rooms or room lists which makes this test less useful roomlist = RoomList(email_address='*****@*****.**') ws = GetRooms(self.config.protocol) roomlists = ws.call(roomlist=roomlist) self.assertEqual(roomlists, [])
from . import Kiosk_settings # 此处设定文件不作上传 import requests import json credentials = Credentials(Kiosk_settings.EWS_config["admin_email"], Kiosk_settings.EWS_config["admin_password"]) config = Configuration(server='outlook.office365.com', credentials=credentials) account = Account(primary_smtp_address='*****@*****.**', credentials=credentials, autodiscover=False, config=config, access_type=DELEGATE) rooms = GetRooms(protocol=account.protocol).call(roomlist=RoomList( email_address='*****@*****.**')) app = Flask(__name__) if __name__ == '__main__': app.run(debug=True, host='0.0.0.0') @app.route('/') def hello_world() -> str: res: dict = {} for room in rooms: room_account = Account(primary_smtp_address=room.email_address, credentials=credentials, config=config) res["%s" % room_account] = [] for item in room_account.calendar.all().order_by('start'):