This branch is based on lp:~adeuring/launchpad/hwdb-submissions-with-udev-data and adds some tests for the changed RelaxNG schema for HWDB submissions. (see also the MP https://code.edge.launchpad.net/~adeuring/launchpad/hwdb-submissions-with-udev-data/+merge/11683 for a exlanation what this branch is about) These tests modify the existing sample submission file by inserting more data, or by replacing/removing sme data from the file. The new tests ensure that: - the new tga can be inserted into - the node can be replaced by the three node , , - may not be mixed with , , The diff against the base branch: === modified file 'lib/canonical/launchpad/scripts/tests/test_hwdb_submission_validation.py' --- lib/canonical/launchpad/scripts/tests/test_hwdb_submission_validation.py 2009-06-25 05:30:52 +0000 +++ lib/canonical/launchpad/scripts/tests/test_hwdb_submission_validation.py 2009-09-14 11:42:30 +0000 @@ -375,8 +375,20 @@ The only allowed tags are specified by the Relax NG schema: live_cd, system_id, distribution, distroseries, architecture, - private, contactable, date_created. + private, contactable, date_created (tested in + testSummaryRequiredTags()), and the optional tag . """ + # we can add the tag + sample_data = self.insertSampledata( + data=self.sample_data, + insert_text='', + where='') + result, submission_id = self.runValidator(sample_data) + self.assertNotEqual( + result, None, + 'Valid submission containing a tag rejected.') + + # Adding any other tag is not possible. sample_data = self.insertSampledata( data=self.sample_data, insert_text='', @@ -609,24 +621,100 @@ 'Invalid attribute foo for element plugin', 'invalid attribute in client plugin') - def testHardwareSubTags(self): + def testHardwareSubTagHalOrUdev(self): + """The tag requires data about hardware devices. + + This data is stored either in the sub-tag or in the + three tags , , . + """ + # Omitting leads to an error. + sample_data = self.replaceSampledata( + data=self.sample_data, + replace_text='', + from_text=' in ') + + # But we may replace by the three tags , , + #. + sample_data = self.replaceSampledata( + data=self.sample_data, + replace_text=""" + some text + some text + some text + """, + from_text=', , tags ' + 'rejected') + + def testHardwareSubTagUdevIncomplete(self): """The tag has a fixed set of allowed sub-tags. - Valid sub-tags are , , . - is optional; and are required. + Valid sub-tags are , , , , + , . is optional, + is required, and either or all three tags , , + must be present. """ - # Omitting either of the required tags leads on an error. - for tag in ('hal', 'processors'): + # Omitting any of the three tags , , + # makes the data invalid. + all_tags = ['udev', 'dmi', 'sysfs-attributes'] + for index in range(len(all_tags)): + test_tags = all_tags[:] + missing_tag = test_tags[index] + del test_tags[index] + replace_text = [ + '<%s>text' % (tag, tag) for tag in test_tags] + replace_text = ''.join(replace_text) sample_data = self.replaceSampledata( data=self.sample_data, - replace_text='', - from_text='<%s' % tag, - to_text='' % tag) - result, submission_id = self.runValidator(sample_data) - self.assertErrorMessage( - submission_id, result, - 'Expecting an element %s, got nothing' % tag, - 'missing tag <%s> in ' % tag) + replace_text=replace_text, + from_text=' in ' % missing_tag) + + def testHardwareSubTagHalMixedWithUdev(self): + """Mixing with , , is impossible. + """ + # A submission containing the tag as well as one of , + # , is invalid. + for tag in ['udev', 'dmi', 'sysfs-attributes']: + sample_data = self.insertSampledata( + data=self.sample_data, + insert_text='<%s>some text' % (tag, tag), + where=' mixed with <%s> in ' % tag) + + def testHardwareOtherSubTags(self): + """The tag has a fixed set of allowed sub-tags. + """ + # The tag must not be omitted. + sample_data = self.replaceSampledata( + data=self.sample_data, + replace_text='', + from_text=' tag omitted') # The tag may be omitted. sample_data = self.replaceSampledata( @@ -1603,23 +1691,12 @@ 'Extra element aliases in interleave', 'missing attribute of ') - # target must be an integer. + # The value of target does not have to be an integer. sample_data = self.sample_data.replace( '', '') result, submission_id = self.runValidator(sample_data) - self.assertErrorMessage( - submission_id, result, - 'Extra element aliases in interleave', - 'missing attribute of ') - - # target must not be empty. - sample_data = self.sample_data.replace( - '', '') - result, submission_id = self.runValidator(sample_data) - self.assertErrorMessage( - submission_id, result, - 'Element hardware failed to validate content', - 'missing attribute of ') + self.assertNotEqual( + result, None, ' rejected') # Other attributes are not allowed. We get again the same # quite unspecific error message as above.