Exemplo n.º 1
0
def test_request_unknown_exception(get_proxies, post, get_canonical_facts):
    """
    If an unknown exception occurs, the call crashes.
    """
    config = Mock(base_url="www.example.com")
    connection = InsightsConnection(config)

    expected_exception = type(post.side_effect)
    with raises(expected_exception):
        connection.checkin()
Exemplo n.º 2
0
def test_response_failure(get_proxies, post, get_canonical_facts, status_code):
    """
    If an unexpected status code is received, the check-in failed and an exception is raised.
    """
    post.return_value.status_code = status_code

    config = Mock(base_url="www.example.com")
    connection = InsightsConnection(config)

    with raises(Exception):
        connection.checkin()
Exemplo n.º 3
0
def test_canonical_facts_request(get_proxies, post, get_canonical_facts):
    """
    A POST requests to the check-in endpoint is issued with correct headers and
    body containing Canonical Facts.
    """
    config = Mock(base_url="www.example.com")

    connection = InsightsConnection(config)
    connection.checkin()

    expected_url = connection.inventory_url + "/hosts/checkin"
    expected_headers = {"Content-Type": "application/json"}
    expected_data = get_canonical_facts.return_value
    post.assert_called_once_with(expected_url,
                                 headers=expected_headers,
                                 data=dumps(expected_data))
Exemplo n.º 4
0
def test_insights_id_request(get_proxies, init_session, get_canonical_facts,
                             generate_machine_id):
    """
    A POST requests to the check-in endpoint is issued with correct headers and
    body containing only an Insights ID if Canonical Facts collection fails.
    """
    config = Mock(base_url="www.example.com")

    connection = InsightsConnection(config)
    connection.checkin()

    expected_url = connection.inventory_url + "/hosts/checkin"
    expected_headers = {"Content-Type": "application/json"}
    expected_data = {"insights_id": generate_machine_id.return_value}
    init_session.return_value.post.assert_called_once_with(
        expected_url, headers=expected_headers, data=dumps(expected_data))
Exemplo n.º 5
0
def test_response_success(get_proxies, post, get_canonical_facts):
    """
    If a CREATED status code is received, the check-in was successful.
    """
    config = Mock(base_url="www.example.com")
    connection = InsightsConnection(config)

    result = connection.checkin()
    assert result is True
Exemplo n.º 6
0
def test_request_http_failure(get_proxies, post, get_canonical_facts,
                              exception):
    """
    If the checkin-request fails, None is returned.
    """
    post.side_effect = exception

    config = Mock(base_url="www.example.com")

    connection = InsightsConnection(config)
    result = connection.checkin()
    assert result is None