Bug 1488468 - Move HTTP POST request to wait_for_ping in TestPingServer; r=davehunt

Depends on D8531

Differential Revision: https://phabricator.services.mozilla.com/D8532

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Raphael Pierzina 2018-10-16 10:42:06 +00:00
Родитель 5961cffb59
Коммит 41ba899583
1 изменённых файлов: 26 добавлений и 9 удалений

Просмотреть файл

@ -3,19 +3,36 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/ # file, You can obtain one at http://mozilla.org/MPL/2.0/
import requests import requests
import simplejson as json
from telemetry_harness.testcase import TelemetryTestCase from telemetry_harness.testcase import TelemetryTestCase
class TestPingServer(TelemetryTestCase): class TestPingServer(TelemetryTestCase):
def test_ping_server_received_ping(self): def test_ping_server_received_ping(self):
ping_type = "server-test-ping"
ping_reason = "unit-test"
data = {'type': 'server-test-ping', 'reason': 'unit-test'} def action_func():
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} """Perform a POST request to the ping server."""
json_req = requests.post(self.ping_server_url, data=json.dumps(data), headers=headers) data = {"type": ping_type, "reason": ping_reason}
ping = self.wait_for_ping(None, lambda p: p['type'] == 'server-test-ping') headers = {"Content-type": "application/json", "Accept": "text/plain"}
assert ping is not None
assert json_req.status_code == 200 response = requests.post(self.ping_server_url, json=data, headers=headers)
assert data['type'] == ping['type'] and data['reason'] == ping['reason']
self.assertEqual(
response.status_code,
200,
msg="Error sending POST request to ping server: {response.text}".format(
response=response
),
)
return response
def ping_filter_func(ping):
return ping["type"] == ping_type
ping = self.wait_for_ping(action_func, ping_filter_func)
self.assertIsNotNone(ping)
self.assertEqual(ping["type"], ping_type)
self.assertEqual(ping["reason"], ping_reason)