File tree Expand file tree Collapse file tree 3 files changed +37
-1
lines changed Expand file tree Collapse file tree 3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 11KiB
22MPixel
33MiB
4+ MissingSchema
45Ubuntu
56admin
67api
Original file line number Diff line number Diff line change 66import re
77from contextlib import ContextDecorator
88from typing import Tuple , Union
9- from urllib .parse import urljoin
9+ from urllib .parse import urljoin , urlparse
1010
11+ import requests
1112from requests_mock .mocker import Mocker
1213
1314from mock_vws .database import VuforiaDatabase
@@ -45,13 +46,26 @@ def __init__( # pylint: disable=too-many-arguments
4546 query_recognizes_deletion_seconds: The number of seconds after a
4647 target has been deleted that the query endpoint will return a
4748 500 response for on a match.
49+
50+ Raises:
51+ ``requests.exceptions.MissingSchema``: There is no schema in a
52+ given URL.
4853 """
4954 super ().__init__ ()
5055 self ._real_http = real_http
5156 self ._mock : Mocker
5257
5358 self ._base_vws_url = base_vws_url
5459 self ._base_vwq_url = base_vwq_url
60+ missing_scheme_error = (
61+ 'Invalid URL "{url}": No scheme supplied. '
62+ 'Perhaps you meant "https://{url}".'
63+ )
64+ for url in (base_vwq_url , base_vws_url ):
65+ result = urlparse (url )
66+ if not result .scheme :
67+ error = missing_scheme_error .format (url = url )
68+ raise requests .exceptions .MissingSchema (error )
5569
5670 self ._mock_vws_api = MockVuforiaWebServicesAPI (
5771 processing_time_seconds = processing_time_seconds ,
Original file line number Diff line number Diff line change 1010
1111import pytest
1212import requests
13+ from requests .exceptions import MissingSchema
1314from requests_mock .exceptions import NoMockAddress
1415
1516from mock_vws import MockVWS
@@ -233,6 +234,26 @@ def test_custom_base_vwq_url(self) -> None:
233234 requests .post (url = 'https://vuforia.vwq.example.com/v1/query' )
234235 requests .get ('https://vws.vuforia.com/summary' )
235236
237+ def test_no_scheme (self ) -> None :
238+ """
239+ An error if raised if a URL is given with no scheme.
240+ """
241+ with pytest .raises (MissingSchema ) as exc :
242+ MockVWS (base_vws_url = 'vuforia.vws.example.com' )
243+
244+ expected = (
245+ 'Invalid URL "vuforia.vws.example.com": No scheme supplied. '
246+ 'Perhaps you meant "https://vuforia.vws.example.com".'
247+ )
248+ assert str (exc .value ) == expected
249+ with pytest .raises (MissingSchema ) as exc :
250+ MockVWS (base_vwq_url = 'vuforia.vwq.example.com' )
251+ expected = (
252+ 'Invalid URL "vuforia.vwq.example.com": No scheme supplied. '
253+ 'Perhaps you meant "https://vuforia.vwq.example.com".'
254+ )
255+ assert str (exc .value ) == expected
256+
236257
237258class TestCustomQueryRecognizesDeletionSeconds :
238259 """
You can’t perform that action at this time.
0 commit comments