Esempio n. 1
0
    def test_init_update(self):
        """Test __init__ and update."""
        with self.assertRaises(ValueError):
            a = radius.Attributes({'foo': b'bar'})

        a = radius.Attributes({'User-Name': b'foobar'})
        self.assertEqual([b'foobar'], a['User-Name'])

        with self.assertRaises(ValueError):
            a.update({'foo': b'bar'})

        a.update({'User-Password': b'raboof'})
        self.assertEqual([b'foobar'], a['User-Name'])
        self.assertEqual([b'raboof'], a['User-Password'])
Esempio n. 2
0
 def test_un_pack(self):
     """Test packing and unpacking attributes."""
     a = radius.Attributes()
     a['User-Name'] = b'foobar'
     a['User-Password'] = b'raboof'
     data = a.pack()
     self.assertEqual(16, len(data))
     b = radius.Attributes.unpack(data)
     self.assertEqual(2, len(b))
     self.assertEqual([b'foobar'], b['User-Name'])
     self.assertEqual([b'raboof'], b['User-Password'])
Esempio n. 3
0
    def test_set_get_item(self):
        """Test setting and getting items."""
        a = radius.Attributes()

        # Cannot use invalid radius codes or names.
        with self.assertRaises(ValueError):
            a[128] = b'bar'

        with self.assertRaises(ValueError):
            a['foo'] = b'bar'

        with self.assertRaises(KeyError):
            a['User-Name']

        a['User-name'] = b'foobar'
        self.assertEqual([b'foobar'], a[radius.ATTR_USER_NAME])
        self.assertEqual([b'foobar'], a['user-name'])
        self.assertEqual([b'foobar'], a['user-Name'])
Esempio n. 4
0
    def test_set_get_item(self):
        """Test setting and getting items."""
        a = radius.Attributes()

        # Can use unknown radius codes.
        a[128] = b'bar'

        # Cannot use invalid radius names.
        with self.assertRaises(ValueError):
            a['foo'] = b'bar'

        with self.assertRaises(KeyError):
            a['User-Name']

        a['User-name'] = b'foobar'
        self.assertEqual([b'foobar'], a[radius.ATTR_USER_NAME])
        self.assertEqual([b'foobar'], a['user-name'])
        self.assertEqual([b'foobar'], a['user-Name'])
        self.assertEqual(
            [(None, ['bar']), ('User-Name', ['foobar'])], list(a.nameditems()))