Skip to content

Commit

Permalink
Add test for ChangesetClosedApiError
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Oderbolz committed Nov 21, 2021
1 parent 95ec6d9 commit e667feb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions tests/fixtures/test_NodeUpdateWhenChangesetIsClosed.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The changeset 2222 was closed at 2021-11-20 09:42:47 UTC.
31 changes: 31 additions & 0 deletions tests/node_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,37 @@ def test_NodeUpdate(self):
self.assertEquals(result['lon'], test_node['lon'])
self.assertEquals(result['tag'], test_node['tag'])

def test_NodeUpdateWhenChangesetIsClosed(self):
self._session_mock(auth=True, status=409)

self.api.ChangesetCreate = mock.Mock(
return_value=1111
)
self.api._CurrentChangesetId = 1111

test_node = {
'id': 7676,
'lat': 47.287,
'lon': 8.765,
'tag': {
'amenity': 'place_of_worship',
'name': 'christian'
}
}

cs = self.api.ChangesetCreate({
'comment': 'This is a test dataset'
})

with self.assertRaises(osmapi.ChangesetClosedApiError) as cm:
result = self.api.NodeUpdate(test_node)

self.assertEquals(cm.exception.status, 409)
self.assertEquals(
cm.exception.payload,
"The changeset 2222 was closed at 2021-11-20 09:42:47 UTC."
)

def test_NodeDelete(self):
self._session_mock(auth=True)

Expand Down
3 changes: 1 addition & 2 deletions tests/osmapi_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ def setUp(self):
print(self._testMethodName)
print(self.api)

def _session_mock(self, auth=False, filenames=None, status=200,
reason=None):
def _session_mock(self, auth=False, filenames=None, status=200):
if auth:
self.api._username = 'testuser'
self.api._password = 'testpassword'
Expand Down

0 comments on commit e667feb

Please sign in to comment.