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)
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, )
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)
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)
def test_get_timezone_for_ip_api_error_types(error_body, expected_exception): setup_basic_api_response(body=json.dumps(error_body)) with assert_raises(expected_exception): tzupdate.get_timezone_for_ip()
def test_get_timezone_for_ip_explicit(ip_octets): setup_basic_api_response() ip_addr = '.'.join(map(str, ip_octets)) got_timezone = tzupdate.get_timezone_for_ip(ip_addr) eq(got_timezone, FAKE_TIMEZONE)
def test_get_timezone_for_ip_none(): setup_basic_api_response() got_timezone = tzupdate.get_timezone_for_ip() eq(got_timezone, FAKE_TIMEZONE)
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) )
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) )
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) )