Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Tests
on: [push]
jobs:
test-here-api:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v2
- uses: actions/setup-ruby@v1
with:
ruby-version: '2.5'
- name: Cache layers and gems
id: cache
uses: actions/cache@v2
with:
path: |
vendor/bundle
key: ${{ runner.os }}-${{ hashFiles('Gemfile.lock') }}
- name: Check cached gems
run: |
echo $(pwd)
echo $(ls -lh vendor/bundle)
- name: Install required libs
run: |
sudo apt-get update
sudo apt-get install -y git build-essential zlib1g-dev zlib1g
pip3 install flexpolyline
- name: Bundle ruby
run: |
gem install bundler --version 1.17.3
bundle install --path vendor/bundle --full-index -j $(nproc)
- name: Ruby test
run: bundle exec rake test TEST=test/wrappers/here_test.rb
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ gem 'puma'
gem 'rack-cors'
gem 'rack-server-pages', '~> 0.1.0'

gem 'grape'
gem 'grape', '>=1.5.3'
gem 'grape_logging'
gem 'grape-entity'
gem 'grape-swagger'
Expand All @@ -28,6 +28,7 @@ group :test do
gem 'minitest-reporters'
gem 'rack-test'
gem 'simplecov', require: false
gem 'webmock'
end

group :development, :test do
Expand All @@ -36,6 +37,7 @@ end

gem 'dotenv'
gem 'polylines'
gem 'pycall'

group :production do
gem 'redis'
Expand Down
61 changes: 36 additions & 25 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
GEM
remote: https://rubygems.org/
specs:
actionpack (5.2.4.5)
actionview (= 5.2.4.5)
activesupport (= 5.2.4.5)
actionpack (5.2.6)
actionview (= 5.2.6)
activesupport (= 5.2.6)
rack (~> 2.0, >= 2.0.8)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.2.4.5)
activesupport (= 5.2.4.5)
actionview (5.2.6)
activesupport (= 5.2.6)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activesupport (5.2.4.5)
activesupport (5.2.6)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
Expand All @@ -27,24 +27,26 @@ GEM
builder (3.2.4)
byebug (11.1.3)
concurrent-ruby (1.1.8)
crack (0.4.5)
rexml
crass (1.0.6)
docile (1.3.5)
domain_name (0.5.20190701)
docile (1.1.5)
domain_name (0.5.20170404)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.7.6)
dotenv (2.2.1)
dry-configurable (0.12.1)
concurrent-ruby (~> 1.0)
dry-core (~> 0.5, >= 0.5.0)
dry-container (0.7.2)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.1, >= 0.1.3)
dry-core (0.5.0)
dry-core (0.6.0)
concurrent-ruby (~> 1.0)
dry-inflector (0.2.0)
dry-logic (1.1.0)
dry-logic (1.2.0)
concurrent-ruby (~> 1.0)
dry-core (~> 0.5, >= 0.5)
dry-types (1.5.0)
dry-types (1.5.1)
concurrent-ruby (~> 1.0)
dry-container (~> 0.3)
dry-core (~> 0.5, >= 0.5)
Expand All @@ -53,15 +55,15 @@ GEM
erubi (1.10.0)
fakeredis (0.8.0)
redis (~> 4.1)
grape (1.5.2)
grape (1.6.0)
activesupport
builder
dry-types (>= 1.1)
mustermann-grape (~> 1.0.0)
rack (>= 1.3.0)
rack-accept
grape-entity (0.8.2)
activesupport (>= 3.0.0)
grape-entity (0.7.1)
activesupport (>= 4.0)
multi_json (>= 1.3.2)
grape-swagger (1.3.1)
grape (~> 1.3)
Expand All @@ -71,27 +73,28 @@ GEM
grape_logging (1.8.4)
grape
rack
hashdiff (1.0.1)
http-accept (1.7.0)
http-cookie (1.0.3)
domain_name (~> 0.5)
i18n (1.8.9)
i18n (1.8.11)
concurrent-ruby (~> 1.0)
loofah (2.9.0)
loofah (2.13.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mime-types (3.3.1)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2021.0212)
mini_portile2 (2.5.0)
minitest (5.14.3)
minitest-focus (1.2.1)
mime-types-data (3.2016.0521)
mini_portile2 (2.5.3)
minitest (5.14.4)
minitest-focus (1.1.2)
minitest (>= 4, < 6)
minitest-reporters (1.4.3)
ansi
builder
minitest (>= 5.0)
ruby-progressbar
multi_json (1.15.0)
multi_json (1.13.1)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
mustermann-grape (1.0.1)
Expand All @@ -105,6 +108,7 @@ GEM
public_suffix (4.0.6)
puma (5.5.1)
nio4r (~> 2.0)
pycall (1.4.1)
racc (1.5.2)
rack (2.2.3)
rack-accept (0.4.5)
Expand All @@ -120,7 +124,7 @@ GEM
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.3.0)
rails-html-sanitizer (1.4.2)
loofah (~> 2.3)
rake (13.0.3)
redis (4.2.5)
Expand All @@ -134,6 +138,7 @@ GEM
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rexml (3.2.5)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.4)
simplecov (0.21.2)
Expand All @@ -148,6 +153,10 @@ GEM
unf (0.1.4)
unf_ext
unf_ext (0.0.7.7)
webmock (3.14.0)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)

