Ejemplo n.º 1
0
def test_client_creates_job_data_correctly(mocker, fake_uuid):
    job_id = fake_uuid
    service_id = fake_uuid
    template_id = fake_uuid
    original_file_name = 'test.csv'
    notification_count = 1

    expected_data = {
        "id": job_id,
        "template": template_id,
        "original_file_name": original_file_name,
        "notification_count": 1
    }

    expected_url = '/service/{}/job'.format(service_id)

    client = JobApiClient()
    mock_attach_user = mocker.patch(
        'app.notify_client.job_api_client._attach_current_user',
        return_value={'created_by': fake_uuid})
    mock_post = mocker.patch('app.notify_client.job_api_client.JobApiClient.post')

    client.create_job(job_id, service_id, template_id, original_file_name, notification_count)

    mock_post.assert_called_once_with(url=expected_url, data=expected_data)
Ejemplo n.º 2
0
def test_client_creates_job_data_correctly(mocker, fake_uuid):
    job_id = fake_uuid
    service_id = fake_uuid
    template_id = fake_uuid
    original_file_name = 'test.csv'
    notification_count = 1
    mocker.patch('app.notify_client.current_user', id='1')

    expected_data = {
        "id": job_id,
        "template": template_id,
        "original_file_name": original_file_name,
        "notification_count": 1,
        "created_by": '1'
    }

    expected_url = '/service/{}/job'.format(service_id)

    client = JobApiClient()
    mock_post = mocker.patch(
        'app.notify_client.job_api_client.JobApiClient.post',
        return_value={'data': dict(statistics=[], **expected_data)})

    result = client.create_job(job_id, service_id, template_id,
                               original_file_name, notification_count)

    assert result['data']['notifications_requested'] == 0
    assert result['data']['notifications_sent'] == 0
    assert result['data']['notification_count'] == 1
    assert result['data']['notifications_failed'] == 0

    mock_post.assert_called_once_with(url=expected_url, data=expected_data)
def test_client_creates_job_data_correctly(mocker, fake_uuid):
    job_id = fake_uuid
    service_id = fake_uuid
    mocker.patch('app.notify_client.current_user', id='1')

    expected_data = {"id": job_id, "created_by": '1'}

    expected_url = '/service/{}/job'.format(service_id)

    client = JobApiClient()
    mock_post = mocker.patch(
        'app.notify_client.job_api_client.JobApiClient.post',
        return_value={'data': dict(statistics=[], **expected_data)})

    client.create_job(service_id, job_id)
    mock_post.assert_called_once_with(url=expected_url, data=expected_data)
Ejemplo n.º 4
0
def test_client_creates_job_data_correctly(mocker, fake_uuid):
    job_id = fake_uuid
    service_id = fake_uuid
    mocker.patch("app.notify_client.current_user", id="1")
    mock_redis_set = mocker.patch("app.extensions.RedisClient.set")

    expected_data = {"id": job_id, "created_by": "1"}

    expected_url = "/service/{}/job".format(service_id)

    client = JobApiClient()
    mock_post = mocker.patch(
        "app.notify_client.job_api_client.JobApiClient.post",
        return_value={"data": dict(statistics=[], **expected_data)},
    )

    client.create_job(service_id, job_id)
    mock_post.assert_called_once_with(url=expected_url, data=expected_data)
    mock_redis_set.assert_called_once_with(
        "has_jobs-{}".format(service_id),
        b"true",
        ex=604800,
    )