|
1 |
| -import nexmo |
2 |
| -from util import * |
3 |
| - |
4 |
| - |
5 |
| -@responses.activate |
6 |
| -def test_send_message(sms, dummy_data): |
7 |
| - stub(responses.POST, "https://rest.nexmo.com/sms/json") |
8 |
| - |
9 |
| - params = {"from": "Python", "to": "447525856424", "text": "Hey!"} |
10 |
| - |
11 |
| - assert isinstance(sms.send_message(params), dict) |
12 |
| - assert request_user_agent() == dummy_data.user_agent |
13 |
| - assert "from=Python" in request_body() |
14 |
| - assert "to=447525856424" in request_body() |
15 |
| - assert "text=Hey%21" in request_body() |
16 |
| - |
17 |
| - |
18 |
| -@responses.activate |
19 |
| -def test_authentication_error(sms): |
20 |
| - responses.add(responses.POST, "https://rest.nexmo.com/sms/json", status=401) |
21 |
| - |
22 |
| - with pytest.raises(nexmo.AuthenticationError): |
23 |
| - sms.send_message({}) |
24 |
| - |
25 |
| - |
26 |
| -@responses.activate |
27 |
| -def test_client_error(sms): |
28 |
| - responses.add(responses.POST, "https://rest.nexmo.com/sms/json", status=400) |
29 |
| - |
30 |
| - with pytest.raises(nexmo.ClientError) as excinfo: |
31 |
| - sms.send_message({}) |
32 |
| - excinfo.match(r"400 response from rest.nexmo.com") |
33 |
| - |
34 |
| - |
35 |
| -@responses.activate |
36 |
| -def test_server_error(sms): |
37 |
| - responses.add(responses.POST, "https://rest.nexmo.com/sms/json", status=500) |
38 |
| - |
39 |
| - with pytest.raises(nexmo.ServerError) as excinfo: |
40 |
| - sms.send_message({}) |
41 |
| - excinfo.match(r"500 response from rest.nexmo.com") |
42 |
| - |
43 |
| - |
44 |
| -@responses.activate |
45 |
| -def test_submit_sms_conversion(sms): |
46 |
| - responses.add( |
47 |
| - responses.POST, "https://api.nexmo.com/conversions/sms", status=200, body=b"OK" |
48 |
| - ) |
49 |
| - |
50 |
| - sms.submit_sms_conversion("a-message-id") |
51 |
| - assert "message-id=a-message-id" in request_body() |
52 |
| - assert "timestamp" in request_body() |
53 |
| - |
54 |
| -@responses.activate |
55 |
| -def test_deprecated_send_message(client, dummy_data): |
56 |
| - stub(responses.POST, "https://rest.nexmo.com/sms/json") |
57 |
| - |
58 |
| - params = {"from": "Python", "to": "447525856424", "text": "Hey!"} |
59 |
| - |
60 |
| - assert isinstance(client.send_message(params), dict) |
61 |
| - assert request_user_agent() == dummy_data.user_agent |
62 |
| - assert "from=Python" in request_body() |
63 |
| - assert "to=447525856424" in request_body() |
64 |
| - assert "text=Hey%21" in request_body() |
65 |
| - |
66 |
| - |
67 |
| -@responses.activate |
68 |
| -def test_deprecated_authentication_error(client): |
69 |
| - responses.add(responses.POST, "https://rest.nexmo.com/sms/json", status=401) |
70 |
| - |
71 |
| - with pytest.raises(nexmo.AuthenticationError): |
72 |
| - client.send_message({}) |
73 |
| - |
74 |
| - |
75 |
| -@responses.activate |
76 |
| -def test_deprecated_client_error(client): |
77 |
| - responses.add(responses.POST, "https://rest.nexmo.com/sms/json", status=400) |
78 |
| - |
79 |
| - with pytest.raises(nexmo.ClientError) as excinfo: |
80 |
| - client.send_message({}) |
81 |
| - excinfo.match(r"400 response from rest.nexmo.com") |
82 |
| - |
83 |
| - |
84 |
| -@responses.activate |
85 |
| -def test_deprecated_server_error(client): |
86 |
| - responses.add(responses.POST, "https://rest.nexmo.com/sms/json", status=500) |
87 |
| - |
88 |
| - with pytest.raises(nexmo.ServerError) as excinfo: |
89 |
| - client.send_message({}) |
90 |
| - excinfo.match(r"500 response from rest.nexmo.com") |
91 |
| - |
92 |
| - |
93 |
| -@responses.activate |
94 |
| -def test_deprecated_submit_sms_conversion(client): |
95 |
| - responses.add( |
96 |
| - responses.POST, "https://api.nexmo.com/conversions/sms", status=200, body=b"OK" |
97 |
| - ) |
98 |
| - |
99 |
| - client.submit_sms_conversion("a-message-id") |
100 |
| - assert "message-id=a-message-id" in request_body() |
101 |
| - assert "timestamp" in request_body() |
| 1 | +import nexmo |
| 2 | +from util import * |
| 3 | + |
| 4 | + |
| 5 | +@responses.activate |
| 6 | +def test_send_message(sms, dummy_data): |
| 7 | + stub(responses.POST, "https://rest.nexmo.com/sms/json") |
| 8 | + |
| 9 | + params = {"from": "Python", "to": "447525856424", "text": "Hey!"} |
| 10 | + |
| 11 | + assert isinstance(sms.send_message(params), dict) |
| 12 | + assert request_user_agent() == dummy_data.user_agent |
| 13 | + assert "from=Python" in request_body() |
| 14 | + assert "to=447525856424" in request_body() |
| 15 | + assert "text=Hey%21" in request_body() |
| 16 | + |
| 17 | + |
| 18 | +@responses.activate |
| 19 | +def test_authentication_error(sms): |
| 20 | + responses.add(responses.POST, "https://rest.nexmo.com/sms/json", status=401) |
| 21 | + |
| 22 | + with pytest.raises(nexmo.AuthenticationError): |
| 23 | + sms.send_message({}) |
| 24 | + |
| 25 | + |
| 26 | +@responses.activate |
| 27 | +def test_client_error(sms): |
| 28 | + responses.add(responses.POST, "https://rest.nexmo.com/sms/json", status=400) |
| 29 | + |
| 30 | + with pytest.raises(nexmo.ClientError) as excinfo: |
| 31 | + sms.send_message({}) |
| 32 | + excinfo.match(r"400 response from rest.nexmo.com") |
| 33 | + |
| 34 | + |
| 35 | +@responses.activate |
| 36 | +def test_server_error(sms): |
| 37 | + responses.add(responses.POST, "https://rest.nexmo.com/sms/json", status=500) |
| 38 | + |
| 39 | + with pytest.raises(nexmo.ServerError) as excinfo: |
| 40 | + sms.send_message({}) |
| 41 | + excinfo.match(r"500 response from rest.nexmo.com") |
| 42 | + |
| 43 | + |
| 44 | +@responses.activate |
| 45 | +def test_submit_sms_conversion(sms): |
| 46 | + responses.add( |
| 47 | + responses.POST, "https://api.nexmo.com/conversions/sms", status=200, body=b"OK" |
| 48 | + ) |
| 49 | + |
| 50 | + sms.submit_sms_conversion("a-message-id") |
| 51 | + assert "message-id=a-message-id" in request_body() |
| 52 | + assert "timestamp" in request_body() |
| 53 | + |
| 54 | +@responses.activate |
| 55 | +def test_deprecated_send_message(client, dummy_data): |
| 56 | + stub(responses.POST, "https://rest.nexmo.com/sms/json") |
| 57 | + |
| 58 | + params = {"from": "Python", "to": "447525856424", "text": "Hey!"} |
| 59 | + |
| 60 | + assert isinstance(client.send_message(params), dict) |
| 61 | + assert request_user_agent() == dummy_data.user_agent |
| 62 | + assert "from=Python" in request_body() |
| 63 | + assert "to=447525856424" in request_body() |
| 64 | + assert "text=Hey%21" in request_body() |
| 65 | + |
| 66 | + |
| 67 | +@responses.activate |
| 68 | +def test_deprecated_authentication_error(client): |
| 69 | + responses.add(responses.POST, "https://rest.nexmo.com/sms/json", status=401) |
| 70 | + |
| 71 | + with pytest.raises(nexmo.AuthenticationError): |
| 72 | + client.send_message({}) |
| 73 | + |
| 74 | + |
| 75 | +@responses.activate |
| 76 | +def test_deprecated_client_error(client): |
| 77 | + responses.add(responses.POST, "https://rest.nexmo.com/sms/json", status=400) |
| 78 | + |
| 79 | + with pytest.raises(nexmo.ClientError) as excinfo: |
| 80 | + client.send_message({}) |
| 81 | + excinfo.match(r"400 response from rest.nexmo.com") |
| 82 | + |
| 83 | + |
| 84 | +@responses.activate |
| 85 | +def test_deprecated_server_error(client): |
| 86 | + responses.add(responses.POST, "https://rest.nexmo.com/sms/json", status=500) |
| 87 | + |
| 88 | + with pytest.raises(nexmo.ServerError) as excinfo: |
| 89 | + client.send_message({}) |
| 90 | + excinfo.match(r"500 response from rest.nexmo.com") |
| 91 | + |
| 92 | + |
| 93 | +@responses.activate |
| 94 | +def test_deprecated_submit_sms_conversion(client): |
| 95 | + responses.add( |
| 96 | + responses.POST, "https://api.nexmo.com/conversions/sms", status=200, body=b"OK" |
| 97 | + ) |
| 98 | + |
| 99 | + client.submit_sms_conversion("a-message-id") |
| 100 | + assert "message-id=a-message-id" in request_body() |
| 101 | + assert "timestamp" in request_body() |
0 commit comments