def test_fad_dir_method(self):
        fad = FixedAttrsDict(
            MagicMock(),
            properties={'href': 1, '_some_property': 2, 'some_property': 3})

        self.assertEqual(
            {'href', '_some_property', 'some_property'}, set(fad.__dir__()))
    def test_fad_init(self):
        fad = FixedAttrsDict(MagicMock(), properties={'a': 1, 'b': 2})

        # getting a non-existing attribute is handled correctly
        with self.assertRaises(AttributeError):
            fad.a = 2
        # non-existing attribute access is handled correctly
        with self.assertRaises(AttributeError):
            fad.foo
示例#3
0
    def test_fad_init(self):
        fad = FixedAttrsDict(MagicMock(), properties={'a': 1, 'b': 2})

        # getting a non-existing attribute is handled correctly
        with self.assertRaises(AttributeError):
            fad.a = 2
        # non-existing attribute access is handled correctly
        with self.assertRaises(AttributeError):
            fad.foo
示例#4
0
    def test_fad_dir_method(self):
        fad = FixedAttrsDict(MagicMock(),
                             properties={
                                 'href': 1,
                                 '_some_property': 2,
                                 'some_property': 3
                             })

        self.assertEqual({'href', '_some_property', 'some_property'},
                         set(fad.__dir__()))
    def test_wrapping_resource_attrs(self):
        r = FixedAttrsDict(MagicMock(), properties={})
        to_wrap = FixedAttrsDict(MagicMock(), properties={})
        ret = r._wrap_resource_attr(AgentConfig, to_wrap)
        self.assertEqual(to_wrap, ret)

        ret = r._wrap_resource_attr(AgentConfig, {'poll_interval': 60})
        self.assertEqual(60, ret.poll_interval)
        self.assertTrue(isinstance(ret, AgentConfig))

        ret = r._wrap_resource_attr(AgentConfig, None)
        self.assertIsNone(ret)

        self.assertRaises(
            TypeError, r._wrap_resource_attr, AgentConfig,
            'Unsupported Conversion')
示例#6
0
    def test_getting_fad_property_names(self):
        fad = FixedAttrsDict(MagicMock(),
                             properties={
                                 'href': 1,
                                 '_some_property': 2,
                                 'some_property': 3
                             })

        self.assertEqual(set(fad.__dict__.keys()),
                         {'href', '_some_property', 'some_property'})
示例#7
0
    def test_wrapping_resource_attrs(self):
        r = FixedAttrsDict(MagicMock(), properties={})
        to_wrap = FixedAttrsDict(MagicMock(), properties={})
        ret = r._wrap_resource_attr(AgentConfig, to_wrap)
        self.assertEqual(to_wrap, ret)

        ret = r._wrap_resource_attr(AgentConfig, {'poll_interval': 60})
        self.assertEqual(60, ret.poll_interval)
        self.assertTrue(isinstance(ret, AgentConfig))

        ret = r._wrap_resource_attr(AgentConfig, None)
        self.assertIsNone(ret)

        self.assertRaises(TypeError, r._wrap_resource_attr, AgentConfig,
                          'Unsupported Conversion')
 def test_sanitize_property(self):
     ret = FixedAttrsDict._sanitize_property({'full_name': 'full name'})
     self.assertEqual({'fullName': 'full name'}, ret)
示例#9
0
 def test_sanitize_property(self):
     ret = FixedAttrsDict._sanitize_property({'full_name': 'full name'})
     self.assertEqual({'fullName': 'full name'}, ret)