]> www.wagner.pp.ru Git - oss/ctypescrypto.git/blob - tests/testoids.py
f324f7e663a790daaf57b2f3f5da7e06142b8d05
[oss/ctypescrypto.git] / tests / testoids.py
1 from ctypescrypto.oid import Oid,create,cleanup
2 import unittest
3
4 class TestStandard(unittest.TestCase):
5         def test_cn(self):
6                 o=Oid("2.5.4.3")
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):
13                 o=Oid("2.5.4.3")
14                 x=Oid("CN")
15                 self.assertEqual(o.nid,x.nid)
16                 self.assertEqual(o,x)
17                 self.assertEqual(hash(o),hash(x))
18
19         def test_cons2(self):
20                 o=Oid("2.5.4.3")
21                 x=Oid("commonName")
22                 self.assertEqual(o.nid,x.nid)
23         def test_bynid(self):
24                 o=Oid("2.5.4.3")
25                 x=Oid(o.nid)
26                 self.assertEqual(o.nid,x.nid)
27         def test_wrongoid(self):
28                 with self.assertRaises(ValueError):
29                         o=Oid("1.2.3.4.5.6.7.8.10.111.1111")
30         def test_wrongname(self):
31                 with self.assertRaises(ValueError):
32                         o=Oid("No such oid in the database")
33         def test_wrongtype(self):
34                 with self.assertRaises(TypeError):
35                         o=Oid([2,5,3,4])
36
37 class TestCustom(unittest.TestCase):
38         def testCreate(self):
39                 d='1.2.643.100.3'
40                 sn="SNILS"
41                 long_name="Russian Pension security number"
42                 o=create(d,sn,long_name)
43                 self.assertEqual(str(o),d)
44                 self.assertEqual(o.shortname(),sn)
45                 self.assertEqual(o.longname(),long_name)
46         def testLookup(self):
47                 d='1.2.643.100.3'
48                 sn="SNILS"
49                 long_name="Russian Pension security number"
50                 o=create(d,sn,long_name)
51                 x=Oid(sn)
52                 self.assertEqual(o,x)
53         def testCleanup(self):
54                 d='1.2.643.100.3'
55                 sn="SNILS"
56                 long_name="Russian Pension security number"
57                 o=create(d,sn,long_name)
58                 cleanup()
59                 with self.assertRaises(ValueError):
60                         x=Oid(sn)
61         def tearDown(self):
62                 # Always call cleanup before next test
63                 cleanup()
64         
65
66
67
68 if __name__ == '__main__':
69         unittest.main()