Ejemplo n.º 1
0
    def test_parse_invalid_root(self):
        """
        Tests that a parsable but ill-formed descriptor throws the correct error.
        A valid descriptor is passed to show that at least one failed descriptor
        causes the parse to fail.
        """

        # Setup
        incorrect = model.TypeDescriptor('incorrect', '{"not-types" : "foo"}')

        # Test
        try:
            parser.parse([VALID_DESCRIPTOR_1, incorrect])
            self.fail('Exception not correctly thrown')
        except parser.MissingRoot, e:
            self.assertEqual(1, len(e.error_filenames()))
            self.assertEqual('incorrect', e.error_filenames()[0])
Ejemplo n.º 2
0
    def test_parse_invalid_descriptor(self):
        """
        Tests the proper exception is thrown when a descriptor cannot be parsed.
        A valid descriptor is passed to show that at least one failed descriptor
        causes the parse to fail.
        """

        # Setup
        invalid = model.TypeDescriptor('invalid', 'foo')

        # Test
        try:
            parser.parse([VALID_DESCRIPTOR_1, invalid])
            self.fail('Exception not correctly thrown')
        except parser.Unparsable, e:
            self.assertEqual(1, len(e.error_filenames()))
            self.assertEqual('invalid', e.error_filenames()[0])
            e.__str__()  # included just for coverage
Ejemplo n.º 3
0
    def test_parse_missing_attribute(self):
        """
        Tests a type definition with a missing attribute cannot be parsed.
        """

        # Setup
        no_id = model.TypeDescriptor(
            'no_id', """{"types": [
                {"display_name" : "RPM", "description" : "RPM",
                 "unit_key" : "name", "search_indexes" : "name"}
               ]}""")

        # Test
        try:
            parser.parse([VALID_DESCRIPTOR_1, no_id])
            self.fail('Exception not correctly thrown')
        except parser.MissingAttribute, e:
            self.assertEqual(1, len(e.error_filenames()))
            self.assertEqual('no_id', e.error_filenames()[0])
Ejemplo n.º 4
0
    def test_parse_invalid_type_id(self):
        """
        Tests that a type definition with a malformed ID throws the correct
        error.
        """

        # Setup
        bad_id = model.TypeDescriptor(
            'bad_id', """{"types": [
                {"id" : "bad-id", "display_name" : "RPM", "description" : "RPM",
                 "unit_key" : "name", "search_indexes" : "name"}
               ]}""")

        # Test
        try:
            parser.parse([VALID_DESCRIPTOR_1, bad_id])
            self.fail('Exception not correctly thrown')
        except parser.InvalidTypeId, e:
            self.assertEqual(1, len(e.type_ids))
            self.assertEqual('bad-id', e.type_ids[0])
Ejemplo n.º 5
0
    def test_parse_extra_attribute(self):
        """
        Tests a type definition with unexpected attributes cannot be parsed.
        """

        # Setup
        extra = model.TypeDescriptor(
            'extra', """{"types": [
                {"id" : "rpm", "display_name" : "RPM", "description" : "RPM",
                 "unit_key" : "name", "search_indexes" : "name",
                 "unexpected_attribute" : "foo"}
               ]}""")

        # Test
        try:
            parser.parse([VALID_DESCRIPTOR_1, extra])
            self.fail('Exception not correctly thrown')
        except parser.InvalidAttribute, e:
            self.assertEqual(1, len(e.error_filenames()))
            self.assertEqual('extra', e.error_filenames()[0])
Ejemplo n.º 6
0
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

import unittest

from pulp.plugins.types import parser, model

# -- test data ---------------------------------------------------------------

VALID_DESCRIPTOR_1 = model.TypeDescriptor(
    'valid_descriptor_1', """{"types": [
    {"id" : "rpm",
     "display_name" : "RPM",
     "description" : "Yum RPM package",
     "unit_key" : ["name", "version", "release", "arch", "filename", "checksum"],
     "search_indexes" : [
         ["name", "epoch", "version", "release", "arch"],
         "filename"
     ]}
   ]}
""")

VALID_DESCRIPTOR_2 = model.TypeDescriptor(
    'valid_descriptor_2', """{"types": [
    {"id" : "deb",
     "display_name" : "DEB",
     "description" : "Debian package",
     "unit_key" : "name",
     "search_indexes" : [
         ["name", "filename"], "filename"
     ]}