Exemplo n.º 1
0
    def test_json_representation_is_correct(self):
        """Verify that the JSON repr of boolean properties is correct."""

        prop = properties.BooleanProperty('name', False)
        self.assertEquals(json.loads(json.dumps(prop, cls=JSONObjectEncoder)),
                          False)

        prop = properties.BooleanProperty('name', True)
        self.assertEquals(json.loads(json.dumps(prop, cls=JSONObjectEncoder)),
                          True)
Exemplo n.º 2
0
    def test_yaml_representation_has_all_expected_fields(self):
        """Verify that the YAML representation of boolean properties is ok."""

        prop = properties.BooleanProperty('name', True)
        string = yaml.dump(prop)
        data = yaml.load(string)
        self.assertTrue(isinstance(data, bool))
        self.assertEqual(data, True)

        prop = properties.BooleanProperty('name', False)
        string = yaml.dump(prop)
        data = yaml.load(string)
        self.assertTrue(isinstance(data, bool))
        self.assertEqual(data, False)
Exemplo n.º 3
0
    def boolean_property_in_data(self, context, object_entry, prop_def, data):
        """Return a boolean property from an object properties dictionary."""

        if not isinstance(data, bool):
            context.error(
                BooleanPropertyValueInvalidError(context, prop_def.name, data))

        return properties.BooleanProperty(prop_def.name, data)
Exemplo n.º 4
0
    def test_equality_operator_is_false_for_different_property_types(self):
        """Verify == is false when comparing properties of different types."""

        test_properties = [
            properties.IntProperty('name', 5),
            properties.BooleanProperty('name', True),
            properties.FloatProperty('name', 5.0),
            properties.TextProperty('name', '5'), 1, 2.0, 'some text'
        ]

        for p1, p2 in itertools.permutations(test_properties, 2):
            self.assertNotEqual(p1, p2)
            self.assertFalse(p1 == p2)
Exemplo n.º 5
0
    def test_constructor_sets_property_name_and_value_properly(self):
        """Verify that the constructor sets property name and value."""

        test_input = [
            ('property1', True),
            ('property2', False),
            ('property3', True),
        ]

        for name, value in test_input:
            boolean_property = properties.BooleanProperty(name, value)
            self.assertEqual(boolean_property.name, name)
            self.assertEqual(boolean_property.value, value)
Exemplo n.º 6
0
    def setUp(self):
        """Initialise helper variables for the tests."""

        self.test_input = [
            ('hash1', '5e27f17c-ff22-4c49-82d9-6549f2800d1a',
             objects.ObjectClass('someclass', []), []),
            ('hash2', 'ad791799-4c3a-4cac-a07d-43493baab121',
             objects.ObjectClass('someclass', []), [
                 properties.TextProperty('title', 'Title'),
                 properties.TextProperty('info', 'Info'),
                 properties.FloatProperty('amount', 237.5),
                 properties.BooleanProperty('important', False),
                 properties.IntProperty('count', 5),
                 properties.TimestampProperty('date', '1377703755 +0100'),
                 properties.ReferenceProperty(
                     'others',
                     set([
                         references.Reference('a', None, None),
                         references.Reference('b', None, None),
                         references.Reference('c', None, None),
                     ])),
                 properties.ListProperty('tags', ['tag-1', 'tag-2', 'tag-3']),
             ]),
        ]
Exemplo n.º 7
0
    def test_input_value_is_converted_to_boolean(self):
        """Verify that the input value is converted to an boolean."""

        test_input = [
            (0, False),
            (1, True),
            (0.0, False),
            (1.0, True),
            ('0', True),
            ('1', True),
            ('', False),
            ([], False),
            ({}, False),
            ([1], True),
            ({
                0: 1
            }, True),
        ]

        for value, bool_value in test_input:
            boolean_property = properties.BooleanProperty('name', value)
            self.assertTrue(isinstance(boolean_property.value, bool))
            self.assertEqual(type(boolean_property.value), type(True))
            self.assertEqual(boolean_property.value, bool_value)