Add test for GeoAPI driver lib

This commit is contained in:
Xavier J 2016-12-16 10:42:34 +01:00
parent 0aedeba125
commit f21f151c9c
4 changed files with 171 additions and 8 deletions

View file

@ -11,7 +11,15 @@ module Carto
end
def self.pays
File.open('lib/carto/geo_api/pays.json').read
File.open('app/lib/carto/geo_api/pays.json').read
end
def self.departements_url
'https://geo.api.gouv.fr/departements'
end
def self.regions_url
'https://geo.api.gouv.fr/regions'
end
private
@ -22,13 +30,6 @@ module Carto
nil
end
def self.departements_url
'https://geo.api.gouv.fr/departements'
end
def self.regions_url
'https://geo.api.gouv.fr/regions'
end
end
end
end

View file

@ -0,0 +1,70 @@
---
http_interactions:
- request:
method: get
uri: https://geo.api.gouv.fr/departements?fields=nom
body:
encoding: US-ASCII
string: ''
headers:
Accept:
- "*/*"
Accept-Encoding:
- gzip, deflate
User-Agent:
- rest-client/2.0.0 (darwin15.6.0 x86_64) ruby/2.3.1p112
response:
status:
code: 200
message: OK
headers:
Server:
- nginx
Date:
- Fri, 16 Dec 2016 09:25:41 GMT
Content-Type:
- application/json; charset=utf-8
Transfer-Encoding:
- chunked
Connection:
- keep-alive
Vary:
- Accept-Encoding
- Accept-Encoding
X-Powered-By:
- Express
Access-Control-Allow-Origin:
- "*"
Etag:
- W/"cc1-lXUcIlpPmDfvrGONl0WWsQ"
Strict-Transport-Security:
- max-age=15552000
Content-Encoding:
- gzip
body:
encoding: ASCII-8BIT
string: !binary |-
H4sIAAAAAAAAA22Wy27bMBBFfyXwJpsKqF96dOfYrZsibow4MFAUXTARGxOQ
xZYSjbpF/yfZ5w/0YyVlpDq0sxTmajg8vJzh1z+9Um9773oTVfbe9O51Lt3H
237v75suUpUSsQFjRaGkQXAYBH/IKspl9FHYWkZLo3eyvGeqEdStqIomhfsJ
CccnCRfCqFptA1VMlcmbx/sN10nCsCzL4O80CKvm8YE/Z4zaO4T6b4OQQ/ef
YD8guJN7o8G3T4YX2rpqHSgb3WyaZ7LuE+dUFDuRa8Dpk99UlLUoUAHJTTfC
yLJmgUT2Eo5e2CIN2U03POw+uU21Mc3jb65AcC5cSb/Flc275IPJsQGiVgjF
BRTT5tn5KD+/huMGBN0KHMnzidlqish7aqQNliDkmTa5fuAZDAh5pu0dDmBA
xjPTPG9ZOgm/t4YhQvWhSNbRlVYsmXA/qFJVdfMY5CDeuTDAOqQvD5fPCbRz
fQd2SG5zabCrIWnNlfuRzh4S18fmyQhb1MhLXJdF0W5trQqhgtUJ7rLMubEh
ubWxFzosnwQvqxDNkOw+WSNQHqldCbczbHxEbv44/MKh50fE5iWoaURuB+zH
CrJrY9GkLtzFVT8tE5FhKwPgEdFdaUYIzkV89SfnPiK4K/07JDciuYU/s1fY
j8hwIcqg147J0LUTnvqY8A6AjhVEuBB736m7wxsT30JaU2/a+ha6ks5pEBKg
E/K6j8lvoc2d2gi05jEhniYmvc9uUuxogDHpfXadBBWR2bViQTGJXQfAYgJb
inaYujEgFEwbE9nS7r1mFnaimNyWe9M8lc2Tn7X/vcd8rwzl7p9uRzE5Ium1
UW7SiIIXKybUC7ePmw2fGzGpel8cx8n1eEbGJHsw1UqEYzQh4UPwFVsnhL0S
3lzdbhNSXomdVgwGLbF97JxISHXpXjAgnpDkSvpLdzqHEyI8iLzzwwuWEOSX
nSxcLi5EjjNpf0Wr1sGUkOZKbznQUmK8dSt3eFKy86FXe09KiGuBaZeS4FrY
+yK4synprWWZO/ticfJbO/exZ6TkdrDHiYTU1rp6IJCUzL6EMzQlrFtp3LvU
N+uzXJ5dyOK7NmjOGeG9r6owU3bcGdur3h5zt88s8GDrk5Vr0XU0k+55AF0I
s/CpjoySBUCFk5yHTSkj07kVuSy0/cFiguvi0tfujRJMsSy4M3O7F8FmkmAW
irOb5smWiq/kLAnauNjrmi/YzF+Jb/8A5ygzwMEMAAA=
http_version:
recorded_at: Fri, 16 Dec 2016 09:25:37 GMT
recorded_with: VCR 3.0.3

