def testElementHandling(self): blip = self.new_blip(blipId=ROOT_BLIP_ID) url = 'http://www.test.com/image.png' org_len = len(blip) blip.append(element.Image(url=url)) elems = [elem for elem in blip.find(element.Image, url=url)] self.assertEquals(1, len(elems)) elem = elems[0] self.assertTrue(isinstance(elem, element.Image)) blip.at(1).insert('twelve chars') self.assertTrue(blip.text.startswith('\ntwelve charshello')) elem = blip[org_len + 12].value() self.assertTrue(isinstance(elem, element.Image)) blip.first('twelve ').delete() self.assertTrue(blip.text.startswith('\nchars')) elem = blip[org_len + 12 - len('twelve ')].value() self.assertTrue(isinstance(elem, element.Image)) blip.first('chars').replace(element.Image(url=url)) elems = [elem for elem in blip.find(element.Image, url=url)] self.assertEquals(2, len(elems)) self.assertTrue(blip.text.startswith('\n hello')) elem = blip[1].value() self.assertTrue(isinstance(elem, element.Image))
def testDocumentOperations(self): blip = self.new_blip(blipId=ROOT_BLIP_ID) newlines = [x for x in blip.find('\n')] self.assertEquals(2, len(newlines)) blip.first('world').replace('jupiter') bits = blip.text.split('\n') self.assertEquals(3, len(bits)) self.assertEquals('hello jupiter!', bits[1]) blip.range(2, 5).delete() self.assertBlipStartswith('\nho jupiter', blip) blip.first('ho').insert_after('la') self.assertBlipStartswith('\nhola jupiter', blip) blip.at(3).insert(' ') self.assertBlipStartswith('\nho la jupiter', blip)