Skip to content

Commit

Permalink
Merge pull request #78 from metaodi/develop
Browse files Browse the repository at this point in the history
Release 1.0.0
  • Loading branch information
metaodi committed Sep 5, 2017
2 parents edb10d6 + 0991bcd commit c34b14a
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,5 +1,6 @@
dist/
MANIFEST
*.pyc
*.egg-info
.coverage
.tox
6 changes: 2 additions & 4 deletions .travis.yml
@@ -1,19 +1,17 @@
language: python

python:
- '2.6'
- '2.7'
- '3.3'
- '3.4'
- '3.5'
- '3.6'

before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq pandoc

install:
- if [[ $TRAVIS_PYTHON_VERSION == 2.6 ]]; then
pip install unittest2;
fi
- pip install -r requirements.txt
- pip install -r test-requirements.txt
- pip install .
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## [Unreleased][unreleased]

## 1.0.0 - 2017-09-05
### Added
- Officially support Python 3.5 and 3.6

### Removed
- osmapi does **not** support Python 2.6 anymore (it might work, it might not)

### Changed
- **BC-Break:** raise an exception if the requested element is deleted (previoulsy `None` has been returned)

## 0.8.1 - 2016-12-21
### Fixed
- Use setuptools instead of distutils in setup.py
Expand Down
14 changes: 12 additions & 2 deletions README.md
Expand Up @@ -56,7 +56,7 @@ Note: The password file should have the format _user:password_

