def setUp(self): self.pool = HTTPConnectionPool(reactor, persistent=False) self.client = HTTPClient.with_config(pool=self.pool, allow_redirects=False, reactor=reactor) self.resource = TxSyncMLResource(reactor) self.site = server.Site(self.resource) self.listener = reactor.listenTCP(0, self.site, interface='localhost') self.listener_port = self.listener.getHost().port self.fixtures = FixtureHelper() self.addCleanup(self.listener.loseConnection) self.addCleanup(self.pool.closeCachedConnections)
class WbXmlCodecTestCase(TxSyncMLTestCase): def setUp(self): self.codec = WbXmlCodec() self.fixtures = FixtureHelper() @inlineCallbacks def test_decode(self): wbxml = self.fixtures.get_fixture('client_sync_init.wbxml') xml = yield self.codec.decode(wbxml) dom = microdom.parseXMLString(xml) [ver_proto] = dom.getElementsByTagName('VerProto') self.assertEqual(ver_proto.firstChild().value, 'SyncML/1.1') @inlineCallbacks def test_encode(self): wbxml = self.fixtures.get_fixture('client_sync_init.wbxml') xml = self.fixtures.get_fixture('client_sync_init.xml') codec_wbxml = yield self.codec.encode(xml) self.assertEqual(wbxml, codec_wbxml)
def setUp(self): self.pool = HTTPConnectionPool(reactor, persistent=False) self.client = HTTPClient.with_config( pool=self.pool, allow_redirects=False, reactor=reactor) self.resource = TxSyncMLResource(reactor) self.site = server.Site(self.resource) self.listener = reactor.listenTCP(0, self.site, interface='localhost') self.listener_port = self.listener.getHost().port self.fixtures = FixtureHelper() self.addCleanup(self.listener.loseConnection) self.addCleanup(self.pool.closeCachedConnections)
class WbXmlTestCase(TxSyncMLTestCase): def setUp(self): self.fixtures = FixtureHelper() self.client = SyncMLClientHelper() @inlineCallbacks def test_encode_decode(self): # FIXME: this test is rather weak fixture_xml = self.fixtures.get_fixture('client_sync_init.xml') wbxml = yield xml2wbxml(fixture_xml) xml = yield wbxml2xml(wbxml) dom = microdom.parseXMLString(xml) [ver_proto] = dom.getElementsByTagName('VerProto') self.assertEqual(ver_proto.firstChild().value, 'SyncML/1.1') @inlineCallbacks def test_build_client_sync_init(self): codec = WbXmlCodec() syncml = self.client.build_request() wbxml = yield codec.encode(syncml.build().toXml()) expected_wbxml = self.fixtures.get_fixture('client_sync_init.wbxml') self.assertEqual(wbxml, expected_wbxml)
class SyncMLParserTestCase(TxSyncMLTestCase): def setUp(self): self.fixtures = FixtureHelper() def test_header_parsing(self): data = self.fixtures.get_fixture('client_sync_init.xml') doc = SyncMLParser.parse(data) [header] = doc.find('SyncHdr') [verdtd] = header.find('VerDTD') self.assertEqual(verdtd.value, '1.1') [verproto] = header.find('VerProto') self.assertEqual(verproto.value, 'SyncML/1.1') [session_id] = header.find('SessionID') self.assertEqual(session_id.value, '1') [msg_id] = header.find('MsgID') self.assertEqual(msg_id.value, '1') [target] = header.find('Target') [target_locuri] = target.find('LocURI') self.assertEqual(target_locuri.value, 'http://www.syncml.org/sync-server')
class SyncMLParserTestCase(TxSyncMLTestCase): def setUp(self): self.fixtures = FixtureHelper() def test_header_parsing(self): data = self.fixtures.get_fixture('client_sync_init.xml') doc = SyncMLParser.parse(data) [header] = doc.find('SyncHdr') [verdtd] = header.find('VerDTD') self.assertEqual(verdtd.value, '1.1') [verproto] = header.find('VerProto') self.assertEqual(verproto.value, 'SyncML/1.1') [session_id] = header.find('SessionID') self.assertEqual(session_id.value, '1') [msg_id] = header.find('MsgID') self.assertEqual(msg_id.value, '1') [target] = header.find('Target') [target_locuri] = target.find('LocURI') self.assertEqual( target_locuri.value, 'http://www.syncml.org/sync-server')
class TxSyncMLTestCase(TxSyncMLTestCase): content_type = 'application/vnd.syncml+xml' codec = XmlCodec def setUp(self): self.pool = HTTPConnectionPool(reactor, persistent=False) self.client = HTTPClient.with_config( pool=self.pool, allow_redirects=False, reactor=reactor) self.resource = TxSyncMLResource(reactor) self.site = server.Site(self.resource) self.listener = reactor.listenTCP(0, self.site, interface='localhost') self.listener_port = self.listener.getHost().port self.fixtures = FixtureHelper() self.addCleanup(self.listener.loseConnection) self.addCleanup(self.pool.closeCachedConnections) def make_url(self, *paths): return 'http://localhost:%s/%s' % ( self.listener_port, ('/'.join(map(str, paths)) + '/' if paths else '')) def request_with_fixture(self, fixture_name, headers={}): return self.request(self.fixtures.get_fixture(fixture_name), headers) def request(self, data, headers={}): default_headers = { 'Content-Type': [self.content_type], } default_headers.update(headers) d = self.encode_request_data(data) d.addCallback( lambda data: self.client.post(self.make_url(), data=data, headers=default_headers)) return d def encode_request_data(self, data): return self.codec().encode(data)
class TxSyncMLTestCase(TxSyncMLTestCase): content_type = 'application/vnd.syncml+xml' codec = XmlCodec def setUp(self): self.pool = HTTPConnectionPool(reactor, persistent=False) self.client = HTTPClient.with_config(pool=self.pool, allow_redirects=False, reactor=reactor) self.resource = TxSyncMLResource(reactor) self.site = server.Site(self.resource) self.listener = reactor.listenTCP(0, self.site, interface='localhost') self.listener_port = self.listener.getHost().port self.fixtures = FixtureHelper() self.addCleanup(self.listener.loseConnection) self.addCleanup(self.pool.closeCachedConnections) def make_url(self, *paths): return 'http://localhost:%s/%s' % (self.listener_port, ('/'.join(map(str, paths)) + '/' if paths else '')) def request_with_fixture(self, fixture_name, headers={}): return self.request(self.fixtures.get_fixture(fixture_name), headers) def request(self, data, headers={}): default_headers = { 'Content-Type': [self.content_type], } default_headers.update(headers) d = self.encode_request_data(data) d.addCallback(lambda data: self.client.post( self.make_url(), data=data, headers=default_headers)) return d def encode_request_data(self, data): return self.codec().encode(data)
def setUp(self): self.fixtures = FixtureHelper()
def setUp(self): self.fixtures = FixtureHelper() self.client = SyncMLClientHelper()
def setUp(self): self.codec = WbXmlCodec() self.fixtures = FixtureHelper()