[python-osmapi] 01/06: New upstream version 1.0.2

Bas Couwenberg sebastic at debian.org
Thu Sep 7 14:08:54 UTC 2017


This is an automated email from the git hooks/post-receive script.

sebastic pushed a commit to branch master
in repository python-osmapi.

commit 95ff0abc9f049bf8afa408baf93a0d0f2b7a1cd1
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date:   Thu Sep 7 15:58:25 2017 +0200

    New upstream version 1.0.2
---
 CHANGELOG.md                          |  7 ++++++
 README.md                             |  2 +-
 osmapi/OsmApi.py                      | 40 ++++++++++++++++++++++++++++-------
 osmapi/__init__.py                    |  2 +-
 test-requirements.txt                 |  1 -
 tests/changeset_tests.py              | 18 ++++++++--------
 tests/fixtures/test_WayGet_nodata.xml |  0
 tests/functional_tests.py             | 18 ----------------
 tests/relation_tests.py               |  7 ++++++
 tests/way_tests.py                    |  6 ++++++
 10 files changed, 63 insertions(+), 38 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 008dad5..c512de1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
 
 ## [Unreleased][unreleased]
 
+## 1.0.2 - 2017-09-07
+### Added
+- Rais ResponseEmptyApiError if we expect a response from the OpenStreetMap API, but didn't get one
+
+### Removed
+- Removed httpretty as HTTP mock library
+
 ## 1.0.1 - 2017-09-07
 ### Fixed
 - Make sure tests run offline
