@@ -61,6 +61,34 @@ def check_exception(exception, message, status):
61
61
assert exception .http_response .status_code == status
62
62
63
63
64
+ class TestMessageStr (object ):
65
+
66
+ @pytest .mark .parametrize ('msg' , [
67
+ messaging .Message (),
68
+ messaging .Message (topic = 'topic' , token = 'token' ),
69
+ messaging .Message (topic = 'topic' , condition = 'condition' ),
70
+ messaging .Message (condition = 'condition' , token = 'token' ),
71
+ messaging .Message (topic = 'topic' , token = 'token' , condition = 'condition' ),
72
+ ])
73
+ def test_invalid_target_message (self , msg ):
74
+ with pytest .raises (ValueError ) as excinfo :
75
+ str (msg )
76
+ assert str (
77
+ excinfo .value ) == 'Exactly one of token, topic or condition must be specified.'
78
+
79
+ def test_empty_message (self ):
80
+ assert str (messaging .Message (token = 'value' )) == '{"token": "value"}'
81
+ assert str (messaging .Message (topic = 'value' )) == '{"topic": "value"}'
82
+ assert str (messaging .Message (condition = 'value' )
83
+ ) == '{"condition": "value"}'
84
+
85
+ def test_data_message (self ):
86
+ assert str (messaging .Message (topic = 'topic' , data = {})
87
+ ) == '{"topic": "topic"}'
88
+ assert str (messaging .Message (topic = 'topic' , data = {
89
+ 'k1' : 'v1' , 'k2' : 'v2' })) == '{"data": {"k1": "v1", "k2": "v2"}, "topic": "topic"}'
90
+
91
+
64
92
class TestMulticastMessage (object ):
65
93
66
94
@pytest .mark .parametrize ('tokens' , NON_LIST_ARGS )
0 commit comments