26 |
26 |
from passerelle.base.models import AccessRight, ApiUser, Job
|
27 |
27 |
from passerelle.utils.jsonresponse import APIError
|
28 |
28 |
|
29 |
29 |
NETLOC = 'contact-everyone.orange-business.com'
|
30 |
30 |
JSON_HEADERS = {'content-type': 'application/json'}
|
31 |
31 |
PAYLOAD = {
|
32 |
32 |
'message': 'hello',
|
33 |
33 |
'from': 'john',
|
34 |
|
'to': ['+33688888888', '+33677777777'],
|
|
34 |
'to': ['+33677777777', '+33688888888'],
|
35 |
35 |
}
|
36 |
36 |
|
37 |
37 |
|
38 |
38 |
@httmock.urlmatch(netloc=NETLOC, path='/api/v1.2/oauth/token', method='POST')
|
39 |
39 |
def response_token_ok(url, request):
|
40 |
40 |
assert 'username=jdoe' in request.body
|
41 |
41 |
assert 'password=secret' in request.body
|
42 |
42 |
content = json.dumps({'access_token': 'my_token'})
|
... | ... | |
55 |
55 |
|
56 |
56 |
|
57 |
57 |
@httmock.urlmatch(netloc=NETLOC, path='/api/v1.2/groups/gid2/diffusion-requests', method='POST')
|
58 |
58 |
def response_diffusion_ok(url, request):
|
59 |
59 |
assert request.headers['authorization'] == 'Bearer my_token'
|
60 |
60 |
request_body = json.loads(force_str(request.body))
|
61 |
61 |
assert request_body['smsParam']['body'] == PAYLOAD['message']
|
62 |
62 |
assert 'senderName' not in request_body['smsParam'].keys()
|
63 |
|
assert '33688888888' in request_body['msisdns'][0]
|
64 |
|
assert '33677777777' in request_body['msisdns'][1]
|
|
63 |
assert '33677777777' in request_body['msisdns'][0]
|
|
64 |
assert '33688888888' in request_body['msisdns'][1]
|
65 |
65 |
content = json.dumps({'status': "I'm ok"})
|
66 |
66 |
return httmock.response(201, content, JSON_HEADERS)
|
67 |
67 |
|
68 |
68 |
|
69 |
69 |
@httmock.urlmatch(netloc=NETLOC)
|
70 |
70 |
def response_500(url, request):
|
71 |
71 |
return httmock.response(500, 'my_error')
|
72 |
72 |
|
... | ... | |
181 |
181 |
|
182 |
182 |
orange.provide_sender = True
|
183 |
183 |
orange.save()
|
184 |
184 |
with pytest.raises(OrangeError, match='The given sender name is not allowed.'):
|
185 |
185 |
with httmock.HTTMock(mocked_response2):
|
186 |
186 |
orange.diffusion('my_token', 'gid2', PAYLOAD['to'], PAYLOAD['message'], PAYLOAD['from'])
|
187 |
187 |
|
188 |
188 |
|
189 |
|
@pytest.mark.xfail(run=False)
|
190 |
189 |
def test_send_msg(app, connector):
|
191 |
190 |
url = '/%s/%s/send/' % (connector.get_connector_slug(), connector.slug)
|
192 |
191 |
assert Job.objects.count() == 0
|
193 |
192 |
resp = app.post_json(url, params=PAYLOAD, status=200)
|
194 |
193 |
assert not resp.json['err']
|
195 |
194 |
assert Job.objects.count() == 1
|
196 |
195 |
with httmock.HTTMock(response_token_ok, response_group_ok, response_diffusion_ok):
|
197 |
196 |
connector.jobs()
|
198 |
|
-
|