NotifyHttpSMS() Edge Cases.
(mock_post)
| 146 | |
| 147 | @mock.patch("requests.post") |
| 148 | def test_plugin_httpsms_edge_cases(mock_post): |
| 149 | """NotifyHttpSMS() Edge Cases.""" |
| 150 | |
| 151 | # Initialize some generic (but valid) tokens |
| 152 | apikey = "mykey123" |
| 153 | source = "1 (405) 123 1234" |
| 154 | targets = [ |
| 155 | "+1(555) 123-1234", |
| 156 | "1555 5555555", |
| 157 | # A garbage entry |
| 158 | "12", |
| 159 | # NOw a valid one because a group was implicit |
| 160 | "@12", |
| 161 | ] |
| 162 | |
| 163 | # Prepare our response |
| 164 | response = requests.Request() |
| 165 | response.status_code = requests.codes.ok |
| 166 | |
| 167 | # Prepare Mock |
| 168 | mock_post.return_value = response |
| 169 | |
| 170 | # Instantiate our object |
| 171 | obj = Apprise.instantiate( |
| 172 | "httpsms://{}@{}/{}".format(apikey, source, "/".join(targets)) |
| 173 | ) |
| 174 | |
| 175 | assert ( |
| 176 | obj.notify(body="body", title="title", notify_type=NotifyType.INFO) |
| 177 | is True |
| 178 | ) |
| 179 | |
| 180 | # We know there are 2 targets |
| 181 | assert len(obj) == 2 |
| 182 | |
| 183 | # Test our call count |
| 184 | assert mock_post.call_count == 2 |
| 185 | |
| 186 | # Test |
| 187 | details = mock_post.call_args_list[0] |
| 188 | payload = loads(details[1]["data"]) |
| 189 | assert payload["from"] == "+14051231234" |
| 190 | assert payload["to"] == "+15551231234" |
| 191 | assert payload["content"] == "title\r\nbody" |
| 192 | |
| 193 | details = mock_post.call_args_list[1] |
| 194 | payload = loads(details[1]["data"]) |
| 195 | assert payload["from"] == "+14051231234" |
| 196 | assert payload["to"] == "+15555555555" |
| 197 | assert payload["content"] == "title\r\nbody" |
| 198 | |
| 199 | # Verify our URL looks good |
| 200 | assert obj.url().startswith( |
| 201 | "httpsms://mykey123@14051231234/15551231234/15555555555" |
| 202 | ) |
nothing calls this directly
no test coverage detected
searching dependent graphs…