metaodi / osmapi

Python wrapper for the OpenStreetMap API
http://osmapi.metaodi.ch/
GNU General Public License v3.0
213 stars 41 forks source link

test_deleted_element_raises_exception fails without network #80

Closed sebastic closed 7 years ago

sebastic commented 7 years ago

osmapi 1.0.0 fails to build due to test failures in build environments without network (like the Debian build chroots), test_deleted_element_raises_exception is not mocked unlike other tests:

======================================================================
ERROR: test_deleted_element_raises_exception (tests.functional_tests.TestOsmApiFunctional)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/httpretty/core.py", line 1146, in wrapper
    return test(*args, **kw)
  File "/build/python-osmapi-1.0.0/tests/functional_tests.py", line 16, in test_deleted_element_raises_exception
    api.RelationFull(2911456)
  File "/build/python-osmapi-1.0.0/osmapi/OsmApi.py", line 1134, in RelationFull
    data = self._get(uri)
  File "/build/python-osmapi-1.0.0/osmapi/OsmApi.py", line 1995, in _get
    return self._http('GET', path, False, None)
  File "/build/python-osmapi-1.0.0/osmapi/OsmApi.py", line 1975, in _http
    "Give up after %s retries" % i
MaximumRetryLimitReachedError: Give up after 5 retries
-------------------- >> begin captured stdout << ---------------------
HTTPSConnectionPool(host='www.openstreetmap.org', port=443): Max retries exceeded with url: /api/0.6/relation/2911456/full (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fd89418af90>: Failed to establish a new connection: [Errno 111] Connection refused',)))
HTTPSConnectionPool(host='www.openstreetmap.org', port=443): Max retries exceeded with url: /api/0.6/relation/2911456/full (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fd894129910>: Failed to establish a new connection: [Errno 111] Connection refused',)))
HTTPSConnectionPool(host='www.openstreetmap.org', port=443): Max retries exceeded with url: /api/0.6/relation/2911456/full (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fd894129a50>: Failed to establish a new connection: [Errno 111] Connection refused',)))
HTTPSConnectionPool(host='www.openstreetmap.org', port=443): Max retries exceeded with url: /api/0.6/relation/2911456/full (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fd894129a10>: Failed to establish a new connection: [Errno 111] Connection refused',)))
HTTPSConnectionPool(host='www.openstreetmap.org', port=443): Max retries exceeded with url: /api/0.6/relation/2911456/full (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fd894129b50>: Failed to establish a new connection: [Errno 111] Connection refused',)))

--------------------- >> end captured stdout << ----------------------
-------------------- >> begin captured logging << --------------------
urllib3.connectionpool: DEBUG: Starting new HTTPS connection (1): www.openstreetmap.org
urllib3.connectionpool: DEBUG: Starting new HTTPS connection (1): www.openstreetmap.org
urllib3.connectionpool: DEBUG: Starting new HTTPS connection (1): www.openstreetmap.org
urllib3.connectionpool: DEBUG: Starting new HTTPS connection (1): www.openstreetmap.org
urllib3.connectionpool: DEBUG: Starting new HTTPS connection (1): www.openstreetmap.org
--------------------- >> end captured logging << ---------------------

----------------------------------------------------------------------
Ran 82 tests in 15.345s
sebastic commented 7 years ago

The following patch may be sufficient, the test is skipped if the OFFLINE_TESTS environment variable is set:

--- a/tests/functional_tests.py
+++ b/tests/functional_tests.py
@@ -1,11 +1,16 @@
 import httpretty
 import unittest
 import osmapi
+import os

+from nose.plugins.skip import SkipTest

 class TestOsmApiFunctional(unittest.TestCase):
     @httpretty.activate
     def test_deleted_element_raises_exception(self):
+        if 'OFFLINE_TESTS' in os.environ:
+            raise SkipTest
+
         httpretty.register_uri(
             httpretty.GET,
             "https://www.openstreetmap.org/api/0.6/relation/2911456/full",
metaodi commented 7 years ago

@sebastic sorry about that, I'll look into it

metaodi commented 7 years ago

Fixed in #79, now test_deleted_element_raises_exception doesn't allow requests to unmocked URLs (they would cause an exception). I hope this solves your problem. The fix is released as v1.0.1.

sebastic commented 7 years ago

Unfortunately the test still fails in 1.0.1:

======================================================================
ERROR: test_deleted_element_raises_exception (tests.functional_tests.TestOsmApiFunctional)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/httpretty/core.py", line 1146, in wrapper
    return test(*args, **kw)
  File "/build/python-osmapi-1.0.1/tests/functional_tests.py", line 17, in test_deleted_element_raises_exception
    api.RelationFull(2911456)
  File "/build/python-osmapi-1.0.1/osmapi/OsmApi.py", line 1159, in RelationFull
    data = self._get(uri)
  File "/build/python-osmapi-1.0.1/osmapi/OsmApi.py", line 2023, in _get
    return self._http('GET', path, False, None)
  File "/build/python-osmapi-1.0.1/osmapi/OsmApi.py", line 2003, in _http
    "Give up after %s retries" % i
MaximumRetryLimitReachedError: Give up after 5 retries
-------------------- >> begin captured stdout << ---------------------
No mocking was registered, and real connections are not allowed (httpretty.allow_net_connect = False).
No mocking was registered, and real connections are not allowed (httpretty.allow_net_connect = False).
No mocking was registered, and real connections are not allowed (httpretty.allow_net_connect = False).
No mocking was registered, and real connections are not allowed (httpretty.allow_net_connect = False).
No mocking was registered, and real connections are not allowed (httpretty.allow_net_connect = False).

--------------------- >> end captured stdout << ----------------------
-------------------- >> begin captured logging << --------------------
urllib3.connectionpool: DEBUG: Starting new HTTPS connection (1): www.openstreetmap.org
urllib3.connectionpool: DEBUG: Starting new HTTPS connection (1): www.openstreetmap.org
urllib3.connectionpool: DEBUG: Starting new HTTPS connection (1): www.openstreetmap.org
urllib3.connectionpool: DEBUG: Starting new HTTPS connection (1): www.openstreetmap.org
urllib3.connectionpool: DEBUG: Starting new HTTPS connection (1): www.openstreetmap.org
--------------------- >> end captured logging << ---------------------

----------------------------------------------------------------------
Ran 81 tests in 15.261s
metaodi commented 7 years ago

@sebastic Okay, I removed the new test and use the same mock as all the other tests. Should be fine with v1.0.2

sebastic commented 7 years ago

Thanks, v1.0.2 builds successfully.