def test_dogma_del_element(self): beliefs = {'book_title':'/bookstore/book[1]/title'} dataObject = etree.parse(StringIO(BOOKS)) d = XmlDogma('Books',beliefs,dataObject) assert_equal(d._get('/bookstore/book[1]/title'),'Everyday Italian') del d.book_title with assert_raises(XmlDogmaException): d._get('/bookstore/book[1]/title') with assert_raises(DogmaGetterSetterException): d.book_title
def dont_txxt_dogma_del_element(self): beliefs = {'book_title':'/bookstore/book[1]/title'} dataObject = etree.parse(StringIO(BOOKS)) d = XmlDogma('Books',beliefs,dataObject) assert_equal(d._get('/bookstore/book[1]/title'),'Everyday Italian') del d.book_title with assert_raises(XmlDogmaException): d._get('/bookstore/book[1]/title') with assert_raises(DogmaGetterSetterException): d.book_title
def test_dogma_del_attribute(self): beliefs = {'book_category':'/bookstore/book[1]/@category'} dataObject = etree.parse(StringIO(BOOKS)) d = XmlDogma('Books',beliefs,dataObject) assert_equal(d._get('/bookstore/book[1]/@category'),'COOKING') del d.book_category with assert_raises(XmlDogmaException): d._get('/bookstore/book[1]/@category') with assert_raises(DogmaGetterSetterException): assert_equal(d.book_category, None)
def test_dogma_get_nonexisting(self): beliefs = {'book_title':'/bookstore/book[5]/title', 'childrens_title':"""/bookstore/book[@category = 'CHILDREN']/title"""} dataObject = etree.parse(StringIO(BOOKS)) d = XmlDogma('Books',beliefs,dataObject) with assert_raises(XmlDogmaException): d._get('bzzz') with assert_raises(DogmaGetterSetterException): d.book_title with assert_raises(AttributeError): d.not_an_att
def dont_txxt_dogma_del_attribute(self): beliefs = {'book_category':'/bookstore/book[1]/@category'} dataObject = etree.parse(StringIO(BOOKS)) d = XmlDogma('Books',beliefs,dataObject) assert_equal(d._get('/bookstore/book[1]/@category'),'COOKING') del d.book_category with assert_raises(XmlDogmaException): d._get('/bookstore/book[1]/@category') with assert_raises(DogmaGetterSetterException): assert_equal(d.book_category, None)
def test_dogma_get_element(self): beliefs = { 'book_title': '/bookstore/book[1]/title', 'no_title': '/bookstore/book[5]/title', 'childrens_title': """/bookstore/book[@category = 'CHILDREN']/title""", 'childrens_year': """/bookstore/book[@category = 'CHILDREN']/year""" } dataObject = etree.parse(BytesIO(BOOKS)) d = XmlDogma('Books', beliefs, dataObject) self.assertEqual(d._get('/bookstore/book[1]/title'), 'Everyday Italian') self.assertEqual(d.book_title, 'Everyday Italian') self.assertEqual(d.childrens_title, 'Harry Potter') self.assertEqual(d.childrens_year, '2005') with self.assertRaises(DogmaGetterSetterException): d.no_title
def test_dogma_set_attribute_text(self): beliefs = {'book_category':'/bookstore/book[1]/@category'} # Set the text using _set dataObject = etree.parse(StringIO(BOOKS)) d = XmlDogma('Books',beliefs,dataObject) assert_equal(d._get('/bookstore/book[1]/@category'),'COOKING') d._set('/bookstore/book[1]/@category','FOOBAR') assert_equal(d._get('/bookstore/book[1]/@category'),'FOOBAR') # Set using the attribute dataObject = etree.parse(StringIO(BOOKS)) d = XmlDogma('Books',beliefs,dataObject) assert_equal(d._get('/bookstore/book[1]/@category'),'COOKING') d.book_category = 'CLEANING' assert_equal(d._get('/bookstore/book[1]/@category'),'CLEANING')
def dont_txxt_dogma_set_attribute_text(self): beliefs = {'book_category':'/bookstore/book[1]/@category'} # Set the text using _set dataObject = etree.parse(StringIO(BOOKS)) d = XmlDogma('Books',beliefs,dataObject) assert_equal(d._get('/bookstore/book[1]/@category'),'COOKING') d._set('/bookstore/book[1]/@category','FOOBAR') assert_equal(d._get('/bookstore/book[1]/@category'),'FOOBAR') # Set using the attribute dataObject = etree.parse(StringIO(BOOKS)) d = XmlDogma('Books',beliefs,dataObject) assert_equal(d._get('/bookstore/book[1]/@category'),'COOKING') d.book_category = 'CLEANING' assert_equal(d._get('/bookstore/book[1]/@category'),'CLEANING')
def test_dogma_get_existing_attribute(self): beliefs = {'book_category':'/bookstore/book[1]/@category'} dataObject = etree.parse(StringIO(BOOKS)) d = XmlDogma('Books',beliefs,dataObject) assert_equal(d._get('/bookstore/book[1]/@category'),'COOKING') assert_equal(d.book_category, 'COOKING')
def dont_txxt_dogma_set_element_text(self): beliefs = { 'book_title': '/bookstore/book[1]/title', 'childrens_title': """/bookstore/book[@category = 'CHILDREN']/title""" } # Set the text using _set dataObject = etree.parse(BytesIO(BOOKS)) d = XmlDogma('Books', beliefs, dataObject) self.assertEqual(d._get('/bookstore/book[1]/title'), 'Everyday Italian') d._set('/bookstore/book[1]/title', 'Z french is better!') self.assertEqual(d._get('/bookstore/book[1]/title'), 'Z french is better!') # Set using the attribute dataObject = etree.parse(BytesIO(BOOKS)) d = XmlDogma('Books', beliefs, dataObject) self.assertEqual(d._get('/bookstore/book[1]/title'), 'Everyday Italian') d.book_title = 'Z french is better!' self.assertEqual(d._get('/bookstore/book[1]/title'), 'Z french is better!') self.assertEqual( d._get("""/bookstore/book[@category = 'CHILDREN']/title"""), 'Harry Potter') d.childrens_title = 'potter harry' self.assertEqual( d._get("""/bookstore/book[@category = 'CHILDREN']/title"""), 'potter harry')
def test_dogma_get_element(self): beliefs = {'book_title':'/bookstore/book[1]/title', 'no_title':'/bookstore/book[5]/title', 'childrens_title':"""/bookstore/book[@category = 'CHILDREN']/title""", 'childrens_year':"""/bookstore/book[@category = 'CHILDREN']/year"""} dataObject = etree.parse(StringIO(BOOKS)) d = XmlDogma('Books',beliefs,dataObject) assert_equal(d._get('/bookstore/book[1]/title'),'Everyday Italian') assert_equal(d.book_title, 'Everyday Italian') assert_equal(d.childrens_title, 'Harry Potter') assert_equal(d.childrens_year, '2005') with assert_raises(DogmaGetterSetterException): d.no_title
def test_dogma_set_element_text(self): beliefs = {'book_title':'/bookstore/book[1]/title', 'childrens_title':"""/bookstore/book[@category = 'CHILDREN']/title"""} # Set the text using _set dataObject = etree.parse(StringIO(BOOKS)) d = XmlDogma('Books',beliefs,dataObject) assert_equal(d._get('/bookstore/book[1]/title'),'Everyday Italian') d._set('/bookstore/book[1]/title','Z french is better!') assert_equal(d._get('/bookstore/book[1]/title'),'Z french is better!') # Set using the attribute dataObject = etree.parse(StringIO(BOOKS)) d = XmlDogma('Books',beliefs,dataObject) assert_equal(d._get('/bookstore/book[1]/title'),'Everyday Italian') d.book_title = 'Z french is better!' assert_equal(d._get('/bookstore/book[1]/title'),'Z french is better!') assert_equal(d._get("""/bookstore/book[@category = 'CHILDREN']/title"""),'Harry Potter') d.childrens_title = 'potter harry' assert_equal(d._get("""/bookstore/book[@category = 'CHILDREN']/title"""),'potter harry')