示例#1
0
def test_replace_facts_without_fact_dict(api_put):
    facts_url = build_facts_url(1, DB_FACTS_NAMESPACE)
    response_status, response_data = api_put(facts_url, None)

    assert_error_response(response_data,
                          expected_status=400,
                          expected_detail="Request body is not valid JSON")
示例#2
0
def test_get_system_profile_with_invalid_host_id(api_get, invalid_host_id):
    response_status, response_data = api_get(
        f"{HOST_URL}/{invalid_host_id}/system_profile")

    assert_error_response(response_data,
                          expected_title="Bad Request",
                          expected_status=400)
示例#3
0
def test_add_facts_without_fact_dict(api_patch, db_create_host):
    facts_url = build_facts_url(host_list_or_id=1,
                                namespace=DB_FACTS_NAMESPACE)
    response_status, response_data = api_patch(facts_url, None)

    assert_error_response(response_data,
                          expected_status=400,
                          expected_detail="Request body is not valid JSON")
示例#4
0
def test_create_host_with_null_system_profile(api_create_or_update_host):
    host = minimal_host(system_profile=None)

    # Create the host without a system profile
    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_error_response(multi_response_data,
                          expected_title="Bad Request",
                          expected_status=400)
示例#5
0
def test_create_host_without_required_fields(api_create_or_update_host, field):
    host = minimal_host()
    delattr(host, field)

    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_error_response(multi_response_data,
                          expected_title="Bad Request",
                          expected_status=400)
示例#6
0
def test_create_host_with_invalid_facts(api_create_or_update_host,
                                        invalid_facts):
    host = minimal_host(facts=invalid_facts)

    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_error_response(multi_response_data,
                          expected_title="Bad Request",
                          expected_status=400)
def test_get_host_tag_part_too_long(tag_query, part_name, mq_create_three_specific_hosts, api_get):
    """
    send a request to find hosts with a string tag where the length
    of the namespace excedes the 255 character limit
    """

    url = build_hosts_url(query=f"?tags={tag_query}")
    response_status, response_data = api_get(url)

    assert_error_response(
        response_data, expected_status=400, expected_detail=f"{part_name} is longer than 255 characters"
    )
示例#8
0
def test_create_host_with_null_culling_fields(api_create_or_update_host,
                                              culling_fields):
    host = minimal_host(fqdn="match this host",
                        **{field: None
                           for field in culling_fields})

    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_error_response(multi_response_data,
                          expected_title="Bad Request",
                          expected_status=400)
示例#9
0
def test_create_host_without_culling_fields(api_create_or_update_host,
                                            fields_to_delete):
    host = minimal_host(fqdn="match this host")
    for field in fields_to_delete:
        delattr(host, field)

    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_error_response(multi_response_data,
                          expected_title="Bad Request",
                          expected_status=400)
示例#10
0
def test_create_host_with_invalid_stale_timestamp(api_create_or_update_host):
    host = minimal_host(stale_timestamp="not a timestamp")

    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_response_status(multi_response_status, 207)

    host_response = get_host_from_multi_response(multi_response_data)

    assert_error_response(host_response,
                          expected_title="Bad Request",
                          expected_status=400)
示例#11
0
def test_create_host_without_account(api_create_or_update_host):
    host = minimal_host()
    del host.account

    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_error_response(
        multi_response_data,
        expected_title="Bad Request",
        expected_detail="'account' is a required property - '0'",
        expected_status=400,
    )
示例#12
0
def test_create_host_with_non_nullable_fields_as_none(
        api_create_or_update_host, non_nullable_field):
    # Have at least one good canonical fact set
    host = minimal_host(insights_id=generate_uuid(),
                        rhel_machine_id=generate_uuid())
    # Set a null canonical fact
    setattr(host, non_nullable_field, None)

    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_error_response(multi_response_data,
                          expected_title="Bad Request",
                          expected_status=400)
示例#13
0
def test_create_host_with_empty_culling_fields(api_create_or_update_host,
                                               culling_fields):
    host = minimal_host(**{field: "" for field in culling_fields})

    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_response_status(multi_response_status, 207)

    host_response = get_host_from_multi_response(multi_response_data)

    assert_error_response(host_response,
                          expected_title="Bad Request",
                          expected_status=400)
示例#14
0
def test_create_host_with_empty_json_key_in_system_profile(
        api_create_or_update_host, sample):
    host = minimal_host(system_profile=sample)

    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_response_status(multi_response_status, 207)

    host_response = get_host_from_multi_response(multi_response_data)

    assert_error_response(host_response,
                          expected_title="Bad Request",
                          expected_status=400)
