geo_ip_test.rb 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # encoding: utf-8
  2. require 'integration_test_helper'
  3. class GeoIpTest < ActiveSupport::TestCase
  4. # check
  5. test 'check some results' do
  6. result = Service::GeoIp.location('127.0.0.0.1')
  7. assert(result)
  8. assert_equal(nil, result['country_name'])
  9. assert_equal(nil, result['city_name'])
  10. assert_equal(nil, result['country_code'])
  11. assert_equal(nil, result['continent_code'])
  12. assert_equal(nil, result['latitude'])
  13. assert_equal(nil, result['longitude'])
  14. result = Service::GeoIp.location('127.0.0.1')
  15. assert(result)
  16. assert_equal(nil, result['country_name'])
  17. assert_equal(nil, result['city_name'])
  18. assert_equal(nil, result['country_code'])
  19. assert_equal(nil, result['continent_code'])
  20. assert_equal(nil, result['latitude'])
  21. assert_equal(nil, result['longitude'])
  22. result = Service::GeoIp.location('195.65.29.254')
  23. assert(result)
  24. assert_equal('Switzerland', result['country_name'])
  25. assert_equal('Regensdorf', result['city_name'])
  26. assert_equal('CH', result['country_code'])
  27. assert_equal('EU', result['continent_code'])
  28. assert_equal(47.4319, result['latitude'])
  29. assert_equal(8.4658, result['longitude'])
  30. result = Service::GeoIp.location('134.109.140.74')
  31. assert(result)
  32. assert_equal('Germany', result['country_name'])
  33. assert_equal('Chemnitz', result['city_name'])
  34. assert_equal('DE', result['country_code'])
  35. assert_equal('EU', result['continent_code'])
  36. assert_equal(50.8333, result['latitude'])
  37. assert_equal(12.9167, result['longitude'])
  38. result = Service::GeoIp.location('46.253.55.170')
  39. assert(result)
  40. assert_equal('Germany', result['country_name'])
  41. assert_equal('Halle', result['city_name'])
  42. assert_equal('DE', result['country_code'])
  43. assert_equal('EU', result['continent_code'])
  44. assert_equal(51.5034, result['latitude'])
  45. assert_equal(11.9622, result['longitude'])
  46. result = Service::GeoIp.location('169.229.216.200')
  47. assert(result)
  48. assert_equal('United States', result['country_name'])
  49. assert_equal('Berkeley', result['city_name'])
  50. assert_equal('US', result['country_code'])
  51. assert_equal('NA', result['continent_code'])
  52. assert_equal(37.8668, result['latitude'])
  53. assert_equal(-122.2536, result['longitude'])
  54. result = Service::GeoIp.location('17.171.2.25')
  55. assert(result)
  56. assert_equal('United States', result['country_name'])
  57. assert_equal('Cupertino', result['city_name'])
  58. assert_equal('US', result['country_code'])
  59. assert_equal('NA', result['continent_code'])
  60. assert_equal(37.323, result['latitude'])
  61. assert_equal(-122.0322, result['longitude'])
  62. end
  63. end