def test_fromElementOneField(self): element = domish.Element((NS_X_DATA, 'x')) element.addElement('field') form = Form.fromElement(element) self.assertEquals(1, len(form.fieldList)) self.assertNotIn('field', form.fields)
def test_fromElementOneField(self): element = domish.Element((NS_X_DATA, 'x')) element.addElement('field') form = Form.fromElement(element) self.assertEquals(1, len(form.fieldList)) self.assertNotIn('field', form.fields)
def test_fromElementInstructions2(self): element = domish.Element((NS_X_DATA, 'x')) element.addElement('instructions', content='instruction 1') element.addElement('instructions', content='instruction 2') form = Form.fromElement(element) self.assertEquals(['instruction 1', 'instruction 2'], form.instructions)
def test_fromElementInstructions2(self): element = domish.Element((NS_X_DATA, 'x')) element.addElement('instructions', content='instruction 1') element.addElement('instructions', content='instruction 2') form = Form.fromElement(element) self.assertEquals(['instruction 1', 'instruction 2'], form.instructions)
def test_fromElementTwoFields(self): element = domish.Element((NS_X_DATA, 'x')) element.addElement('field')['var'] = 'field1' element.addElement('field')['var'] = 'field2' form = Form.fromElement(element) self.assertEquals(2, len(form.fieldList)) self.assertIn('field1', form.fields) self.assertEquals('field1', form.fieldList[0].var) self.assertIn('field2', form.fields) self.assertEquals('field2', form.fieldList[1].var)
def test_fromElementTwoFields(self): element = domish.Element((NS_X_DATA, 'x')) element.addElement('field')['var'] = 'field1' element.addElement('field')['var'] = 'field2' form = Form.fromElement(element) self.assertEquals(2, len(form.fieldList)) self.assertIn('field1', form.fields) self.assertEquals('field1', form.fieldList[0].var) self.assertIn('field2', form.fields) self.assertEquals('field2', form.fieldList[1].var)
def test_fromElement(self): """ The fromElement static method creates a L{Form} from a L{DOM. """ element = domish.Element((NS_X_DATA, 'x')) element['type'] = 'result' form = Form.fromElement(element) self.assertEquals('result', form.formType) self.assertEquals(None, form.title) self.assertEquals([], form.instructions) self.assertEquals({}, form.fields)
def test_fromElement(self): """ The fromElement static method creates a L{Form} from a L{DOM. """ element = domish.Element((NS_X_DATA, 'x')) element['type'] = 'result' form = Form.fromElement(element) self.assertEquals('result', form.formType) self.assertEquals(None, form.title) self.assertEquals([], form.instructions) self.assertEquals({}, form.fields)
def process_stats(item): """ Process result of user-stats command Extract IP address and related info and returns it as dict """ x = xpath.queryForNodes("//x/field[@var='ipaddresses']",item) if not x: raise ValueError, "Wrong response from stats-request" frm = Form.fromElement(x[0]) values = frm.getValues() jid = JID(values['accountjid']) ipport = values['ipaddresses'] ip, port = ipport.split(':') userstats = dict() userstats['username'] = jid.userhost() userstats['fulljid'] = jid.full() #full jid which causes current change, i.e. which is connestion actualy used userstats['ip'] = ip return userstats
def test_fromElementTitle(self): element = domish.Element((NS_X_DATA, 'x')) element.addElement('title', content='My title') form = Form.fromElement(element) self.assertEquals('My title', form.title)
def test_fromElementTitle(self): element = domish.Element((NS_X_DATA, 'x')) element.addElement('title', content='My title') form = Form.fromElement(element) self.assertEquals('My title', form.title)