From e667febe9835898c0acbf152b248ba0cae8872de Mon Sep 17 00:00:00 2001 From: Stefan Oderbolz Date: Sun, 21 Nov 2021 13:14:41 +0100 Subject: [PATCH] Add test for ChangesetClosedApiError --- .../test_NodeUpdateWhenChangesetIsClosed.xml | 1 + tests/node_tests.py | 31 +++++++++++++++++++ tests/osmapi_tests.py | 3 +- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 tests/fixtures/test_NodeUpdateWhenChangesetIsClosed.xml diff --git a/tests/fixtures/test_NodeUpdateWhenChangesetIsClosed.xml b/tests/fixtures/test_NodeUpdateWhenChangesetIsClosed.xml new file mode 100644 index 0000000..a68d0f4 --- /dev/null +++ b/tests/fixtures/test_NodeUpdateWhenChangesetIsClosed.xml @@ -0,0 +1 @@ +The changeset 2222 was closed at 2021-11-20 09:42:47 UTC. diff --git a/tests/node_tests.py b/tests/node_tests.py index cbb7f8c..6d324f8 100644 --- a/tests/node_tests.py +++ b/tests/node_tests.py @@ -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) diff --git a/tests/osmapi_tests.py b/tests/osmapi_tests.py index 9630cef..58b2589 100644 --- a/tests/osmapi_tests.py +++ b/tests/osmapi_tests.py @@ -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'