Exemplo n.º 1
0
def test_send_no_target():
    payload = Payload(
        data={"hello": "world"},
        targets=[Target()],
    )
    responses = distribution.send([payload], SENDING, error_parser)
    assert len(responses) == 0
Exemplo n.º 2
0
def test_send_single_payload_successfully():
    with requests_mock.Mocker() as mocker:
        mocker.post(URL1, text="hallo", status_code=200)
        mocker.post(URL2, text="hallo", status_code=200)
        responses = distribution.send([PAYLOAD], SENDING, error_parser)
        assert len(responses) == 2
        assert responses[0].request.url == URL1
        assert responses[1].request.url == URL2
        assert responses[0].status_code == 200
        assert responses[1].status_code == 200
Exemplo n.º 3
0
def test_send_fail_without_error_parser():
    with requests_mock.Mocker() as mocker:
        mocker.post(URL1, text="hallo", status_code=404)
        mocker.post(URL2, text="hallo", status_code=404)
        mocker.get(notify_url, text="x", status_code=200)
        responses = distribution.send([PAYLOAD], SENDING)
        assert len(responses) == 4
        assert responses[0].status_code == 404
        assert responses[1].status_code == 200
        assert responses[2].status_code == 404
        assert responses[3].status_code == 200