Skip to content

Commit

Permalink
Merge pull request #29 from metaodi/develop
Browse files Browse the repository at this point in the history
Release 0.4.1
  • Loading branch information
metaodi committed Oct 8, 2014
2 parents 2307782 + d6847bb commit 8c5b7c8
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 36 deletions.
17 changes: 14 additions & 3 deletions osmapi/OsmApi.py
Expand Up @@ -10,6 +10,7 @@
import time
import sys
import urllib
from datetime import datetime

# Python 3.x
if getattr(urllib, 'urlencode', None) is None:
Expand Down Expand Up @@ -1043,7 +1044,7 @@ def _DomGetComments(self, DomElement):
result = []
for t in DomElement.getElementsByTagName("comment"):
comment = {}
comment['date'] = self._GetXmlValue(t, "date")
comment['date'] = self._ParseDate(self._GetXmlValue(t, "date"))
comment['action'] = self._GetXmlValue(t, "action")
comment['text'] = self._GetXmlValue(t, "text")
comment['html'] = self._GetXmlValue(t, "html")
Expand Down Expand Up @@ -1103,12 +1104,22 @@ def _DomParseNote(self, DomElement):
result["id"] = self._GetXmlValue(DomElement, "id")
result["status"] = self._GetXmlValue(DomElement, "status")

result["date_created"] = self._GetXmlValue(DomElement, "date_created")
result["date_closed"] = self._GetXmlValue(DomElement, "date_closed")
result["date_created"] = self._ParseDate(
self._GetXmlValue(DomElement, "date_created")
)
result["date_closed"] = self._ParseDate(
self._GetXmlValue(DomElement, "date_closed")
)
result["comments"] = self._DomGetComments(DomElement)

return result

def _ParseDate(self, DateString):
try:
return datetime.strptime(DateString, "%Y-%m-%d %H:%M:%S UTC")
except:
return None

##################################################
# Internal xml builder #
##################################################
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.4.0'
__version__ = '0.4.1'

