Exemplo n.º 1
0
class TestChoiceOptionWithDefault(TestChoiceOptionNoDefault):
    """Tests ChoiceOption with a default value."""
    def setUp(self):
        self.option = ChoiceOption([
            'hello',
            'world',
        ], 'hello')

    def test_default(self):
        """Tests that the default was set correctly."""
        self.assertEqual(self.option.default, 'hello')

    def test_schema(self):
        """Tests a ChoiceOption schema method."""
        expected = {
            'default': 'hello',
            'enum': [
                'hello',
                'world',
            ],
        }
        self.assertRaises(ValidationError, validate, 'error',
                          self.option.schema())
        self.assertIsNone(validate('world', self.option.schema()))
        self.assertDictEqual(self.option.schema(), expected)
Exemplo n.º 2
0
class TestChoiceOptionWithDefault(TestChoiceOptionNoDefault):
    """Tests ChoiceOption with a default value."""

    def setUp(self):
        self.option = ChoiceOption(["hello", "world"], "hello")

    def test_default(self):
        """Tests that the default was set correctly."""
        self.assertEqual(self.option.default, "hello")

    def test_schema(self):
        """Tests a ChoiceOption schema method."""
        expected = {"default": "hello", "enum": ["hello", "world"]}
        self.assertRaises(ValidationError, validate, "error", self.option.schema())
        self.assertIsNone(validate("world", self.option.schema()))
        self.assertDictEqual(self.option.schema(), expected)
Exemplo n.º 3
0
class TestChoiceOptionNoDefault(unittest.TestCase, OptionTest):
    """Tests ChoiceOption without a default value."""

    valid_success = ["hello", "world"]
    valid_failure = ["hello1", "1hello", "w0rld"]

    encode_success = zip(valid_success, valid_success)

    decode_success = zip(valid_success, valid_success)
    decode_failure = valid_failure

    def setUp(self):
        self.option = ChoiceOption(["hello", "world"])

    def test_schema(self):
        """Tests a ChoiceOption schema method."""
        expected = {"enum": ["hello", "world"]}
        self.assertRaises(ValidationError, validate, "error", self.option.schema())
        self.assertIsNone(validate("world", self.option.schema()))
        self.assertDictEqual(self.option.schema(), expected)
Exemplo n.º 4
0
class TestChoiceOptionNoDefault(unittest.TestCase, OptionTest):
    """Tests ChoiceOption without a default value."""

    valid_success = [
        'hello',
        'world',
    ]
    valid_failure = [
        'hello1',
        '1hello',
        'w0rld',
    ]

    encode_success = zip(valid_success, valid_success)

    decode_success = zip(valid_success, valid_success)
    decode_failure = valid_failure

    def setUp(self):
        self.option = ChoiceOption([
            'hello',
            'world',
        ])

    def test_schema(self):
        """Tests a ChoiceOption schema method."""
        expected = {
            'enum': [
                'hello',
                'world',
            ],
        }
        self.assertRaises(ValidationError, validate, 'error',
                          self.option.schema())
        self.assertIsNone(validate('world', self.option.schema()))
        self.assertDictEqual(self.option.schema(), expected)
Exemplo n.º 5
0
 def setUp(self):
     self.option = ChoiceOption([
         'hello',
         'world',
     ], 'hello')
Exemplo n.º 6
0
 def setUp(self):
     self.option = ChoiceOption(["hello", "world"], "hello")