diff --git a/README.md b/README.md
index 4ba0fec..d536b11 100644
--- a/README.md
+++ b/README.md
@@ -96,7 +96,7 @@ To create a new release, follow these steps (please respect [Semantic Versioning
 
 1. Adapt the version number in `osmapi/__init__.py`
 1. Update the CHANGELOG with the version
-1. Create a pull request to merge develop into master
+1. Create a pull request to merge develop into master (make sure the tests pass!)
 1. Create a [new release/tag on GitHub](https://github.com/metaodi/osmapi/releases) (on the master branch)
 1. The [publication on PyPI](https://pypi.python.org/pypi/osmapi) happens via [Travis CI](https://travis-ci.org/metaodi/osmapi) on every tagged commit
 
diff --git a/osmapi/OsmApi.py b/osmapi/OsmApi.py
index a43efd3..4c18572 100644
--- a/osmapi/OsmApi.py
+++ b/osmapi/OsmApi.py
@@ -129,6 +129,13 @@ class ElementDeletedApiError(ApiError):
     pass
 
 
+class ResponseEmptyApiError(ApiError):
+    """
+    Error when the response to the request is empty
+    """
+    pass
+
+
 class OsmApi:
     """
     Main class of osmapi, instanciate this class to use osmapi
@@ -238,7 +245,7 @@ class OsmApi:
         try:
             if self._changesetauto:
                 self._changesetautoflush(True)
-        except ValueError:
+        except ResponseEmptyApiError:
             pass
 
         return None
@@ -1240,7 +1247,8 @@ class OsmApi:
             ChangesetTags["created_by"] = self._created_by
         self._put(
             "/api/0.6/changeset/%s" % (self._CurrentChangesetId),
-            self._XmlBuild("changeset", {"tag": ChangesetTags})
+            self._XmlBuild("changeset", {"tag": ChangesetTags}),
+            return_value=False
         )
         return self._CurrentChangesetId
 
@@ -1285,7 +1293,8 @@ class OsmApi:
             raise NoChangesetOpenError("No changeset currently opened")
         self._put(
             "/api/0.6/changeset/%s/close" % (self._CurrentChangesetId),
-            ""
+            "",
+            return_value=False
         )
         CurrentChangesetId = self._CurrentChangesetId
         self._CurrentChangesetId = 0
@@ -1920,7 +1929,7 @@ class OsmApi:
             self._changesetautocpt = 0
         return None
 
-    def _http_request(self, method, path, auth, send):  # noqa
+    def _http_request(self, method, path, auth, send, return_value=True):  # noqa
         """
         Returns the response generated by an HTTP request.
 
@@ -1933,6 +1942,8 @@ class OsmApi:
         be preformed on this request.
         `send` contains additional data that might be sent in a
         request.
+        `return_value` indicates wheter this request should return
+        any data or not.
 
         If the username or password is missing,
         `OsmApi.UsernamePasswordMissingError` is raised.
@@ -1971,6 +1982,13 @@ class OsmApi:
                     payload
                 )
             raise ApiError(response.status_code, response.reason, payload)
+        if return_value and not response.content:
+            raise ResponseEmptyApiError(
+                response.status_code,
+                response.reason,
+                ''
+            )
+
         if self._debug:
             error_msg = (
                 "%s %s %s"
@@ -1979,12 +1997,18 @@ class OsmApi:
             print(error_msg, file=sys.stderr)
         return response.content
 
-    def _http(self, cmd, path, auth, send):  # noqa
+    def _http(self, cmd, path, auth, send, return_value=True):  # noqa
         i = 0
         while True:
             i += 1
             try:
-                return self._http_request(cmd, path, auth, send)
+                return self._http_request(
+                    cmd,
+                    path,
+                    auth,
+                    send,
+                    return_value=return_value
+                )
             except ApiError as e:
                 if e.status >= 500:
                     if i == self.MAX_RETRY_LIMIT:
@@ -2022,8 +2046,8 @@ class OsmApi:
     def _get(self, path):
         return self._http('GET', path, False, None)
 
-    def _put(self, path, data):
-        return self._http('PUT', path, True, data)
+    def _put(self, path, data, return_value=True):
+        return self._http('PUT', path, True, data, return_value=return_value)
 
     def _post(self, path, data, optionalAuth=False):
         auth = True
diff --git a/osmapi/__init__.py b/osmapi/__init__.py
index 4711e90..9f8ccda 100644
--- a/osmapi/__init__.py
+++ b/osmapi/__init__.py
@@ -1,5 +1,5 @@
 from __future__ import (absolute_import, print_function, unicode_literals)
 
-__version__ = '1.0.1'
+__version__ = '1.0.2'
 
 from .OsmApi import *  # noqa
diff --git a/test-requirements.txt b/test-requirements.txt
index 3b52c77..6be8847 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -9,4 +9,3 @@ coveralls==0.4.1
 mock==1.0.1
 xmltodict==0.9.0
 virtualenv==15.1.0
-httpretty==0.8.14
diff --git a/tests/changeset_tests.py b/tests/changeset_tests.py
index 82df4d8..7176d38 100644
--- a/tests/changeset_tests.py
+++ b/tests/changeset_tests.py
@@ -92,10 +92,10 @@ class TestOsmApiChangeset(osmapi_tests.TestOsmApi):
             xmltosorteddict(kwargs['data']),
             xmltosorteddict(
                 b'<?xml version="1.0" encoding="UTF-8"?>\n'
-                b'<osm version="0.6" generator="osmapi/1.0.1">\n'
+                b'<osm version="0.6" generator="osmapi/1.0.2">\n'
                 b'  <changeset visible="true">\n'
                 b'    <tag k="test" v="foobar"/>\n'
-                b'    <tag k="created_by" v="osmapi/1.0.1"/>\n'
+                b'    <tag k="created_by" v="osmapi/1.0.2"/>\n'
                 b'  </changeset>\n'
                 b'</osm>\n'
             )
@@ -125,7 +125,7 @@ class TestOsmApiChangeset(osmapi_tests.TestOsmApi):
             xmltosorteddict(kwargs['data']),
             xmltosorteddict(
                 b'<?xml version="1.0" encoding="UTF-8"?>\n'
-                b'<osm version="0.6" generator="osmapi/1.0.1">\n'
+                b'<osm version="0.6" generator="osmapi/1.0.2">\n'
                 b'  <changeset visible="true">\n'
                 b'    <tag k="test" v="foobar"/>\n'
                 b'    <tag k="created_by" v="MyTestOSMApp"/>\n'
@@ -163,10 +163,10 @@ class TestOsmApiChangeset(osmapi_tests.TestOsmApi):
             xmltosorteddict(kwargs['data']),
             xmltosorteddict(
                 b'<?xml version="1.0" encoding="UTF-8"?>\n'
-                b'<osm version="0.6" generator="osmapi/1.0.1">\n'
+                b'<osm version="0.6" generator="osmapi/1.0.2">\n'
                 b'  <changeset visible="true">\n'
                 b'    <tag k="foobar" v="A new test changeset"/>\n'
-                b'    <tag k="created_by" v="osmapi/1.0.1"/>\n'
+                b'    <tag k="created_by" v="osmapi/1.0.2"/>\n'
                 b'  </changeset>\n'
                 b'</osm>\n'
             )
@@ -190,7 +190,7 @@ class TestOsmApiChangeset(osmapi_tests.TestOsmApi):
             xmltosorteddict(kwargs['data']),
             xmltosorteddict(
                 b'<?xml version="1.0" encoding="UTF-8"?>\n'
-                b'<osm version="0.6" generator="osmapi/1.0.1">\n'
+                b'<osm version="0.6" generator="osmapi/1.0.2">\n'
                 b'  <changeset visible="true">\n'
                 b'    <tag k="foobar" v="A new test changeset"/>\n'
                 b'    <tag k="created_by" v="CoolTestApp"/>\n'
@@ -276,7 +276,7 @@ class TestOsmApiChangeset(osmapi_tests.TestOsmApi):
             xmltosorteddict(kwargs['data']),
             xmltosorteddict(
                 b'<?xml version="1.0" encoding="UTF-8"?>\n'
-                b'<osmChange version="0.6" generator="osmapi/1.0.1">\n'
+                b'<osmChange version="0.6" generator="osmapi/1.0.2">\n'
                 b'<create>\n'
                 b'  <node lat="47.123" lon="8.555" visible="true" '
                 b'changeset="4444">\n'
@@ -350,7 +350,7 @@ class TestOsmApiChangeset(osmapi_tests.TestOsmApi):
             xmltosorteddict(kwargs['data']),
             xmltosorteddict(
                 b'<?xml version="1.0" encoding="UTF-8"?>\n'
-                b'<osmChange version="0.6" generator="osmapi/1.0.1">\n'
+                b'<osmChange version="0.6" generator="osmapi/1.0.2">\n'
                 b'<modify>\n'
                 b'  <way id="4294967296" version="2" visible="true" '
                 b'changeset="4444">\n'
@@ -434,7 +434,7 @@ class TestOsmApiChangeset(osmapi_tests.TestOsmApi):
             xmltosorteddict(kwargs['data']),
             xmltosorteddict(
                 b'<?xml version="1.0" encoding="UTF-8"?>\n'
-                b'<osmChange version="0.6" generator="osmapi/1.0.1">\n'
+                b'<osmChange version="0.6" generator="osmapi/1.0.2">\n'
                 b'<delete>\n'
                 b'  <relation id="676" version="2" visible="true" '
                 b'changeset="4444">\n'
diff --git a/tests/fixtures/test_WayGet_nodata.xml b/tests/fixtures/test_WayGet_nodata.xml
new file mode 100644
index 0000000..e69de29
diff --git a/tests/functional_tests.py b/tests/functional_tests.py
deleted file mode 100644
index 0133afe..0000000
--- a/tests/functional_tests.py
+++ /dev/null
@@ -1,18 +0,0 @@
-import httpretty
-import unittest
-import osmapi
-
-
-class TestOsmApiFunctional(unittest.TestCase):
-    @httpretty.activate
-    def test_deleted_element_raises_exception(self):
-        httpretty.HTTPretty.allow_net_connect = False
-        httpretty.register_uri(
-            httpretty.GET,
-            "https://www.openstreetmap.org/api/0.6/relation/2911456/full",
-            status=410
-        )
-        with self.assertRaises(osmapi.ElementDeletedApiError) as context:
-            api = osmapi.OsmApi()
-            api.RelationFull(2911456)
-        self.assertEquals(410, context.exception.status)
diff --git a/tests/relation_tests.py b/tests/relation_tests.py
index 5e9fac6..7e7aa10 100644
--- a/tests/relation_tests.py
+++ b/tests/relation_tests.py
@@ -310,3 +310,10 @@ class TestOsmApiRelation(osmapi_tests.TestOsmApi):
         self.assertEquals(result[1532552]['id'], 1532552)
         self.assertEquals(result[1532552]['visible'], True)
         self.assertEquals(result[1532552]['tag']['route'], 'bicycle')
+
+    def test_RelationFull_with_deleted_relation(self):
+        self._session_mock(filenames=[], status=410)
+
+        with self.assertRaises(osmapi.ElementDeletedApiError) as context:
+            self.api.RelationFull(2911456)
+        self.assertEquals(410, context.exception.status)
diff --git a/tests/way_tests.py b/tests/way_tests.py
index 3ea5bdc..37d96f2 100644
--- a/tests/way_tests.py
+++ b/tests/way_tests.py
@@ -62,6 +62,12 @@ class TestOsmApiWay(osmapi_tests.TestOsmApi):
         self.assertEquals(result['changeset'], 41303)
         self.assertEquals(result['user'], 'metaodi')
 
+    def test_WayGet_nodata(self):
+        self._session_mock()
+
+        with self.assertRaises(osmapi.ResponseEmptyApiError):
+            self.api.WayGet(321)
+
     def test_WayCreate(self):
         self._session_mock(auth=True)
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/python-osmapi.git



More information about the Pkg-grass-devel mailing list