Skip to content

Commit

Permalink
Merge pull request #4102 from hove-io/new_relic_external_service
Browse files Browse the repository at this point in the history
New relic added on external_service
  • Loading branch information
azime authored Sep 13, 2023
2 parents 06ce956 + 965a11d commit 6e94497
Show file tree
Hide file tree
Showing 7 changed files with 260 additions and 203 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class ExternalServiceError(RuntimeError):

@six.add_metaclass(abc.ABCMeta)
class AbstractExternalService(object):
@new_relic.distributedEvent("call_webservice", "external_service")
def _call_webservice(self, arguments):
"""
Call external_services webservice with URL defined in settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def get_response(self, arguments):
"""
Get free-floating information from Forseti webservice
"""
raw_response = self._call_webservice(arguments)
raw_response = self._call_webservice(self, arguments)

return self.response_marshaller(raw_response, arguments)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def get_response(self, arguments):
"""
Get vehicle_occupancy information from Forseti webservice
"""
raw_response = self._call_webservice(arguments)
raw_response = self._call_webservice(self, arguments)

# We don't need any further action if raw_response is None
if raw_response is None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def get_response(self, arguments):
"""
Get vehicle_position information from Forseti webservice
"""
raw_response = self._call_webservice(arguments)
raw_response = self._call_webservice(self, arguments)

# We don't need any further action if raw_response is None
if raw_response is None:
Expand Down
109 changes: 61 additions & 48 deletions source/jormungandr/tests/freefloatings_nearby_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
from __future__ import absolute_import, print_function, unicode_literals, division
from .tests_mechanism import AbstractTestFixture, dataset
from tests.check_utils import get_not_null
import pytest
from jormungandr.tests.utils_test import MockResponse
import mock
from six.moves.urllib.parse import urlencode
from jormungandr.tests.utils_test import MockRequests

MOCKED_INSTANCE_CONF = {
'scenario': 'new_default',
Expand All @@ -42,7 +43,7 @@
"id": "forseti_free_floatings",
"navitia_service": "free_floatings",
"args": {
"service_url": "http://wtf/free_floatings",
"service_url": "https://wtf/free_floatings",
"timeout": 10,
"circuit_breaker_max_fail": 4,
"circuit_breaker_reset_timeout": 60,
Expand Down Expand Up @@ -90,17 +91,6 @@
}


def mock_free_floating(_, params):
return MockResponse(FREE_FLOATINGS_RESPONSE, 200)


@pytest.fixture(scope="function", autouse=True)
def mock_http_free_floating(monkeypatch):
monkeypatch.setattr(
'jormungandr.external_services.free_floating.FreeFloatingProvider._call_webservice', mock_free_floating
)


@dataset({'main_routing_test': MOCKED_INSTANCE_CONF})
class TestFreeFloating(AbstractTestFixture):
"""
Expand All @@ -111,41 +101,64 @@ def test_freefloatings_nearby(self):
"""
simple freefloatings_nearby call
"""
response, status = self.query_no_assert(
'v1/coverage/main_routing_test/coord/2.37715%3B48.846781/freefloatings_nearby?count=5&start_page=1'
" https://wtf/free_floatings?type%5B%5D=None&distance=500&count=5&coord=2.37715%3B48.846781&start_page=1"
url = "https://wtf/free_floatings"
mock_requests = MockRequests(
{
'{}?{}'.format(
url,
urlencode(
{
"type[]": None,
"distance": 500,
"count": 5,
"coord": "2.37715;48.846781",
"start_page": 1,
}
),
): (
FREE_FLOATINGS_RESPONSE,
200,
)
}
)

warnings = get_not_null(response, 'warnings')
assert len(warnings) == 1
assert warnings[0]['id'] == 'beta_endpoint'
with mock.patch('requests.get', mock_requests.get):
response, status = self.query_no_assert(
'v1/coverage/main_routing_test/coord/2.37715%3B48.846781/freefloatings_nearby?count=5&start_page=1'
)

free_floatings = get_not_null(response, 'free_floatings')
assert len(free_floatings) == 3
# First free_floating doesn't contain all attributes
assert free_floatings[0]['public_id'] == '12009'
assert free_floatings[0]['provider_name'] == 'Velib'
assert free_floatings[0]['type'] == 'STATION'
assert free_floatings[0]['id'] == 'dmVsaWI6U1RBVElPTjoxMjAwOQ=='
assert free_floatings[0]['coord']['lat'] == '48.84617146118711'
assert free_floatings[0]['coord']['lon'] == '2.379306815564632'
warnings = get_not_null(response, 'warnings')
assert len(warnings) == 1
assert warnings[0]['id'] == 'beta_endpoint'

# Second free_floating contains more attributes
assert free_floatings[1]['public_id'] == 'FB-435-HD'
assert free_floatings[1]['distance'] == 100.55
assert free_floatings[1]['provider_name'] == 'Cityscoot'
assert free_floatings[1]['type'] == 'MOTORSCOOTER'
assert free_floatings[1]['id'] == 'Y2l0eXNjb290Ok1PVE9SU0NPT1RFUjpGQi00MzUtSEQ='
assert free_floatings[1]['coord']['lat'] == '48.848715'
assert free_floatings[1]['coord']['lon'] == '2.37618'
assert (
free_floatings[1]['deeplink']
== 'https://cityscoot.onelink.me/8GT9?pid=FLUCTUO&c=CS-API-FLUCTUO&af_dp=cityscoot%3A%2F%2Fcities%2F4%2Fscooters%2F18055&af_web_dp=https%3A%2F%2Fwww.cityscoot.eu%2F&af_force_deeplink=true'
)
assert free_floatings[1]['battery'] == 91
assert free_floatings[1]['propulsion'] == 'ELECTRIC'
assert free_floatings[1]['attributes'] == ['ELECTRIC']
assert 'pagination' in response
assert response['pagination']['start_page'] == 1
assert response['pagination']['items_on_page'] == 3
assert response['pagination']['items_per_page'] == 5
assert response['pagination']['total_result'] == 8
free_floatings = get_not_null(response, 'free_floatings')
assert len(free_floatings) == 3
# First free_floating doesn't contain all attributes
assert free_floatings[0]['public_id'] == '12009'
assert free_floatings[0]['provider_name'] == 'Velib'
assert free_floatings[0]['type'] == 'STATION'
assert free_floatings[0]['id'] == 'dmVsaWI6U1RBVElPTjoxMjAwOQ=='
assert free_floatings[0]['coord']['lat'] == '48.84617146118711'
assert free_floatings[0]['coord']['lon'] == '2.379306815564632'

# Second free_floating contains more attributes
assert free_floatings[1]['public_id'] == 'FB-435-HD'
assert free_floatings[1]['distance'] == 100.55
assert free_floatings[1]['provider_name'] == 'Cityscoot'
assert free_floatings[1]['type'] == 'MOTORSCOOTER'
assert free_floatings[1]['id'] == 'Y2l0eXNjb290Ok1PVE9SU0NPT1RFUjpGQi00MzUtSEQ='
assert free_floatings[1]['coord']['lat'] == '48.848715'
assert free_floatings[1]['coord']['lon'] == '2.37618'
assert (
free_floatings[1]['deeplink']
== 'https://cityscoot.onelink.me/8GT9?pid=FLUCTUO&c=CS-API-FLUCTUO&af_dp=cityscoot%3A%2F%2Fcities%2F4%2Fscooters%2F18055&af_web_dp=https%3A%2F%2Fwww.cityscoot.eu%2F&af_force_deeplink=true'
)
assert free_floatings[1]['battery'] == 91
assert free_floatings[1]['propulsion'] == 'ELECTRIC'
assert free_floatings[1]['attributes'] == ['ELECTRIC']
assert 'pagination' in response
assert response['pagination']['start_page'] == 1
assert response['pagination']['items_on_page'] == 3
assert response['pagination']['items_per_page'] == 5
assert response['pagination']['total_result'] == 8
Loading

0 comments on commit 6e94497

Please sign in to comment.