Beispiel #1
0
def test_timeout_results_in_exception(process_mock):
    # The process mock causes us to never run get_timezone_from_ip, so we
    # should time out
    setup_basic_api_response()
    args = ['-s', '0.01']
    with assert_raises(tzupdate.TimezoneAcquisitionError):
        tzupdate.main(args, services=FAKE_SERVICES)
Beispiel #2
0
def test_timeout_results_in_exception(process_mock):
    # The process mock causes us to never run get_timezone_from_ip, so we
    # should time out
    setup_basic_api_response()
    args = ["-s", "0.01"]
    with assert_raises(tzupdate.TimezoneAcquisitionError):
        tzupdate.main(args, services=FAKE_SERVICES)
Beispiel #3
0
def test_get_timezone_for_ip_empty_val(ip, service):
    fake_queue = mock.Mock()
    setup_basic_api_response(empty_val=True)
    with assert_raises(tzupdate.TimezoneAcquisitionError):
        tzupdate.get_timezone_for_ip(
            ip=ip,
            service=service,
            queue_obj=fake_queue,
        )
Beispiel #4
0
def test_get_timezone_for_ip(ip, service):
    fake_queue = mock.Mock()
    setup_basic_api_response()
    tzupdate.get_timezone_for_ip(ip=ip, service=service, queue_obj=fake_queue)

    if ip is not None:
        assert_in(ip, httpretty.last_request().path)

    fake_queue.put.assert_called_once_with(FAKE_TIMEZONE)
Beispiel #5
0
def test_end_to_end_no_args(link_localtime_mock, deb_tz_mock):
    setup_basic_api_response()
    args = []
    tzupdate.main(args, services=FAKE_SERVICES)
    link_localtime_mock.assert_called_once_with(
        FAKE_TIMEZONE, tzupdate.DEFAULT_ZONEINFO_PATH,
        tzupdate.DEFAULT_LOCALTIME_PATH)
    deb_tz_mock.assert_called_once_with(FAKE_TIMEZONE,
                                        tzupdate.DEFAULT_DEBIAN_TIMEZONE_PATH)
Beispiel #6
0
def test_end_to_end_no_args(link_localtime_mock, deb_tz_mock):
    setup_basic_api_response()
    args = []
    tzupdate.main(args, services=FAKE_SERVICES)
    link_localtime_mock.assert_called_once_with(
        FAKE_TIMEZONE, tzupdate.DEFAULT_ZONEINFO_PATH, tzupdate.DEFAULT_LOCALTIME_PATH
    )
    deb_tz_mock.assert_called_once_with(
        FAKE_TIMEZONE, tzupdate.DEFAULT_DEBIAN_TIMEZONE_PATH
    )
Beispiel #7
0
def test_explicit_paths(link_localtime_mock, deb_tz_mock):
    setup_basic_api_response()
    localtime_path = "/l"
    zoneinfo_path = "/z"
    deb_path = "/d"
    args = ["-l", localtime_path, "-z", zoneinfo_path, "-d", deb_path]
    tzupdate.main(args, services=FAKE_SERVICES)
    link_localtime_mock.assert_called_once_with(FAKE_TIMEZONE, zoneinfo_path,
                                                localtime_path)
    deb_tz_mock.assert_called_once_with(FAKE_TIMEZONE, deb_path, True)
Beispiel #8
0
def test_explicit_paths(link_localtime_mock, deb_tz_mock):
    setup_basic_api_response()
    localtime_path = "/l"
    zoneinfo_path = "/z"
    deb_path = "/d"
    args = ["-l", localtime_path, "-z", zoneinfo_path, "-d", deb_path]
    tzupdate.main(args, services=FAKE_SERVICES)
    link_localtime_mock.assert_called_once_with(
        FAKE_TIMEZONE, zoneinfo_path, localtime_path
    )
    deb_tz_mock.assert_called_once_with(FAKE_TIMEZONE, deb_path)
Beispiel #9
0
def test_explicit_paths(link_localtime_mock, deb_tz_mock):
    setup_basic_api_response()
    localtime_path = '/l'
    zoneinfo_path = '/z'
    deb_path = '/d'
    args = ['-l', localtime_path, '-z', zoneinfo_path, '-d', deb_path]
    tzupdate.main(args, services=FAKE_SERVICES)
    link_localtime_mock.assert_called_once_with(
        FAKE_TIMEZONE,
        zoneinfo_path,
        localtime_path,
    )
    deb_tz_mock.assert_called_once_with(FAKE_TIMEZONE, deb_path)
Beispiel #10
0
def test_explicit_ip(_unused_ll, _unused_deb):
    setup_basic_api_response()
    ip_addr = "1.2.3.4"
    args = ["-a", ip_addr]
    tzupdate.main(args, services=FAKE_SERVICES)
Beispiel #11
0
def test_print_only_no_link(link_localtime_mock, deb_tz_mock):
    setup_basic_api_response()
    args = ["-p"]
    tzupdate.main(args, services=FAKE_SERVICES)
    assert_false(link_localtime_mock.called)
    assert_false(deb_tz_mock.called)
Beispiel #12
0
def test_get_timezone_for_ip_empty_val(ip, service):
    fake_queue = mock.Mock()
    setup_basic_api_response(empty_val=True)
    assert_is_none(
        tzupdate.get_timezone_for_ip(ip=ip, service=service, queue_obj=fake_queue)
    )
Beispiel #13
0
def test_get_timezone_for_ip_empty_resp(ip, service):
    fake_queue = mock.Mock()
    setup_basic_api_response(empty_resp=True)
    assert_is_none(
        tzupdate.get_timezone_for_ip(ip=ip, service=service, queue_obj=fake_queue)
    )
Beispiel #14
0
def test_explicit_ip(_unused_ll, _unused_deb):
    setup_basic_api_response()
    ip_addr = '1.2.3.4'
    args = ['-a', ip_addr]
    tzupdate.main(args, services=FAKE_SERVICES)
Beispiel #15
0
def test_print_only_no_link(link_localtime_mock, deb_tz_mock):
    setup_basic_api_response()
    args = ['-p']
    tzupdate.main(args, services=FAKE_SERVICES)
    assert_false(link_localtime_mock.called)
    assert_false(deb_tz_mock.called)
Beispiel #16
0
def test_get_timezone_for_ip_empty_val(ip, service):
    fake_queue = mock.Mock()
    setup_basic_api_response(empty_val=True)
    assert (tzupdate.get_timezone_for_ip(
        ip_addr=ip, service=service, queue_obj=fake_queue) is None)
Beispiel #17
0
def test_get_timezone_for_ip_doesnt_raise(ip, service, status):
    fake_queue = mock.Mock()
    setup_basic_api_response(status=status)
    assert (tzupdate.get_timezone_for_ip(
        ip_addr=ip, service=service, queue_obj=fake_queue) is None)
Beispiel #18
0
def test_get_timezone_for_ip_doesnt_raise(ip, service, status):
    fake_queue = mock.Mock()
    setup_basic_api_response(status=status)
    assert_is_none(
        tzupdate.get_timezone_for_ip(ip=ip, service=service, queue_obj=fake_queue)
    )