@@ -46,13 +46,20 @@ def test_message(self):
46
46
try :
47
47
raise oauth .Error
48
48
except oauth .Error , e :
49
- self .assertEqual (e .message , 'OAuth error occured.' )
49
+ self .assertEqual (e .message , 'OAuth error occurred.' )
50
+
50
51
msg = 'OMG THINGS BROKE!!!!'
51
52
try :
52
53
raise oauth .Error (msg )
53
54
except oauth .Error , e :
54
55
self .assertEqual (e .message , msg )
55
56
57
+ def test_str (self ):
58
+ try :
59
+ raise oauth .Error
60
+ except oauth .Error , e :
61
+ self .assertEquals (str (e ), 'OAuth error occurred.' )
62
+
56
63
class TestGenerateFunctions (unittest .TestCase ):
57
64
def test_build_auth_header (self ):
58
65
header = oauth .build_authenticate_header ()
@@ -64,6 +71,28 @@ def test_build_auth_header(self):
64
71
realm )
65
72
self .assertEqual (len (header ), 1 )
66
73
74
+ def test_build_xoauth_string (self ):
75
+ consumer = oauth .Consumer ('consumer_token' , 'consumer_secret' )
76
+ token = oauth .Token ('user_token' , 'user_secret' )
77
+ url = "https://mail.google.com/mail/b/[email protected] /imap/"
78
+ xoauth_string = oauth .build_xoauth_string (url , consumer , token )
79
+
80
+ method , oauth_url , oauth_string = xoauth_string .split (' ' )
81
+
82
+ self .assertEqual ("GET" , method )
83
+ self .assertEqual (url , oauth_url )
84
+
85
+ returned = {}
86
+ parts = oauth_string .split (',' )
87
+ for part in parts :
88
+ var , val = part .split ('=' )
89
+ returned [var ] = val .strip ('"' )
90
+
91
+ self .assertEquals ('HMAC-SHA1' , returned ['oauth_signature_method' ])
92
+ self .assertEquals ('user_token' , returned ['oauth_token' ])
93
+ self .assertEquals ('consumer_token' , returned ['oauth_consumer_key' ])
94
+ self .assertTrue ('oauth_signature' in returned , 'oauth_signature' )
95
+
67
96
def test_escape (self ):
68
97
string = 'http://whatever.com/~someuser/?test=test&other=other'
69
98
self .assert_ ('~' in oauth .escape (string ))
0 commit comments