|
| 1 | +# This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | +# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | +# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 4 | +""" |
| 5 | +Test the hgpush message processing code. |
| 6 | +""" |
| 7 | + |
| 8 | +from unittest.mock import MagicMock, patch |
| 9 | + |
| 10 | +import pytest |
| 11 | + |
| 12 | +pytestmark = pytest.mark.usefixtures('null_config') |
| 13 | + |
| 14 | + |
| 15 | +# This structure is described here: |
| 16 | +# https://mozilla-version-control-tools.readthedocs.io/en/latest/hgmo/notifications.html#common-properties-of-notifications |
| 17 | +# Example messages can be collected from this URL: |
| 18 | +# https://tools.taskcluster.net/pulse-inspector?bindings[0][exchange]=exchange%2Fhgpushes%2Fv2&bindings[0][routingKeyPattern]=%23 |
| 19 | +test_message = { |
| 20 | + 'payload': { |
| 21 | + 'type': 'changegroup.1', |
| 22 | + 'data': { |
| 23 | + 'pushlog_pushes': [ |
| 24 | + { |
| 25 | + 'time': 15278721560, |
| 26 | + 'pushid': 64752, |
| 27 | + 'push_json_url': 'https://hg.mozilla.org/integration/autoland/json-pushes?version=2&startID=64751&endID=64752', |
| 28 | + 'push_full_json_url': 'https://hg.mozilla.org/integration/autoland/json-pushes?version=2&full=1&startID=64751&endID=64752', |
| 29 | + 'user': 'someuser@mozilla.org', |
| 30 | + } |
| 31 | + ], |
| 32 | + 'heads': [ |
| 33 | + 'ebe99842f5f8d543e5453ce78b1eae3641830b13', |
| 34 | + ], |
| 35 | + 'repo_url': 'https://hg.mozilla.org/integration/autoland', |
| 36 | + }, |
| 37 | + }, |
| 38 | +} # yapf: disable |
| 39 | + |
| 40 | +def test_process_push_message(): |
| 41 | + from committelemetry.pulse import process_push_message |
| 42 | + |
| 43 | + with patch('committelemetry.pulse.send_ping') as send_ping, \ |
| 44 | + patch('committelemetry.pulse.payload_for_changeset'), \ |
| 45 | + patch('committelemetry.pulse.changesets_for_pushid') as changesets_for_pushid: |
| 46 | + changesets_for_pushid.return_value = ['ab1cd2'] |
| 47 | + |
| 48 | + process_push_message(test_message, MagicMock()) |
| 49 | + |
| 50 | + send_ping.assert_called_once() |
| 51 | + |
| 52 | + |
0 commit comments