asksol / python-stomp
fork of python-stomp
stompy is a fork of the STOMP client python-stomp, with support for non-blocking, polling and multiple subscriptions per connection.
Clone this repository (size: 101.6 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/asksol/python-stomp/
| commit 48: | fa049e026851 |
| parent 47: | 29ec112a0cb1 |
| branch: | default |
tests/test_frame.py now passes pep8.py
Changed (Δ252 bytes):
raw changeset »
tests/test_frame.py (67 lines added, 54 lines removed)
Up to file-list tests/test_frame.py:
| … | … | @@ -6,6 +6,7 @@ import socket |
6 |
6 |
from four import frame |
7 |
7 |
from four.frame import Frame |
8 |
8 |
|
9 |
||
9 |
10 |
class WhenSettingUp(DingusTestCase(Frame)): |
10 |
11 |
|
11 |
12 |
def setup(self): |
| … | … | @@ -14,17 +15,19 @@ class WhenSettingUp(DingusTestCase(Frame |
14 |
15 |
self.sockobj = frame.socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
15 |
16 |
|
16 |
17 |
def should_set_name(self): |
17 |
assert frame.socket.calls('gethostbyname', |
|
18 |
assert frame.socket.calls('gethostbyname', frame.socket.gethostname()) |
|
18 |
19 |
|
19 |
20 |
def should_connect(self): |
20 |
21 |
self.frame._getline = Dingus() |
21 |
self.frame._getline.return_value = 'CONNECTED\nsession:ID:nose-session123\n\n\x00\n' |
|
22 |
self.frame.connect(self.sockobj.connect('localhost',99999)) |
|
23 |
se |
|
22 |
self.frame._getline.return_value = \ |
|
23 |
'CONNECTED\nsession:ID:nose-session123\n\n\x00\n' |
|
24 |
self.frame.connect(self.sockobj.connect('localhost', 99999)) |
|
25 |
sendall = self.frame.sock.calls('sendall', DontCare).one().args[0] |
|
24 |
26 |
|
25 |
27 |
assert self.frame.session is not None |
26 |
28 |
assert 'CONNECT' in sendall |
27 |
29 |
|
30 |
||
28 |
31 |
class WhenSendingFrames(DingusTestCase(Frame)): |
29 |
32 |
|
30 |
33 |
def setup(self): |
| … | … | @@ -34,9 +37,11 @@ class WhenSendingFrames(DingusTestCase(F |
34 |
37 |
|
35 |
38 |
def should_send_frame_and_return_none(self): |
36 |
39 |
self.frame._getline = Dingus() |
37 |
self.frame._getline.return_value = 'CONNECTED\nsession:ID:nose-session123\n\n\x00\n' |
|
38 |
self.frame.connect(self.sockobj.connect('localhost',99999)) |
|
39 |
|
|
40 |
self.frame._getline.return_value = \ |
|
41 |
'CONNECTED\nsession:ID:nose-session123\n\n\x00\n' |
|
42 |
self.frame.connect(self.sockobj.connect('localhost', 99999)) |
|
43 |
this_frame = self.frame.build_frame({'command': 'CONNECT', |
|
44 |
'headers': {}}) |
|
40 |
45 |
send_frame = self.frame.send_frame(this_frame.as_string()) |
41 |
46 |
|
42 |
47 |
assert send_frame is None |
| … | … | @@ -44,18 +49,22 @@ class WhenSendingFrames(DingusTestCase(F |
44 |
49 |
def should_send_frame_and_return_frame(self): |
45 |
50 |
my_frame = Frame() |
46 |
51 |
my_frame._getline = Dingus() |
47 |
headers = {'destination':'/queue/nose_test', |
|
48 |
'persistent':'true'} |
|
49 |
body = {'body':'Testing'} |
|
50 |
my_frame._getline.return_value = 'CONNECTED\nsession:ID:nose-session123\n\n\x00\n' |
|
51 |
my_frame.connect(self.sockobj.connect('localhost',99999)) |
|
52 |
this_frame = my_frame.build_frame({'command':'SEND', |
|
53 |
'headers':headers, |
|
54 |
'body':body},want_receipt=True) |
|
55 |
|
|
52 |
headers = {'destination': '/queue/nose_test', |
|
53 |
'persistent': 'true'} |
|
54 |
body = {'body': 'Testing'} |
|
55 |
my_frame._getline.return_value = \ |
|
56 |
'CONNECTED\nsession:ID:nose-session123\n\n\x00\n' |
|
57 |
my_frame.connect(self.sockobj.connect('localhost', 99999)) |
|
58 |
this_frame = my_frame.build_frame({'command': 'SEND', |
|
59 |
'headers': headers, |
|
60 |
'body': body}, |
|
61 |
want_receipt=True) |
|
62 |
my_frame._getline.return_value = \ |
|
63 |
'RECEIPT\nreceipt-id:ID:nose-receipt123\n\n\x00\n' |
|
56 |
64 |
send_frame = my_frame.send_frame(this_frame.as_string()) |
57 |
65 |
|
58 |
assert isinstance(my_frame, |
|
66 |
assert isinstance(my_frame, Frame) |
|
67 |
||
59 |
68 |
|
60 |
69 |
class WhenBuildingFrames(DingusTestCase(Frame)): |
61 |
70 |
|
| … | … | @@ -65,44 +74,47 @@ class WhenBuildingFrames(DingusTestCase( |
65 |
74 |
self.sockobj = frame.socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
66 |
75 |
|
67 |
76 |
def should_build_frame(self): |
68 |
this_frame = self.frame.build_frame({'command': |
|
77 |
this_frame = self.frame.build_frame({'command': 'CONNECT', |
|
78 |
'headers': {}}) |
|
69 |
79 |
|
70 |
80 |
assert self.frame.command is not None |
71 |
81 |
assert self.frame.headers is not None |
72 |
82 |
assert '\x00' in this_frame.as_string() |
73 |
83 |
|
74 |
84 |
def should_build_frame_with_body(self): |
75 |
headers = {'destination':'/queue/nose_test', |
|
76 |
'persistent':'true'} |
|
77 |
body = 'Testing' |
|
78 |
this_frame = self.frame.build_frame({'command':'SEND', |
|
79 |
'headers':headers, |
|
80 |
'body':body}) |
|
85 |
headers = {'destination': '/queue/nose_test', |
|
86 |
'persistent': 'true'} |
|
87 |
body = 'Testing' |
|
88 |
this_frame = self.frame.build_frame({'command': 'SEND', |
|
89 |
'headers': headers, |
|
90 |
'body': body}) |
|
81 |
91 |
|
82 |
92 |
assert self.frame.body is not None |
83 |
93 |
|
84 |
94 |
def should_build_frame_with_receipt(self): |
85 |
headers = {'destination':'/queue/nose_test', |
|
86 |
'persistent':'true'} |
|
87 |
body = 'Testing' |
|
88 |
self.frame.session = {'session':'ID:nose-session123'} |
|
89 |
this_frame = self.frame.build_frame({'command':'SEND', |
|
90 |
'headers':headers, |
|
91 |
|
|
95 |
headers = {'destination': '/queue/nose_test', |
|
96 |
'persistent': 'true'} |
|
97 |
body = 'Testing' |
|
98 |
self.frame.session = {'session': 'ID:nose-session123'} |
|
99 |
this_frame = self.frame.build_frame({'command': 'SEND', |
|
100 |
'headers': headers, |
|
101 |
'body': body}, |
|
102 |
want_receipt=True) |
|
92 |
103 |
|
93 |
104 |
assert 'receipt' in self.frame.headers |
94 |
||
105 |
||
95 |
106 |
def should_build_frame_bytes_message(self): |
96 |
headers = {'destination':'/queue/nose_test', |
|
97 |
'persistent':'true', |
|
98 |
'bytes_message':'true'} |
|
99 |
body = 'Testing' |
|
100 |
this_frame = self.frame.build_frame({'command':'SEND', |
|
101 |
'headers':headers, |
|
102 |
|
|
107 |
headers = {'destination': '/queue/nose_test', |
|
108 |
'persistent': 'true', |
|
109 |
'bytes_message': 'true'} |
|
110 |
body = 'Testing' |
|
111 |
this_frame = self.frame.build_frame({'command': 'SEND', |
|
112 |
'headers': headers, |
|
113 |
'body': body}) |
|
103 |
114 |
|
104 |
115 |
assert 'content-length:%i' % len(body) in this_frame.as_string() |
105 |
116 |
|
117 |
||
106 |
118 |
class WhenParsingFrames(DingusTestCase(Frame)): |
107 |
119 |
|
108 |
120 |
def setup(self): |
| … | … | @@ -114,38 +126,39 @@ class WhenParsingFrames(DingusTestCase(F |
114 |
126 |
header = 'destination:/queue/nose_test' |
115 |
127 |
parsed = self.frame.parse_headers(header) |
116 |
128 |
|
117 |
assert isinstance(parsed, |
|
129 |
assert isinstance(parsed, type({})) |
|
118 |
130 |
|
119 |
131 |
def should_parse_command(self): |
120 |
132 |
command_str = 'CONNECT\nsession:ID:nose-session123' |
121 |
command = self.frame.parse_command(command_str) |
|
122 |
||
123 |
|
|
133 |
command = self.frame.parse_command(command_str) |
|
134 |
||
135 |
assert isinstance(command, type('')) |
|
124 |
136 |
|
125 |
137 |
def should_set_bytes_message(self): |
126 |
138 |
my_frame = Frame() |
127 |
139 |
my_frame._getline = Dingus() |
128 |
140 |
body = 'Test 1' |
129 |
my_frame._getline.return_value = ('MESSAGE\nsession:ID:nose-session123' |
|
130 |
'\ncontent-length:%d\n\n%s\x00\n'%(len(body),body)) |
|
141 |
my_frame._getline.return_value = ( |
|
142 |
'MESSAGE\nsession:ID:nose-session123' |
|
143 |
'\ncontent-length:%d\n\n%s\x00\n' % (len(body), body)) |
|
131 |
144 |
this_frame = my_frame.parse_frame() |
132 |
145 |
|
133 |
146 |
assert 'bytes_message' in this_frame.headers |
134 |
||
147 |
||
135 |
148 |
def should_get_line(self): |
136 |
149 |
command = 'CONNECTED' |
137 |
headers = {'session':'ID:nose-session123'} |
|
138 |
body = '\x00\n' |
|
150 |
headers = {'session': 'ID:nose-session123'} |
|
151 |
body = '\x00\n' |
|
139 |
152 |
my_frame = Frame() |
140 |
153 |
self.frame.parse_frame = Dingus() |
141 |
this_frame = my_frame.build_frame({'command':command, |
|
142 |
'headers':headers, |
|
143 |
|
|
154 |
this_frame = my_frame.build_frame({'command': command, |
|
155 |
'headers': headers, |
|
156 |
'body': body}) |
|
144 |
157 |
self.frame.parse_frame.return_value = this_frame |
145 |
self.frame.connect(self.sockobj.connect(('localhost', |
|
158 |
self.frame.connect(self.sockobj.connect(('localhost', 99999))) |
|
146 |
159 |
header = "session:%(session)s\n" % headers |
147 |
ret = '\n'.join([command, |
|
160 |
ret = '\n'.join([command, header, body]) |
|
148 |
161 |
self.frame.sock.recv.return_value = ret |
149 |
162 |
self.frame._getline() |
150 |
163 |
|
151 |
assert self.frame.sock.calls('recv', |
|
164 |
assert self.frame.sock.calls('recv', 1) |
