Skip to content

Commit

Permalink
Add tests for new error classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Oderbolz committed May 24, 2015
1 parent 2a3f13a commit ef98f5a
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 10 deletions.
12 changes: 6 additions & 6 deletions tests/changeset_tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import (unicode_literals, absolute_import)
from nose.tools import * # noqa
from . import osmapi_tests
from osmapi import AlreadySubscribedApiError, NotSubscribedApiError
import osmapi
import mock
import xmltodict
import datetime
Expand Down Expand Up @@ -148,7 +148,7 @@ def test_ChangesetUpdate_wo_changeset(self):
self._conn_mock()

with self.assertRaisesRegexp(
Exception,
osmapi.NoChangesetOpenError,
'No changeset currently opened'):
self.api.ChangesetUpdate(
{
Expand Down Expand Up @@ -221,7 +221,7 @@ def test_ChangesetCreate_with_open_changeset(self):
)

with self.assertRaisesRegexp(
Exception,
osmapi.ChangesetAlreadyOpenError,
'Changeset already opened'):
self.api.ChangesetCreate(
{
Expand All @@ -248,7 +248,7 @@ def test_ChangesetClose_with_no_changeset(self):
self._conn_mock()

with self.assertRaisesRegexp(
Exception,
osmapi.NoChangesetOpenError,
'No changeset currently opened'):
self.api.ChangesetClose()

Expand Down Expand Up @@ -652,7 +652,7 @@ def test_ChangesetSubscribe(self):
def test_ChangesetSubscribeWhenAlreadySubscribed(self):
self._conn_mock(auth=True, status=409)

with self.assertRaises(AlreadySubscribedApiError) as cm:
with self.assertRaises(osmapi.AlreadySubscribedApiError) as cm:
self.api.ChangesetSubscribe(52924)

self.assertEquals(cm.exception.status, 409)
Expand Down Expand Up @@ -690,7 +690,7 @@ def test_ChangesetUnsubscribe(self):
def test_ChangesetUnsubscribeWhenNotSubscribed(self):
self._conn_mock(auth=True, status=404)

with self.assertRaises(NotSubscribedApiError) as cm:
with self.assertRaises(osmapi.NotSubscribedApiError) as cm:
self.api.ChangesetUnsubscribe(52924)

self.assertEquals(cm.exception.status, 404)
Expand Down
30 changes: 26 additions & 4 deletions tests/node_tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import (unicode_literals, absolute_import)
from nose.tools import * # noqa
from . import osmapi_tests
from osmapi import OsmApi, UsernamePasswordMissingError
import osmapi
import mock
import datetime

Expand Down Expand Up @@ -59,7 +59,7 @@ def test_NodeGet_with_version(self):

def test_NodeCreate_changesetauto(self):
# setup mock
self.api = OsmApi(
self.api = osmapi.OsmApi(
api="api06.dev.openstreetmap.org",
changesetauto=True
)
Expand Down Expand Up @@ -124,10 +124,32 @@ def test_NodeCreate_wo_changeset(self):
}

with self.assertRaisesRegexp(
Exception,
osmapi.NoChangesetOpenError,
'need to open a changeset'):
self.api.NodeCreate(test_node)

def test_NodeCreate_existing_node(self):
# setup mock
self.api.ChangesetCreate = mock.Mock(
return_value=1111
)
self.api._CurrentChangesetId = 1111

test_node = {
'id': 123,
'lat': 47.287,
'lon': 8.765,
'tag': {
'amenity': 'place_of_worship',
'religion': 'pastafarian'
}
}

with self.assertRaisesRegexp(
osmapi.OsmTypeAlreadyExistsError,
'This node already exists'):
self.api.NodeCreate(test_node)

def test_NodeCreate_wo_auth(self):
self._conn_mock()

Expand All @@ -146,7 +168,7 @@ def test_NodeCreate_wo_auth(self):
}

with self.assertRaisesRegexp(
UsernamePasswordMissingError,
osmapi.UsernamePasswordMissingError,
'Username/Password missing'):
self.api.NodeCreate(test_node)

Expand Down
32 changes: 32 additions & 0 deletions tests/relation_tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import (unicode_literals, absolute_import)
from nose.tools import * # noqa
from . import osmapi_tests
import osmapi
import mock
import datetime

Expand Down Expand Up @@ -140,6 +141,37 @@ def test_RelationCreate(self):
self.assertEquals(result['member'], test_relation['member'])
self.assertEquals(result['tag'], test_relation['tag'])

def test_RelationCreate_existing_node(self):
# setup mock
self.api.ChangesetCreate = mock.Mock(
return_value=1111
)
self.api._CurrentChangesetId = 1111

test_relation = {
'id': 456,
'tag': {
'type': 'test',
},
'member': [
{
'ref': 6908,
'role': 'outer',
'type': 'way'
},
{
'ref': 6352,
'role': 'point',
'type': 'node'
},
]
}

with self.assertRaisesRegexp(
osmapi.OsmTypeAlreadyExistsError,
'This relation already exists'):
self.api.RelationCreate(test_relation)

def test_RelationUpdate(self):
self._conn_mock(auth=True)

Expand Down
22 changes: 22 additions & 0 deletions tests/way_tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import (unicode_literals, absolute_import)
from nose.tools import * # noqa
from . import osmapi_tests
import osmapi
import mock
import datetime

Expand Down Expand Up @@ -104,6 +105,27 @@ def test_WayCreate(self):
self.assertEquals(result['nd'], test_way['nd'])
self.assertEquals(result['tag'], test_way['tag'])

def test_WayCreate_existing_node(self):
# setup mock
self.api.ChangesetCreate = mock.Mock(
return_value=1111
)
self.api._CurrentChangesetId = 1111

test_way = {
'id': 456,
'nd': [11949, 11950],
'tag': {
'highway': 'unclassified',
'name': 'Osmapi Street'
}
}

with self.assertRaisesRegexp(
osmapi.OsmTypeAlreadyExistsError,
'This way already exists'):
self.api.WayCreate(test_way)

def test_WayUpdate(self):
self._conn_mock(auth=True)

Expand Down

0 comments on commit ef98f5a

Please sign in to comment.