def testNamingFieldAppendRejectsBad(self): f = policy_simple.NamingField('RFC1918') bads = ( 'corp_internal', 'CORP+INTERNAL', ) for bad in bads: logging.debug('Testing bad "%s".', bad) self.assertRaises(ValueError, f.Append, bad)
def testNamingFieldAcceptsGood(self): goods = ( 'CORP_INTERNAL', 'RFC1918', 'FOO_BAR102.BAZ101', ) for good in goods: try: logging.debug('Testing good "%s".', good) _ = policy_simple.NamingField(good) except ValueError: self.fail('Rejected good NamingField value "%s".' % good)
def testNamingFieldDedupes(self): f = policy_simple.NamingField('RFC1918 CORP_INTERNAL RFC1918') f.Append('RFC1918') f.Append('CORP_INTERNAL RFC1918') self.assertEqual(set(['RFC1918', 'CORP_INTERNAL']), f.value)
def testNamingFieldStr(self): f = policy_simple.NamingField(' '.join(str(x) for x in xrange(25))) expected_str = ('UNKNOWN:: 0 1 10 11 12 13 14 15 16 17 18 19 2 20 21' ' 22 23 24 3 4 5 6 7\n 9') self.assertEqual(expected_str, str(f))