1 from ctypescrypto.oid import Oid,create,cleanup
4 class TestStandard(unittest.TestCase):
7 self.assertEqual(repr(o),"Oid('2.5.4.3')")
8 self.assertEqual(o.dotted(),"2.5.4.3")
9 self.assertEqual(str(o),"2.5.4.3")
10 self.assertEqual(o.shortname(),"CN")
11 self.assertEqual(o.longname(),"commonName")
12 def test_getnid(self):
15 self.assertEqual(o.nid,x.nid)
17 self.assertEqual(hash(o),hash(x))
22 self.assertEqual(o.nid,x.nid)
26 self.assertEqual(o.nid,x.nid)
30 self.assertEqual(o1.nid,o2.nid)
31 def test_fromunicode(self):
33 self.assertEqual(o.shortname(),'CN')
34 def test_wrongoid(self):
35 with self.assertRaises(ValueError):
36 o=Oid("1.2.3.4.5.6.7.8.10.111.1111")
37 def test_wrongname(self):
38 with self.assertRaises(ValueError):
39 o=Oid("No such oid in the database")
40 def test_wrongnid(self):
41 with self.assertRaises(ValueError):
43 def test_wrongtype(self):
44 with self.assertRaises(TypeError):
47 class TestCustom(unittest.TestCase):
51 long_name="Russian Pension security number"
52 o=create(d,sn,long_name)
53 self.assertEqual(str(o),d)
54 self.assertEqual(o.shortname(),sn)
55 self.assertEqual(o.longname(),long_name)
59 long_name="Russian Pension security number"
60 o=create(d,sn,long_name)
63 def testCleanup(self):
66 long_name="Russian Pension security number"
67 o=create(d,sn,long_name)
68 self.assertEqual(str(o),'1.2.643.100.9')
71 with self.assertRaises(ValueError):
73 def testFromObj(self):
74 from ctypescrypto import libcrypto
75 from ctypes import c_int, c_char_p, c_void_p
76 libcrypto.OBJ_txt2obj.argtypes = (c_char_p, c_int)
77 libcrypto.OBJ_txt2obj.restype = c_void_p
78 obj= libcrypto.OBJ_txt2obj("1.2.643.100.9",1)
80 self.assertEqual(str(oid),'1.2.643.100.9')
82 # Always call cleanup before next test
88 if __name__ == '__main__':