Merge lp:~rick-fdd/pyopenssl/tests_of_types into lp:~exarkun/pyopenssl/trunk

Proposed by rick_dean on 2009-07-16
Status: Merged
Approved by: Jean-Paul Calderone on 2009-07-18
Approved revision: 114
Merged at revision: not available
Proposed branch: lp:~rick-fdd/pyopenssl/tests_of_types
Merge into: lp:~exarkun/pyopenssl/trunk
Diff against target: None lines
To merge this branch: bzr merge lp:~rick-fdd/pyopenssl/tests_of_types
Reviewer Review Type Date Requested Status
Jean-Paul Calderone 2009-07-16 Pending
Review via email: mp+8893@code.launchpad.net
To post a comment you must log in.
rick_dean (rick-fdd) wrote :

Unit tests make good examples as well.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'test/test_crypto.py'
2--- test/test_crypto.py 2009-07-05 16:54:05 +0000
3+++ test/test_crypto.py 2009-07-09 20:53:42 +0000
4@@ -191,6 +191,9 @@
5 isinstance(comment, X509ExtensionType),
6 "%r is of type %r, should be %r" % (
7 comment, type(comment), X509ExtensionType))
8+ self.assertEqual(type(X509ExtensionType).__name__, 'type')
9+ self.assertEqual(type(basic).__name__, 'X509Extension')
10+ self.assertEqual(type(basic), X509ExtensionType)
11
12
13 def test_invalid_extension(self):
14@@ -248,6 +251,9 @@
15 self.assertTrue(
16 isinstance(key, PKeyType),
17 "%r is of type %r, should be %r" % (key, type(key), PKeyType))
18+ self.assertEqual(type(PKeyType).__name__, 'type')
19+ self.assertEqual(type(key).__name__, 'PKey')
20+ self.assertEqual(type(key), PKeyType)
21
22
23 def test_pregeneration(self):
24@@ -350,6 +356,21 @@
25 return name
26
27
28+ def test_type(self):
29+ """
30+ L{X509NameType} is a type, and matches the type of a
31+ X509Name.
32+ """
33+ name = self._x509name()
34+ self.assertTrue(
35+ isinstance(name, X509NameType),
36+ "%r is of type %r, should be %r" % (
37+ name, type(name), X509NameType))
38+ self.assertEqual(type(X509NameType).__name__, 'type')
39+ self.assertEqual(type(name).__name__, 'X509Name')
40+ self.assertEqual(type(name), X509NameType)
41+
42+
43 def test_attributes(self):
44 """
45 L{X509NameType} instances have attributes for each standard (?)
46@@ -558,7 +579,11 @@
47 """
48 Create and return a new L{X509Req}.
49 """
50- return X509Req()
51+ req = X509Req()
52+ self.assertEqual(type(X509ReqType).__name__, 'type')
53+ self.assertEqual(type(req).__name__, 'X509Req')
54+ self.assertEqual(type(req), X509ReqType)
55+ return req
56
57
58 def test_construction(self):
59@@ -627,6 +652,9 @@
60 "%r is of type %r, should be %r" % (certificate,
61 type(certificate),
62 X509Type))
63+ self.assertEqual(type(X509Type).__name__, 'type')
64+ self.assertEqual(type(certificate).__name__, 'X509')
65+ self.assertEqual(type(certificate), X509Type)
66
67
68 def test_serial_number(self):
69@@ -895,6 +923,9 @@
70 """
71 pkcs7 = load_pkcs7_data(FILETYPE_PEM, pkcs7Data)
72 self.assertTrue(isinstance(pkcs7, PKCS7Type))
73+ self.assertEqual(type(PKCS7Type).__name__, 'type')
74+ self.assertEqual(type(pkcs7).__name__, 'PKCS7')
75+ self.assertEqual(type(pkcs7), PKCS7Type)
76
77
78 def test_load_pkcs12(self):
79@@ -904,6 +935,9 @@
80 """
81 pkcs12 = load_pkcs12(pkcs12Data)
82 self.assertTrue(isinstance(pkcs12, PKCS12Type))
83+ self.assertEqual(type(PKCS12Type).__name__, 'type')
84+ self.assertEqual(type(pkcs12).__name__, 'PKCS12')
85+ self.assertEqual(type(pkcs12), PKCS12Type)
86
87
88
89@@ -917,6 +951,9 @@
90 """
91 nspki = NetscapeSPKI()
92 self.assertTrue(isinstance(nspki, NetscapeSPKIType))
93+ self.assertEqual(type(NetscapeSPKIType).__name__, 'type')
94+ self.assertEqual(type(nspki).__name__, 'NetscapeSPKI')
95+ self.assertEqual(type(nspki), NetscapeSPKIType)
96
97
98
99
100=== modified file 'test/test_ssl.py'
101--- test/test_ssl.py 2009-07-05 17:50:34 +0000
102+++ test/test_ssl.py 2009-07-09 20:53:42 +0000
103@@ -11,7 +11,7 @@
104 from unittest import main
105
106 from OpenSSL.crypto import TYPE_RSA, FILETYPE_PEM, PKey, dump_privatekey, load_certificate, load_privatekey
107-from OpenSSL.SSL import WantReadError, Context, Connection, Error
108+from OpenSSL.SSL import WantReadError, Context, ContextType, Connection, ConnectionType, Error
109 from OpenSSL.SSL import SSLv2_METHOD, SSLv3_METHOD, SSLv23_METHOD, TLSv1_METHOD
110 from OpenSSL.SSL import OP_NO_SSLv2, OP_NO_SSLv3, OP_SINGLE_DH_USE
111 from OpenSSL.SSL import VERIFY_PEER, VERIFY_FAIL_IF_NO_PEER_CERT, VERIFY_CLIENT_ONCE
112@@ -46,6 +46,17 @@
113 self.assertRaises(ValueError, Context, 10)
114
115
116+ def test_type(self):
117+ """
118+ L{Context} must be of type L{ContextType}.
119+ """
120+ ctx = Context(TLSv1_METHOD)
121+ self.assertTrue(isinstance(ctx, ContextType))
122+ self.assertEqual(type(ContextType).__name__, 'type')
123+ self.assertEqual(type(ctx).__name__, 'Context')
124+ self.assertEqual(type(ctx), ContextType)
125+
126+
127 def test_use_privatekey(self):
128 """
129 L{Context.use_privatekey} takes an L{OpenSSL.crypto.PKey} instance.
130@@ -259,6 +270,26 @@
131
132
133
134+class ConnectionTests(TestCase):
135+ """
136+ Unit tests for L{OpenSSL.SSL.Connection}.
137+ """
138+ def test_type(self):
139+ """
140+ L{Connection} must be of type L{ConnectionType}.
141+ """
142+ ctx = Context(TLSv1_METHOD)
143+ conn = Connection(ctx, None)
144+ self.assertTrue(isinstance(conn, ConnectionType))
145+ self.assertEqual(type(ConnectionType).__name__, 'type')
146+ self.assertEqual(type(conn).__name__, 'Connection')
147+ self.assertEqual(type(conn), ConnectionType)
148+
149+ self.assertEqual(Error.__name__, 'Error')
150+ self.assertEqual(type(Error).__name__, 'type')
151+
152+
153+
154 class ConstantsTests(TestCase):
155 """
156 Tests for the values of constants exposed in L{OpenSSL.SSL}.

Subscribers

People subscribed via source and target branches

to status/vote changes: