]> www.wagner.pp.ru Git - oss/ctypescrypto.git/blob - tests/testoids.py
Fixes some style. Improved tests coverage for bio,oid,digest and cipher. Prepare...
[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_fromunicode(self):
28                 o=Oid(u'commonName')
29                 self.assertEqual(o.shortname(),'CN')
30         def test_wrongoid(self):
31                 with self.assertRaises(ValueError):
32                         o=Oid("1.2.3.4.5.6.7.8.10.111.1111")
33         def test_wrongname(self):
34                 with self.assertRaises(ValueError):
35                         o=Oid("No such oid in the database")
36         def test_wrongnid(self):
37                 with self.assertRaises(ValueError):
38                         o=Oid(9999999)
39         def test_wrongtype(self):
40                 with self.assertRaises(TypeError):
41                         o=Oid([2,5,3,4])
42
43 class TestCustom(unittest.TestCase):
44         def testCreate(self):
45                 d='1.2.643.100.3'
46                 sn="SNILS"
47                 long_name="Russian Pension security number"
48                 o=create(d,sn,long_name)
49                 self.assertEqual(str(o),d)
50                 self.assertEqual(o.shortname(),sn)
51                 self.assertEqual(o.longname(),long_name)
52         def testLookup(self):
53                 d='1.2.643.100.3'
54                 sn="SNILS"
55                 long_name="Russian Pension security number"
56                 o=create(d,sn,long_name)
57                 x=Oid(sn)
58                 self.assertEqual(o,x)
59         def testCleanup(self):
60                 d='1.2.643.100.3'
61                 sn="SNILS"
62                 long_name="Russian Pension security number"
63                 o=create(d,sn,long_name)
64                 cleanup()
65                 with self.assertRaises(ValueError):
66                         x=Oid(sn)
67         def tearDown(self):
68                 # Always call cleanup before next test
69                 cleanup()
70         
71
72
73
74 if __name__ == '__main__':
75         unittest.main()