示例#15
0
def test_create_host_with_empty_json_key_in_facts(api_create_or_update_host,
                                                  facts):
    host = minimal_host(facts=facts)

    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_response_status(multi_response_status, 207)

    host_response = get_host_from_multi_response(multi_response_data)

    assert_error_response(host_response,
                          expected_title="Bad Request",
                          expected_status=400)
示例#16
0
def test_create_host_with_invalid_external_id(api_create_or_update_host,
                                              invalid_external_id):
    host = minimal_host(external_id=invalid_external_id)

    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_response_status(multi_response_status, 207)

    host_response = get_host_from_multi_response(multi_response_data)

    assert_error_response(host_response,
                          expected_title="Bad Request",
                          expected_status=400)
示例#17
0
def test_create_host_with_invalid_mac_address(api_create_or_update_host,
                                              invalid_mac_array):
    host = minimal_host(insights_id=generate_uuid(),
                        mac_addresses=invalid_mac_array)

    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_response_status(multi_response_status, 207)

    host_response = get_host_from_multi_response(multi_response_data)

    assert_error_response(host_response,
                          expected_title="Bad Request",
                          expected_status=400)
示例#18
0
def test_rest_post_disabling(disable_rest_api_post, api_create_or_update_host):
    host = minimal_host()

    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_response_status(multi_response_status, 405)

    assert_error_response(
        response=multi_response_data,
        expected_status=405,
        expected_title="Method Not Allowed",
        expected_detail="The method is not allowed for the requested URL.",
        expected_type="about:blank",
    )
示例#19
0
def test_create_host_with_invalid_uuid_field_values(api_create_or_update_host,
                                                    uuid_field):
    host = minimal_host()
    setattr(host, uuid_field, "notauuid")

    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_response_status(multi_response_status, 207)

    host_response = get_host_from_multi_response(multi_response_data)

    assert_error_response(host_response,
                          expected_title="Bad Request",
                          expected_status=400)
示例#20
0
def test_create_host_with_system_profile_with_invalid_data(
        api_create_or_update_host, api_get, system_profile):
    host = minimal_host(system_profile=system_profile)

    # Create the host
    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_response_status(multi_response_status, 207)

    host_response = get_host_from_multi_response(multi_response_data)

    assert_error_response(host_response,
                          expected_title="Bad Request",
                          expected_status=400)
示例#21
0
def test_create_host_with_invalid_account(api_create_or_update_host, account):
    host = minimal_host(account=account)

    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_response_status(multi_response_status, 207)

    host_response = get_host_from_multi_response(multi_response_data)

    assert_error_response(
        host_response,
        expected_title="Bad Request",
        expected_detail="{'account': ['Length must be between 1 and 10.']}",
        expected_status=400,
    )
示例#22
0
def test_create_host_with_mismatched_account_numbers(
        api_create_or_update_host):
    host = minimal_host(account=ACCOUNT[::-1])

    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_response_status(multi_response_status, 207)

    host_response = get_host_from_multi_response(multi_response_data)

    assert_error_response(
        host_response,
        expected_title="Invalid request",
        expected_detail=
        "The account number associated with the user does not match the account number associated "
        "with the host",
        expected_status=400,
    )
示例#23
0
def test_create_host_with_too_long_mac_address(api_create_or_update_host):
    system_profile = {
        "network_interfaces": [{
            "mac_address":
            "00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33:44"
        }]
    }

    host = minimal_host(system_profile=system_profile)

    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_response_status(multi_response_status, 207)

    host_response = get_host_from_multi_response(multi_response_data)

    assert_error_response(host_response,
                          expected_title="Bad Request",
                          expected_status=400)
示例#24
0
def test_create_host_without_canonical_facts(api_create_or_update_host):
    host = minimal_host()
    del host.insights_id
    del host.rhel_machine_id
    del host.subscription_manager_id
    del host.satellite_id
    del host.bios_uuid
    del host.ip_addresses
    del host.fqdn
    del host.mac_addresses
    del host.external_id

    multi_response_status, multi_response_data = api_create_or_update_host(
        [host])

    assert_response_status(multi_response_status, 207)

    host_response = get_host_from_multi_response(multi_response_data)

    assert_error_response(host_response,
                          expected_title="Invalid request",
                          expected_status=400)