from .OsmApi import * # noqa
18 changes: 9 additions & 9 deletions tests/changeset_tests.py
Expand Up @@ -98,10 +98,10 @@ def test_ChangesetUpdate(self):
xmltosorteddict(args[3]),
xmltosorteddict(
b'<?xml version="1.0" encoding="UTF-8"?>\n'
b'<osm version="0.6" generator="osmapi/0.4.0">\n'
b'<osm version="0.6" generator="osmapi/0.4.1">\n'
b' <changeset visible="true">\n'
b' <tag k="test" v="foobar"/>\n'
b' <tag k="created_by" v="osmapi/0.4.0"/>\n'
b' <tag k="created_by" v="osmapi/0.4.1"/>\n'
b' </changeset>\n'
b'</osm>\n'
)
Expand Down Expand Up @@ -132,7 +132,7 @@ def test_ChangesetUpdate_with_created_by(self):
xmltosorteddict(args[3]),
xmltosorteddict(
b'<?xml version="1.0" encoding="UTF-8"?>\n'
b'<osm version="0.6" generator="osmapi/0.4.0">\n'
b'<osm version="0.6" generator="osmapi/0.4.1">\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 @@ -171,10 +171,10 @@ def test_ChangesetCreate(self):
xmltosorteddict(args[3]),
xmltosorteddict(
b'<?xml version="1.0" encoding="UTF-8"?>\n'
b'<osm version="0.6" generator="osmapi/0.4.0">\n'
b'<osm version="0.6" generator="osmapi/0.4.1">\n'
b' <changeset visible="true">\n'
b' <tag k="foobar" v="A new test changeset"/>\n'
b' <tag k="created_by" v="osmapi/0.4.0"/>\n'
b' <tag k="created_by" v="osmapi/0.4.1"/>\n'
b' </changeset>\n'
b'</osm>\n'
)
Expand All @@ -199,7 +199,7 @@ def test_ChangesetCreate_with_created_by(self):
xmltosorteddict(args[3]),
xmltosorteddict(
b'<?xml version="1.0" encoding="UTF-8"?>\n'
b'<osm version="0.6" generator="osmapi/0.4.0">\n'
b'<osm version="0.6" generator="osmapi/0.4.1">\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 @@ -285,7 +285,7 @@ def test_ChangesetUpload_create_node(self):
xmltosorteddict(args[3]),
xmltosorteddict(
b'<?xml version="1.0" encoding="UTF-8"?>\n'
b'<osmChange version="0.6" generator="osmapi/0.4.0">\n'
b'<osmChange version="0.6" generator="osmapi/0.4.1">\n'
b'<create>\n'
b' <node lat="47.123" lon="8.555" visible="true" '
b'changeset="4444">\n'
Expand Down Expand Up @@ -359,7 +359,7 @@ def test_ChangesetUpload_modify_way(self):
xmltosorteddict(args[3]),
xmltosorteddict(
b'<?xml version="1.0" encoding="UTF-8"?>\n'
b'<osmChange version="0.6" generator="osmapi/0.4.0">\n'
b'<osmChange version="0.6" generator="osmapi/0.4.1">\n'
b'<modify>\n'
b' <way id="4294967296" version="2" visible="true" '
b'changeset="4444">\n'
Expand Down Expand Up @@ -443,7 +443,7 @@ def test_ChangesetUpload_delete_relation(self):
xmltosorteddict(args[3]),
xmltosorteddict(
b'<?xml version="1.0" encoding="UTF-8"?>\n'
b'<osmChange version="0.6" generator="osmapi/0.4.0">\n'
b'<osmChange version="0.6" generator="osmapi/0.4.1">\n'
b'<delete>\n'
b' <relation id="676" version="2" visible="true" '
b'changeset="4444">\n'
Expand Down
47 changes: 24 additions & 23 deletions tests/notes_tests.py
@@ -1,6 +1,7 @@
from __future__ import (unicode_literals, absolute_import)
from nose.tools import * # noqa
from . import osmapi_tests
from datetime import datetime

try:
import urlparse
Expand Down Expand Up @@ -36,20 +37,20 @@ def test_NotesGet(self):
'id': '231775',
'lon': -1.4929605,
'lat': 52.4107312,
'date_created': '2014-08-28 19:25:37 UTC',
'date_closed': '2014-09-27 09:21:41 UTC',
'date_created': datetime(2014, 8, 28, 19, 25, 37),
'date_closed': datetime(2014, 9, 27, 9, 21, 41),
'status': 'closed',
'comments': [
{
'date': '2014-08-28 19:25:37 UTC',
'date': datetime(2014, 8, 28, 19, 25, 37),
'action': 'opened',
'text': "Is it Paynes or Payne's",
'html': "<p>Is it Paynes or Payne's</p>",
'uid': '1486336',
'user': 'Wyken Seagrave'
},
{
'date': '2014-09-26 13:05:33 UTC',
'date': datetime(2014, 9, 26, 13, 5, 33),
'action': 'commented',
'text': "Royal Mail's postcode finder has PAYNES LANE",
'html':
Expand All @@ -76,20 +77,20 @@ def test_NoteGet(self):
'id': '1111',
'lon': 12.3133135,
'lat': 37.9305489,
'date_created': '2013-05-01 20:58:21 UTC',
'date_closed': '2013-08-21 16:43:26 UTC',
'date_created': datetime(2013, 5, 1, 20, 58, 21),
'date_closed': datetime(2013, 8, 21, 16, 43, 26),
'status': 'closed',
'comments': [
{
'date': '2013-05-01 20:58:21 UTC',
'date': datetime(2013, 5, 1, 20, 58, 21),
'action': 'opened',
'text': "It does not exist this path",
'html': "<p>It does not exist this path</p>",
'uid': '1363438',
'user': 'giuseppemari'
},
{
'date': '2013-08-21 16:43:26 UTC',
'date': datetime(2013, 8, 21, 16, 43, 26),
'action': 'closed',
'text': "there is no path signed",
'html': "<p>there is no path signed</p>",
Expand Down Expand Up @@ -122,12 +123,12 @@ def test_NoteCreate(self):
'id': '816',
'lat': 47.123,
'lon': 8.432,
'date_created': '2014-10-03 15:21:21 UTC',
'date_created': datetime(2014, 10, 3, 15, 21, 21),
'date_closed': None,
'status': 'open',
'comments': [
{
'date': '2014-10-03 15:21:22 UTC',
'date': datetime(2014, 10, 3, 15, 21, 22),
'action': 'opened',
'text': "This is a test",
'html': "<p>This is a test</p>",
Expand All @@ -153,20 +154,20 @@ def test_NoteComment(self):
'id': '812',
'lat': 47.123,
'lon': 8.432,
'date_created': '2014-10-03 15:11:05 UTC',
'date_created': datetime(2014, 10, 3, 15, 11, 5),
'date_closed': None,
'status': 'open',
'comments': [
{
'date': '2014-10-03 15:11:05 UTC',
'date': datetime(2014, 10, 3, 15, 11, 5),
'action': 'opened',
'text': "This is a test",
'html': "<p>This is a test</p>",
'uid': '1841',
'user': 'metaodi'
},
{
'date': '2014-10-04 22:36:35 UTC',
'date': datetime(2014, 10, 4, 22, 36, 35),
'action': 'commented',
'text': "This is a comment",
'html': "<p>This is a comment</p>",
Expand All @@ -192,20 +193,20 @@ def test_NoteClose(self):
'id': '815',
'lat': 47.123,
'lon': 8.432,
'date_created': '2014-10-03 15:20:57 UTC',
'date_closed': '2014-10-05 16:35:13 UTC',
'date_created': datetime(2014, 10, 3, 15, 20, 57),
'date_closed': datetime(2014, 10, 5, 16, 35, 13),
'status': 'closed',
'comments': [
{
'date': '2014-10-03 15:20:57 UTC',
'date': datetime(2014, 10, 3, 15, 20, 57),
'action': 'opened',
'text': "This is a test",
'html': "<p>This is a test</p>",
'uid': '1841',
'user': 'metaodi'
},
{
'date': '2014-10-05 16:35:13 UTC',
'date': datetime(2014, 10, 5, 16, 35, 13),
'action': 'closed',
'text': "Close this note!",
'html': "<p>Close this note!</p>",
Expand All @@ -231,28 +232,28 @@ def test_NoteReopen(self):
'id': '815',
'lat': 47.123,
'lon': 8.432,
'date_created': '2014-10-03 15:20:57 UTC',
'date_created': datetime(2014, 10, 3, 15, 20, 57),
'date_closed': None,
'status': 'open',
'comments': [
{
'date': '2014-10-03 15:20:57 UTC',
'date': datetime(2014, 10, 3, 15, 20, 57),
'action': 'opened',
'text': "This is a test",
'html': "<p>This is a test</p>",
'uid': '1841',
'user': 'metaodi'
},
{
'date': '2014-10-05 16:35:13 UTC',
'date': datetime(2014, 10, 5, 16, 35, 13),
'action': 'closed',
'text': "Close this note!",
'html': "<p>Close this note!</p>",
'uid': '1841',
'user': 'metaodi'
},
{
'date': '2014-10-05 16:44:56 UTC',
'date': datetime(2014, 10, 5, 16, 44, 56),
'action': 'reopened',
'text': "Reopen this note!",
'html': "<p>Reopen this note!</p>",
Expand Down Expand Up @@ -281,12 +282,12 @@ def test_NotesSearch(self):
'id': '788',
'lon': 11.96395,
'lat': 57.70301,
'date_created': '2014-07-16 16:12:41 UTC',
'date_created': datetime(2014, 7, 16, 16, 12, 41),
'date_closed': None,
'status': 'open',
'comments': [
{
'date': '2014-07-16 16:12:41 UTC',
'date': datetime(2014, 7, 16, 16, 12, 41),
'action': 'opened',
'text': "One way street:\ncomment",
'html': "<p>One way street:\n<br />comment</p>",
Expand Down

0 comments on commit 8c5b7c8

Please sign in to comment.