コード例 #1
0
def test_update(shared_client, cleanup, scan_host, src_type):
    """Create a {network, vcenter} source and then update it.

    :id: 900dda70-6208-44f5-b64d-f6ca4db7dfa4
    :description: Create {network, vcenter} source of single host and
        credential
    :steps:
        1) Create host credential
        2) Send POST with data to create {network, vcenter} source using the
           host credential to the source endpoint.
        3) Add a host and a new credential and send and PUT to the server with
           the data
    :expectedresults: The source entry is created and updated.
    """
    cred = Credential(cred_type=src_type, client=shared_client, password=uuid4())
    cred.create()
    cleanup.append(cred)
    src = Source(
        source_type=src_type,
        client=shared_client,
        hosts=[scan_host],
        credential_ids=[cred._id],
    )
    src.create()
    cleanup.append(src)
    assert_matches_server(src)
    src.hosts = ["example.com"]
    cred2 = Credential(cred_type=src_type, password=uuid4())
    cred2.create()
    cleanup.append(cred2)
    src.credentials = [cred2._id]
    src.update()
    assert_matches_server(src)
コード例 #2
0
def test_update_empty_str_host_valid(shared_client, cleanup):
    """Create a host manager source and then add host data with empty string.

    :id: 850b06ba-8e3f-4699-b24b-e75aad20a63a
    :description: Assert that we can update a source with hosts including an
         empty string, but the empty string is filtered out.
    :steps:
        1) Create a valid network credential and source
        2) Attempt to update with host list including empty string
        3) Assert update is made but with the empty string filtered out.
    :expectedresults: Source is updated with only valid host list.
    """
    empty_str_host_data = ["192.0.2.1", "192.0.2.10", ""]
    hosts_without_empty_str = ["192.0.2.1", "192.0.2.10"]
    # initialize & create original credential & source
    pwd_cred = Credential(
        cred_type=NETWORK_TYPE, client=shared_client, password=uuid4()
    )
    pwd_cred.create()

    src = Source(
        source_type=NETWORK_TYPE,
        client=shared_client,
        hosts=["127.0.0.1"],
        credential_ids=[pwd_cred._id],
    )
    src.create()

    # add the ids to the lists to destroy after the test is done
    cleanup.extend([pwd_cred, src])
    src.hosts = empty_str_host_data
    updated_data = src.update().json()
    assert updated_data["hosts"] == hosts_without_empty_str