PLATFORMS
ruby
Expand All @@ -160,7 +169,7 @@ DEPENDENCIES
byebug
dotenv
fakeredis
grape
grape (>= 1.5.3)
grape-entity
grape-swagger
grape-swagger-entity
Expand All @@ -171,6 +180,7 @@ DEPENDENCIES
minitest-reporters
polylines
puma
pycall
rack
rack-contrib
rack-cors
Expand All @@ -182,6 +192,7 @@ DEPENDENCIES
redis-store (~> 1.4.1)
rest-client
simplecov
webmock

RUBY VERSION
ruby 2.5.7p206
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Install package containing ogr2ogr exec from system package (GDAL).
In router-wrapper as root directory:

```
pip3 install flexpolyline
bundle install
```

Expand Down
2 changes: 1 addition & 1 deletion api/v01/api_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def self.count_route_locations(params)
def self.count_matrix_locations(params)
src_size = count_locations(params[:src])
dst_size = params[:dst] ? count_locations(params[:dst]) : src_size
src_size * dst_size
[src_size, dst_size].max
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ module RouterWrapper
CROW = Wrappers::Crow.new(CACHE, boundary: 'poly/france-marseille.kml')
OSRM = Wrappers::Osrm.new(CACHE, url_time: 'http://localhost:5000', url_distance: 'http://localhost:5000', url_isochrone: 'http://localhost:1723', url_isodistance: 'http://localhost:1723', track: true, toll: true, motorway: true, area_mapping: area_mapping, whitelist_classes: whitelist_classes, with_summed_by_area: true, licence: 'ODbL', attribution: '© OpenStreetMap contributors', area: 'Europe', boundary: 'poly/europe.kml')
OTP_BORDEAUX = Wrappers::Otp.new(CACHE, url: 'http://localhost:7001', router_id: 'bordeaux', licence: 'ODbL', attribution: 'Bordeaux Métropole', area: 'Bordeaux', crs: 'EPSG:2154')
HERE_TRUCK = Wrappers::Here.new(CACHE, app_id: ENV['HERE_APP_ID'], app_code: ENV['HERE_APP_CODE'], mode: 'truck')
HERE_CAR = Wrappers::Here.new(CACHE, app_id: ENV['HERE_APP_ID'], app_code: ENV['HERE_APP_CODE'], mode: 'car')
ENV['HERE_API_KEY'] = ENV['HERE_API_KEY'] || 'abcdef'
HERE_TRUCK = Wrappers::Here.new(CACHE, api_key: ENV['HERE_API_KEY'], mode: 'truck')
HERE_CAR = Wrappers::Here.new(CACHE, api_key: ENV['HERE_API_KEY'], mode: 'car')

PARAMS_LIMIT = { locations: 10000 }.freeze
REDIS_COUNT = Redis.new # Fake redis
Expand Down
1 change: 1 addition & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ WORKDIR /srv/app
# because of Certificate verification failed
RUN apt update ; apt upgrade -y
RUN apt-get install -y git build-essential zlib1g-dev zlib1g > /dev/null
RUN pip3 install flexpolyline
RUN gem install bundler --version 1.17.3
RUN bundle install --path vendor/bundle --full-index --without ${BUNDLE_WITHOUT}

