Exemplo n.º 1
0
    def test_validate_length(self):
        good_duid_object = EnterpriseDUID(0, 124 * b'x')
        good_duid_object.validate()

        bad_duid_object = EnterpriseDUID(0, 125 * b'x')
        with self.assertRaisesRegex(ValueError, 'cannot be longer than 124 bytes'):
            bad_duid_object.validate()
Exemplo n.º 2
0
    def test_validate_length(self):
        good_duid_object = EnterpriseDUID(0, 122 * b'x')
        good_duid_object.validate()

        bad_duid_object = EnterpriseDUID(0, 123 * b'x')
        with self.assertRaisesRegex(ValueError,
                                    'cannot be longer than 122 bytes'):
            bad_duid_object.validate()
Exemplo n.º 3
0
def duid_en(section) -> EnterpriseDUID:
    """
    Create a EnterpriseDUID from the data provided in the config section.

    :param section: The section data
    :return: The DUID object
    """
    duid = EnterpriseDUID(enterprise_number=section.enterprise_number,
                          identifier=section.identifier)
    duid.validate()
    return duid
Exemplo n.º 4
0
    def test_validate_enterprise_number(self):
        good_duid_object = EnterpriseDUID(0, b'demo')
        good_duid_object.validate()

        bad_duid_object = EnterpriseDUID(-1, b'demo')
        with self.assertRaisesRegex(ValueError, 'unsigned 32 bit integer'):
            bad_duid_object.validate()

        bad_duid_object = EnterpriseDUID(2**32, b'demo')
        with self.assertRaisesRegex(ValueError, 'unsigned 32 bit integer'):
            bad_duid_object.validate()
Exemplo n.º 5
0
    def test_validate_enterprise_number(self):
        good_duid_object = EnterpriseDUID(0, b'demo')
        good_duid_object.validate()

        bad_duid_object = EnterpriseDUID(-1, b'demo')
        with self.assertRaisesRegex(ValueError, 'unsigned 32 bit integer'):
            bad_duid_object.validate()

        bad_duid_object = EnterpriseDUID(2 ** 32, b'demo')
        with self.assertRaisesRegex(ValueError, 'unsigned 32 bit integer'):
            bad_duid_object.validate()
Exemplo n.º 6
0
 def test_validate_identifier(self):
     # noinspection PyTypeChecker
     bad_duid_object = EnterpriseDUID(0, 'demo')
     with self.assertRaisesRegex(ValueError, 'sequence of bytes'):
         bad_duid_object.validate()
Exemplo n.º 7
0
 def test_validate_identifier(self):
     # noinspection PyTypeChecker
     bad_duid_object = EnterpriseDUID(0, 'demo')
     with self.assertRaisesRegex(ValueError, 'sequence of bytes'):
         bad_duid_object.validate()