def test_system_profile_doesnt_use_staleness_parameter(mq_create_hosts_in_all_states, api_get):
    created_hosts = mq_create_hosts_in_all_states

    url = build_system_profile_url(host_list_or_id=created_hosts)
    response_status, response_data = api_get(url, query_parameters={"staleness": "fresh"})

    assert response_status == 400
def _test_order_by_id_desc(inventory_config, api_get, subtests, created_hosts, specifications, order_by, order_how):
    for updates, expected_added_hosts in specifications:
        # Update hosts to they have a same modified_on timestamp, but different IDs.
        # New modified_on value must be set explicitly so it’s saved the same to all
        # records. Otherwise SQLAlchemy would consider it unchanged and update it
        # automatically to its own "now" only for records whose ID changed.
        new_modified_on = now()

        for added_host_index, new_id in updates:
            host = update_host_in_db(created_hosts[added_host_index].id, id=new_id, modified_on=new_modified_on)
            created_hosts[added_host_index] = serialize_db_host(host, inventory_config)

        # Check the order in the response against the expected order. Only indexes
        # are passed, because self.added_hosts values were replaced during the
        # update.
        expected_hosts = tuple(created_hosts[added_host_index] for added_host_index in expected_added_hosts)

        urls = (HOST_URL, build_hosts_url(created_hosts), build_system_profile_url(created_hosts))
        for url in urls:
            with subtests.test(url=url, updates=updates):
                order_query_parameters = build_order_query_parameters(order_by=order_by, order_how=order_how)
                response_status, response_data = api_get(url, query_parameters=order_query_parameters)

                assert_response_status(response_status, expected_status=200)
                assert_host_ids_in_response(response_data, expected_hosts)
def test_get_system_profile_ignores_culled(mq_create_hosts_in_all_states, api_get):
    created_hosts = mq_create_hosts_in_all_states

    url = build_system_profile_url(host_list_or_id=created_hosts)
    response_status, response_data = api_get(url)

    assert response_status == 200
    assert created_hosts["culled"].id not in [host["id"] for host in response_data["results"]]
Exemple #4
0
def test_system_profile_includes_owner_id(mq_create_or_update_host, api_get,
                                          subtests):
    system_profile = valid_system_profile()
    host = minimal_host(system_profile=system_profile)
    created_host = mq_create_or_update_host(host)

    url = build_system_profile_url(host_list_or_id=created_host.id)

    response_status, response_data = api_get(url)
    assert response_data["results"][0]["system_profile"] == system_profile
    assert response_status == 200
def test_only_order_how(mq_create_three_specific_hosts, api_get, subtests):
    created_hosts = mq_create_three_specific_hosts

    urls = (
        HOST_URL,
        build_hosts_url(host_list_or_id=created_hosts),
        build_system_profile_url(host_list_or_id=created_hosts),
    )
    for url in urls:
        with subtests.test(url=url):
            order_query_parameters = build_order_query_parameters(order_by=None, order_how="ASC")
            response_status, response_data = api_get(url, query_parameters=order_query_parameters)
            assert response_status == 400
def tests_hosts_are_ordered_by_updated_ascending(mq_create_four_specific_hosts, api_get, subtests):
    created_hosts = mq_create_four_specific_hosts

    urls = (
        HOST_URL,
        build_hosts_url(host_list_or_id=created_hosts),
        build_system_profile_url(host_list_or_id=created_hosts),
    )
    order_query_parameters = build_order_query_parameters(order_by="updated", order_how="ASC")

    for url in urls:
        with subtests.test(url=url):
            response_status, response_data = api_get(url, query_parameters=order_query_parameters)
            assert_response_status(response_status, expected_status=200)
            assert_host_ids_in_response(response_data, expected_hosts=created_hosts)
def tests_hosts_are_ordered_by_updated_desc_by_default(mq_create_four_specific_hosts, api_get, subtests):
    created_hosts = mq_create_four_specific_hosts
    created_hosts.reverse()

    urls = (
        HOST_URL,
        build_hosts_url(host_list_or_id=created_hosts),
        build_system_profile_url(host_list_or_id=created_hosts),
    )

    for url in urls:
        with subtests.test(url=url):
            response_status, response_data = api_get(url)
            assert_response_status(response_status, expected_status=200)
            assert_host_ids_in_response(response_data, expected_hosts=created_hosts)
def tests_hosts_ordered_by_display_name_are_ascending_by_default(mq_create_four_specific_hosts, api_get, subtests):
    created_hosts = mq_create_four_specific_hosts
    expected_hosts = [created_hosts[3], created_hosts[0], created_hosts[1], created_hosts[2]]

    urls = (
        HOST_URL,
        build_hosts_url(host_list_or_id=created_hosts),
        build_system_profile_url(host_list_or_id=created_hosts),
    )
    order_query_parameters = build_order_query_parameters(order_by="display_name")

    for url in urls:
        with subtests.test(url=url):
            response_status, response_data = api_get(url, query_parameters=order_query_parameters)
            assert_response_status(response_status, expected_status=200)
            assert_host_ids_in_response(response_data, expected_hosts=expected_hosts)