Expand Down
18 changes: 9 additions & 9 deletions test/api/v01/api_base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@
class Api::V01::APIBaseTest < Minitest::Test
def test_count_locations
lat, lng = 1, 1
assert 2, Api::V01::APIBase.count_locations([[[lat, lng], [lat, lng]]])
assert 2, Api::V01::APIBase.count_locations([[lat, lng], [lat, lng]])
assert 2, Api::V01::APIBase.count_locations([lat, lng, lat, lng])
assert 2, Api::V01::APIBase.count_locations('lat,lng,lat,lng')
assert 0, Api::V01::APIBase.count_locations(nil)
assert_equal 2, Api::V01::APIBase.count_locations([[[lat, lng], [lat, lng]]])
assert_equal 2, Api::V01::APIBase.count_locations([[lat, lng], [lat, lng]])
assert_equal 2, Api::V01::APIBase.count_locations([lat, lng, lat, lng])
assert_equal 2, Api::V01::APIBase.count_locations('lat,lng,lat,lng')
assert_equal 0, Api::V01::APIBase.count_locations(nil)
end

def test_count_matrix_locations
assert 2, Api::V01::APIBase.count_matrix_locations(src: 'lat,lng,lat,lng', dest: 'lat,lng,lat,lng')
assert 2, Api::V01::APIBase.count_matrix_locations(src: 'lat,lng,lat,lng')
assert_equal 2, Api::V01::APIBase.count_matrix_locations(src: 'lat,lng,lat,lng', dest: 'lat,lng')
assert_equal 12, Api::V01::APIBase.count_matrix_locations(src: 'lat,lng,lat,lng,lat,lng,lat,lng,lat,lng,lat,lng,lat,lng,lat,lng,lat,lng,lat,lng,lat,lng,lat,lng')
end

def test_count_route_locations
assert 2, Api::V01::APIBase.count_matrix_locations(loc: 'lat,lng,lat,lng')
assert 2, Api::V01::APIBase.count_matrix_locations(locs: 'lat,lng,lat,lng')
assert_equal 2, Api::V01::APIBase.count_route_locations(loc: 'lat,lng,lat,lng')
assert_equal 12, Api::V01::APIBase.count_route_locations(locs: 'lat,lng,lat,lng,lat,lng,lat,lng,lat,lng,lat,lng,lat,lng,lat,lng,lat,lng,lat,lng,lat,lng,lat,lng')
end
end
10 changes: 10 additions & 0 deletions test/api/v01/isoline_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
class Api::V01::IsolineTest < Minitest::Test
include Rack::Test::Methods

def setup
@stubs = [
stub_request(:get, %r{0.1/isochrone\?.*lat=-?\d+\.\d+&lng=-?\d+\.\d+&time=\d+}).to_return(status: 200, body: File.new(File.expand_path('../../', __dir__) + '/fixtures/isoline-default.json').read),
]
end

def teardown
@stubs.each { |stub| remove_request_stub(stub) } if @stubs
end

def app
Api::Root
end
Expand Down
29 changes: 29 additions & 0 deletions test/fixtures/isoline-default-v8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"departure": {
"time": "2021-12-20T13:37:44+01:00",
"place": {
"type": "place",
"location": {
"lat": 49.6106295,
"lng": 18.2376727
},
"originalLocation": {
"lat": 49.6107099,
"lng": 18.2373049
}
}
},
"isolines": [
{
"range": {
"type": "time",
"value": 300
},
"polygons": [
{
"outer": "BGwtw1-C0_43iBAqmF3KmgBlgB2K7qBAlgB4K9qB-qB3KmgB4KmgBuVuVwVsgCuVuV4KmgBA-qB3KmgBtVuVvVsgClgB4K51CAlgB2KAwV-qB8qBsgCwV2KmgBA4gE1KmgB9qB8qBlgB4K9qBAlgB4KtVuVrgCuV51C61C3KmgBA4gE3KmgB7qB-qBrgCuVvV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