Exemplo n.º 1
0
def test_checkin_no_canonical_facts(event_producer_mock, db_create_host, db_get_host, api_post, post_doc):
    response_status, response_data = api_post(
        build_host_checkin_url(), post_doc, extra_headers={"x-rh-insights-request-id": "123456"}
    )

    assert_response_status(response_status, expected_status=400)
    assert event_producer_mock.key is None
    assert event_producer_mock.event is None
def test_checkin_no_matching_host(event_producer_mock, db_create_host, db_get_host, api_post):
    post_doc = {"insights_id": generate_uuid()}

    response_status, response_data = api_post(
        build_host_checkin_url(), post_doc, extra_headers={"x-rh-insights-request-id": "123456"}
    )

    assert_response_status(response_status, expected_status=404)
    assert event_producer_mock.key is None
    assert event_producer_mock.event is None
Exemplo n.º 3
0
def test_checkin_checkin_frequency_invalid(event_producer_mock, db_create_host, api_post, mocker, checkin_frequency):
    canonical_facts = {"insights_id": generate_uuid()}
    created_host = db_create_host(extra_data={"canonical_facts": canonical_facts})

    post_doc = {**created_host.canonical_facts, "checkin_frequency": checkin_frequency}
    response_status, response_data = api_post(
        build_host_checkin_url(), post_doc, extra_headers={"x-rh-insights-request-id": "123456"}
    )

    assert_response_status(response_status, expected_status=400)
Exemplo n.º 4
0
def test_checkin_checkin_frequency_valid(event_producer_mock, db_create_host, api_post, mocker):
    canonical_facts = {"insights_id": generate_uuid()}
    created_host = db_create_host(extra_data={"canonical_facts": canonical_facts})

    deserialize_canonical_facts_mock = mocker.patch(
        "api.host.deserialize_canonical_facts", wraps=deserialize_canonical_facts
    )

    post_doc = {**created_host.canonical_facts, "checkin_frequency": 720}
    response_status, response_data = api_post(
        build_host_checkin_url(), post_doc, extra_headers={"x-rh-insights-request-id": "123456"}
    )

    assert_response_status(response_status, expected_status=201)
    deserialize_canonical_facts_mock.assert_called_once_with(post_doc)
def test_checkin(event_datetime_mock, event_producer_mock, db_create_host, db_get_host, api_post):
    created_host = db_create_host()

    post_doc = created_host.canonical_facts
    updated_time = created_host.modified_on

    response_status, response_data = api_post(
        build_host_checkin_url(), post_doc, extra_headers={"x-rh-insights-request-id": "123456"}
    )

    assert_response_status(response_status, expected_status=201)
    record = db_get_host(created_host.id)

    assert record.modified_on > updated_time
    assert record.stale_timestamp == created_host.stale_timestamp
    assert record.reporter == created_host.reporter

    assert_patch_event_is_valid(
        created_host, event_producer_mock, "123456", event_datetime_mock, created_host.display_name
    )