View file

@ -0,0 +1,57 @@
---
http_interactions:
- request:
method: get
uri: https://geo.api.gouv.fr/regions?fields=nom
body:
encoding: US-ASCII
string: ''
headers:
Accept:
- "*/*"
Accept-Encoding:
- gzip, deflate
User-Agent:
- rest-client/2.0.0 (darwin15.6.0 x86_64) ruby/2.3.1p112
response:
status:
code: 200
message: OK
headers:
Server:
- nginx
Date:
- Fri, 16 Dec 2016 09:24:28 GMT
Content-Type:
- application/json; charset=utf-8
Transfer-Encoding:
- chunked
Connection:
- keep-alive
Vary:
- Accept-Encoding
- Accept-Encoding
X-Powered-By:
- Express
Access-Control-Allow-Origin:
- "*"
Etag:
- W/"2dd-2SAFdhiM3SIQ2017gqYxbw"
Strict-Transport-Security:
- max-age=15552000
Content-Encoding:
- gzip
body:
encoding: ASCII-8BIT
string: !binary |-
H4sIAAAAAAAAA11Ry2rDMBD8FeNLLxE0rybpzTE0F6eYHHopPSyWSASyNllJ
Abf0F/ofvucP/GO1aIvXPQm0M7MzO68fqcU6fUx3AaQyGM4qnaQVStX/3U/T
z8kfYA/ktdWXwAEzBtiFBiwfztmwgOTQtcFqtEx/MdJv0HvOf2DT7ssoIZV4
IrAVA025xVxZT0q8gEmkSgrUxJAzvmyLgY54tL+CJyVyrH3XDt5mK7b9GakG
KzWXW4/nUpTgosMcDGgnSl0BjRhzfqzMOKh68AnqM0QfGUll+7dAItD8jgtu
vITGxXAG/udbcvktKR9lhzxL3kZ2CdrHLaLQNQanrShRewzREPVXVG5grpaj
Hu0xKImVOPQ8p41BK/ZaalE21LW2a0dUXmEWropi1MOpu8XE5syx61FMwqvq
i/4Biby7eZXIu+w90GBswyPlSI7F3fRqb99L+pyA3QIAAA==
http_version:
recorded_at: Fri, 16 Dec 2016 09:24:25 GMT
recorded_with: VCR 3.0.3

View file

@ -0,0 +1,35 @@
require 'spec_helper'
describe Carto::GeoAPI::Driver do
describe '.regions', vcr: {cassette_name: 'geoapi_regions'} do
subject { described_class.regions }
it { expect(subject.code).to eq 200 }
end
describe '.departements', vcr: {cassette_name: 'geoapi_departements'} do
subject { described_class.departements }
it { expect(subject.code).to eq 200 }
end
describe '.pays' do
subject { described_class.pays }
it { is_expected.to eq File.open('app/lib/carto/geo_api/pays.json').read }
end
describe 'departements_url' do
subject { described_class.departements_url }
it { is_expected.to eq 'https://geo.api.gouv.fr/departements' }
end
describe 'regions_url' do
subject { described_class.regions_url }
it { is_expected.to eq 'https://geo.api.gouv.fr/regions' }
end
end