geo_ip_test.rb 2.6 KB

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