def test_data_object_dict_fail_can_handle_invalid_tag(self):
        '''Validate that can_handle fails using an invalid tag name'''
        indentation = '''\
        '''
        TEST_XML = '''\
        <bad_data_dictionary name="test_dictionary_xml">
          <data name="name1">value1</data>
          <data name="name2">value2</data>
          <data name="name3">value3</data>
          <data name="name4">value4</data>
          <data name="name5">value5</data>
        </bad_data_dictionary>
        '''.replace(indentation, "")

        # Parse the XML into an XML tree.
        xml_tree = etree.fromstring(TEST_XML)

        self.assertFalse(
            DataObjectDict.can_handle(xml_tree),
            "can_handle returned True when given a bad tag: %s" % (TEST_XML))
    def test_data_object_dict_val_attr_fail_can_handle_invalid_tag(self):
        '''Validate that can_handle fails using an invalid value attr name'''
        indentation = '''\
        '''
        TEST_XML = '''\
        <data_dictionary name="test_dictionary_xml">
          <data name="name1" bad_value="value1"/>
          <data name="name2" bad_value="value2"/>
          <data name="name3" bad_value="value3"/>
          <data name="name4" bad_value="value4"/>
          <data name="name5" bad_value="value5"/>
        </data_dictionary>
        '''.replace(indentation, "")

        # Parse the XML(value attr) into an XML tree.
        xml_tree = etree.fromstring(TEST_XML)

        self.assertFalse(
            DataObjectDict.can_handle(xml_tree),
            "can_handle returned True when given a bad value attr: %s" %
            (TEST_XML))
    def test_data_object_dict_val_attr_xml_default_no_name(self):
        '''Validate that from_xml() imports XML(value attr) if no name for tag
        '''
        # Set expected xml, and compensate for indent
        indentation = '''\
        '''
        TEST_XML = '''\
        <data_dictionary>
          <data name="name1" value="value1"/>
          <data name="name2" value="value2"/>
          <data name="name3" value="value3"/>
          <data name="name4" value="value4"/>
          <data name="name5" value="value5"/>
        </data_dictionary>
        '''.replace(indentation, "")

        # Parse the XML(value attr) into an XML tree.
        xml_tree = etree.fromstring(TEST_XML)

        if DataObjectDict.can_handle(xml_tree):
            new_obj = DataObjectDict.from_xml(xml_tree)
            self.assertTrue(new_obj != None,
                            "Failed to create DataObjectDict from XML")
            self.assertEquals(new_obj.name, None,
                              "new object's name is not None.")
            self.assertEquals(type(new_obj.data_dict), dict,
                              "new object's data_dict is not a data_dict.")
            self.assertEquals(new_obj.data_dict["name1"], "value1",
                              "new object's name1 doesn't have correct value")
            self.assertEquals(new_obj.data_dict["name2"], "value2",
                              "new object's name2 doesn't have correct value")
            self.assertEquals(new_obj.data_dict["name3"], "value3",
                              "new object's name3 doesn't have correct value")
            self.assertEquals(new_obj.data_dict["name4"], "value4",
                              "new object's name4 doesn't have correct value")
            self.assertEquals(new_obj.data_dict["name5"], "value5",
                              "new object's name5 doesn't have correct value")
        else:
            self.fail("can_handle returned False, expected True!")