```python
import osmapi
api = osmapi.OsmApi(username = u"metaodi", password = u"*******")
api = osmapi.OsmApi(api="api06.dev.openstreetmap.org", username = u"metaodi", password = u"*******")
api.ChangesetCreate({u"comment": u"My first test"})
print api.NodeCreate({u"lon":1, u"lat":1, u"tag": {}})
# {u'changeset': 532907, u'lon': 1, u'version': 1, u'lat': 1, u'tag': {}, u'id': 164684}
Expand Down Expand Up @@ -86,10 +86,20 @@ To run the tests use the following command:

nosetests --verbose

By using tox you can even run the tests against different versions of python (2.6, 2.7, 3.2 and 3.3):
By using tox you can even run the tests against different versions of python (2.7, 3.3, 3.4, 3.5 and 3.6):

tox

## Release

To create a new release, follow these steps (please respect [Semantic Versioning](http://semver.org/)):

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 [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

## Attribution

This project was orginally developed by Etienne Chové.
Expand Down
6 changes: 2 additions & 4 deletions build.sh
Expand Up @@ -14,10 +14,8 @@ flake8 --statistics --show-source .
# run tests
nosetests --verbose --with-coverage

# generate docs (currently it's not possible to generate docs in Python 2.6)
if [[ $TRAVIS_PYTHON_VERSION != 2.6 ]]; then
pdoc --html --overwrite osmapi/OsmApi.py
fi
# generate the docs
pdoc --html --overwrite osmapi/OsmApi.py

# setup a new virtualenv and try to install the lib
virtualenv pyenv
Expand Down
24 changes: 22 additions & 2 deletions osmapi/OsmApi.py
Expand Up @@ -122,6 +122,13 @@ class NotSubscribedApiError(ApiError):
pass


class ElementDeletedApiError(ApiError):
"""
Error when the requested element is deleted
"""
pass


class OsmApi:
"""
Main class of osmapi, instanciate this class to use osmapi
Expand Down Expand Up @@ -1898,6 +1905,15 @@ def _http_request(self, method, path, auth, send): # noqa
be preformed on this request.
`send` contains additional data that might be sent in a
request.
If the username or password is missing,
`OsmApi.UsernamePasswordMissingError` is raised.
If the requested element has been deleted,
`OsmApi.ElementDeletedApiError` is raised.
If the response status code indicates an error,
`OsmApi.ApiError` is raised.
"""
if self._debug:
error_msg = (
Expand All @@ -1919,9 +1935,13 @@ def _http_request(self, method, path, auth, send): # noqa
response = self._session.request(method, path, auth=user_pass,
data=send)
if response.status_code != 200:
if response.status_code == 410:
return None
payload = response.content.strip()
if response.status_code == 410:
raise ElementDeletedApiError(
response.status_code,
response.reason,
payload
)
raise ApiError(response.status_code, response.reason, payload)
if self._debug:
error_msg = (
Expand Down
2 changes: 1 addition & 1 deletion osmapi/__init__.py
@@ -1,5 +1,5 @@
from __future__ import (absolute_import, print_function, unicode_literals)

__version__ = '0.8.1'
__version__ = '1.0.0'

from .OsmApi import * # noqa
3 changes: 2 additions & 1 deletion setup.py
Expand Up @@ -42,10 +42,11 @@
'Topic :: Software Development :: Libraries',
'Development Status :: 4 - Beta',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
],
)
3 changes: 2 additions & 1 deletion test-requirements.txt
Expand Up @@ -3,9 +3,10 @@
flake8==3.0.4; python_version >= '2.7'
flake8==2.1.0; python_version == '2.6'
nose==1.3.0
tox==1.7.1
tox==2.8.1
coverage==3.7.1
coveralls==0.4.1
mock==1.0.1
xmltodict==0.9.0
virtualenv==15.1.0
httpretty==0.8.14
18 changes: 9 additions & 9 deletions tests/changeset_tests.py
Expand Up @@ -92,10 +92,10 @@ def test_ChangesetUpdate(self):
xmltosorteddict(kwargs['data']),
xmltosorteddict(
b'<?xml version="1.0" encoding="UTF-8"?>\n'
b'<osm version="0.6" generator="osmapi/0.8.1">\n'
b'<osm version="0.6" generator="osmapi/1.0.0">\n'
b' <changeset visible="true">\n'
b' <tag k="test" v="foobar"/>\n'
b' <tag k="created_by" v="osmapi/0.8.1"/>\n'
b' <tag k="created_by" v="osmapi/1.0.0"/>\n'
b' </changeset>\n'
b'</osm>\n'
)
Expand Down Expand Up @@ -125,7 +125,7 @@ def test_ChangesetUpdate_with_created_by(self):
xmltosorteddict(kwargs['data']),
xmltosorteddict(
b'<?xml version="1.0" encoding="UTF-8"?>\n'
b'<osm version="0.6" generator="osmapi/0.8.1">\n'
b'<osm version="0.6" generator="osmapi/1.0.0">\n'
b' <changeset visible="true">\n'
b' <tag k="test" v="foobar"/>\n'
b' <tag k="created_by" v="MyTestOSMApp"/>\n'
Expand Down Expand Up @@ -163,10 +163,10 @@ def test_ChangesetCreate(self):
xmltosorteddict(kwargs['data']),
xmltosorteddict(
b'<?xml version="1.0" encoding="UTF-8"?>\n'
b'<osm version="0.6" generator="osmapi/0.8.1">\n'
b'<osm version="0.6" generator="osmapi/1.0.0">\n'
b' <changeset visible="true">\n'
b' <tag k="foobar" v="A new test changeset"/>\n'
b' <tag k="created_by" v="osmapi/0.8.1"/>\n'
b' <tag k="created_by" v="osmapi/1.0.0"/>\n'
b' </changeset>\n'
b'</osm>\n'
)
Expand All @@ -190,7 +190,7 @@ def test_ChangesetCreate_with_created_by(self):
xmltosorteddict(kwargs['data']),
xmltosorteddict(
b'<?xml version="1.0" encoding="UTF-8"?>\n'
b'<osm version="0.6" generator="osmapi/0.8.1">\n'
b'<osm version="0.6" generator="osmapi/1.0.0">\n'
b' <changeset visible="true">\n'
b' <tag k="foobar" v="A new test changeset"/>\n'
b' <tag k="created_by" v="CoolTestApp"/>\n'
Expand Down Expand Up @@ -276,7 +276,7 @@ def test_ChangesetUpload_create_node(self):
xmltosorteddict(kwargs['data']),
xmltosorteddict(
b'<?xml version="1.0" encoding="UTF-8"?>\n'
b'<osmChange version="0.6" generator="osmapi/0.8.1">\n'
b'<osmChange version="0.6" generator="osmapi/1.0.0">\n'
b'<create>\n'
b' <node lat="47.123" lon="8.555" visible="true" '
b'changeset="4444">\n'
Expand Down Expand Up @@ -350,7 +350,7 @@ def test_ChangesetUpload_modify_way(self):
xmltosorteddict(kwargs['data']),
xmltosorteddict(
b'<?xml version="1.0" encoding="UTF-8"?>\n'
b'<osmChange version="0.6" generator="osmapi/0.8.1">\n'
b'<osmChange version="0.6" generator="osmapi/1.0.0">\n'
b'<modify>\n'
b' <way id="4294967296" version="2" visible="true" '
b'changeset="4444">\n'
Expand Down Expand Up @@ -434,7 +434,7 @@ def test_ChangesetUpload_delete_relation(self):
xmltosorteddict(kwargs['data']),
xmltosorteddict(
b'<?xml version="1.0" encoding="UTF-8"?>\n'
b'<osmChange version="0.6" generator="osmapi/0.8.1">\n'
b'<osmChange version="0.6" generator="osmapi/1.0.0">\n'
b'<delete>\n'
b' <relation id="676" version="2" visible="true" '
b'changeset="4444">\n'
Expand Down
17 changes: 17 additions & 0 deletions tests/functional_tests.py
@@ -0,0 +1,17 @@
import httpretty
import unittest
import osmapi


class TestOsmApiFunctional(unittest.TestCase):
@httpretty.activate
def test_deleted_element_raises_exception(self):
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)
23 changes: 10 additions & 13 deletions tests/helper_tests.py
Expand Up @@ -101,19 +101,16 @@ def test_http_request_auth(self):

def test_http_request_410_response(self):
self.setupMock(410)
response = self.api._http_request(
'GET',
'/api/0.6/test410',
False,
None
)
self.api._session.request.assert_called_with(
'GET',
self.api_base + '/api/0.6/test410',
auth=None,
data=None
)
self.assertIsNone(response, "test response")
with self.assertRaises(osmapi.ElementDeletedApiError) as cm:
self.api._http_request(
'GET',
'/api/0.6/test410',
False,
None
)
self.assertEquals(cm.exception.status, 410)
self.assertEquals(cm.exception.reason, "test reason")
self.assertEquals(cm.exception.payload, "test response")

def test_http_request_500_response(self):
self.setupMock(500)
Expand Down
6 changes: 1 addition & 5 deletions tox.ini
@@ -1,11 +1,7 @@
[tox]
envlist = py26,py27,py32,py33,py34
envlist = py27,py33,py34,py35,py36
[testenv]
commands=nosetests --verbose
deps =
-r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
[testenv:py26]
deps =
unittest2
{[testenv]deps}

0 comments on commit c34b14a

Please sign in to comment.