def test_registration_check_conn_error(get_proxies, _init_session, _):
    '''
    Connection error
        Returns None
    '''
    config = Mock(legacy_upload=False, base_url='example.com')
    conn = InsightsConnection(config)
    conn.get = MagicMock()
    conn.get.side_effect = requests.ConnectionError()
    assert conn.api_registration_check() is None
def test_request(get_proxies, init_session):
    """
    The request to get branch info is issued.
    """
    config = Mock(base_url="www.example.com", branch_info_url="https://www.example.com/branch_info")

    connection = InsightsConnection(config)
    connection.get = MagicMock()
    connection.get_branch_info()

    connection.get.assert_called_once_with(config.branch_info_url)
Example #3
0
def test_registration_check_conn_error(test_connection, get_proxies,
                                       _init_session, _):
    '''
    Can't connect, run connection test
        Returns False
    '''
    config = Mock(legacy_upload=True, base_url='example.com')
    conn = InsightsConnection(config)

    conn.get = MagicMock()
    conn.get.side_effect = requests.ConnectionError()
    assert conn.api_registration_check() is False
    test_connection.assert_called_once()
def test_registration_check_bad_res(get_proxies, _init_session, _):
    '''
    Failure HTTP response
        Returns None
    '''
    config = Mock(legacy_upload=False, base_url='example.com')
    conn = InsightsConnection(config)

    res = requests.Response()
    res._content = 'wakannai'
    res.status_code = 500

    conn.get = MagicMock(return_value=res)
    assert conn.api_registration_check() is None
def test_registration_check_parse_error(get_proxies, _init_session, _):
    '''
    Can't parse response
        Returns None
    '''
    config = Mock(legacy_upload=False, base_url='example.com')
    conn = InsightsConnection(config)

    res = requests.Response()
    res._content = 'zSDFasfghsRGH'
    res.status_code = 200

    conn.get = MagicMock(return_value=res)
    assert conn.api_registration_check() is None
Example #6
0
def test_registration_check_ok_reg(get_proxies, _init_session, _):
    '''
    Request completed OK, registered
        Returns True
    '''
    config = Mock(legacy_upload=True, base_url='example.com')
    conn = InsightsConnection(config)

    res = requests.Response()
    res._content = json.dumps({'unregistered_at': None})
    res.status_code = 200

    conn.get = MagicMock(return_value=res)
    assert conn.api_registration_check()
Example #7
0
def test_registration_check_ok_reg_then_unreg(get_proxies, _init_session, _):
    '''
    Request completed OK, was once registered but has been unregistered
        Returns the date it was unregistered
    '''
    config = Mock(legacy_upload=True, base_url='example.com')
    conn = InsightsConnection(config)

    res = requests.Response()
    res._content = json.dumps({'unregistered_at': '2019-04-10'})
    res.status_code = 200

    conn.get = MagicMock(return_value=res)
    assert conn.api_registration_check() == '2019-04-10'
def test_registration_check_ok_unreg(get_proxies, _init_session, _):
    '''
    Request completed OK, has not been registered
        Returns False
    '''
    config = Mock(legacy_upload=False, base_url='example.com')
    conn = InsightsConnection(config)

    res = requests.Response()
    res._content = json.dumps({
        "count": 0,
        "page": 1,
        "per_page": 50,
        "results": [],
        "total": 0
    })
    res.status_code = 200

    conn.get = MagicMock(return_value=res)
    assert conn.api_registration_check() is False