From 1d7ff51f2d5a09e3698bf369fed4a48589833ca4 Mon Sep 17 00:00:00 2001 From: "Morten W. Hansen" Date: Mon, 11 Nov 2024 18:29:26 +0100 Subject: [PATCH 1/2] Use delete and insert in update method --- dmci/distributors/pycsw_dist.py | 21 ++++++--------------- tests/test_dist/test_pycsw_dist.py | 6 ++++-- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/dmci/distributors/pycsw_dist.py b/dmci/distributors/pycsw_dist.py index ff7f671..7974524 100644 --- a/dmci/distributors/pycsw_dist.py +++ b/dmci/distributors/pycsw_dist.py @@ -103,21 +103,12 @@ def _update(self): properties against a csw:Constraint, to update: Define overwriting property, search for places to overwrite. """ - headers = requests.structures.CaseInsensitiveDict() - headers["Content-Type"] = "application/xml" - headers["Accept"] = "application/xml" - xml = ( - b'' - b'' - ) - xml += self._translate() - xml += b"" - return self._post_request(headers, xml, "update", self.TOTAL_UPDATED) + del_status, del_response_text = self._delete() + if not del_status: + return del_status, del_response_text + ins_status, ins_response_text = self._insert() + # Handle insertion + return ins_status, ins_response_text def _delete(self): """Delete entry with a specified metadata_id.""" diff --git a/tests/test_dist/test_pycsw_dist.py b/tests/test_dist/test_pycsw_dist.py index 24f56ca..da42d99 100644 --- a/tests/test_dist/test_pycsw_dist.py +++ b/tests/test_dist/test_pycsw_dist.py @@ -105,6 +105,7 @@ def testDistPyCSW_Update(monkeypatch, mockXml, mockXslt, tmpUUID): tstWorker = Worker("update", None, None) tstWorker._file_metadata_id = tmpUUID + tstWorker._namespace = "no.test" # Update returns True with monkeypatch.context() as mp: @@ -117,8 +118,8 @@ def testDistPyCSW_Update(monkeypatch, mockXml, mockXslt, tmpUUID): tstPyCSW._worker = tstWorker tstPyCSW._conf.mmd_xsl_path = mockXslt assert tstPyCSW.run() == (True, "Mock response") - tstPyCSW._worker._namespace = "test.no" - assert tstPyCSW.run() == (True, "Mock response") + #tstPyCSW._worker._namespace = "test.no" + #assert tstPyCSW.run() == (True, "Mock response") # Update returns False with monkeypatch.context() as mp: @@ -137,6 +138,7 @@ def testDistPyCSW_Update(monkeypatch, mockXml, mockXslt, tmpUUID): mp.setattr( "dmci.distributors.pycsw_dist.requests.post", causeException) tstPyCSW = PyCSWDist("update", xml_file=mockXml) + tstPyCSW._worker = tstWorker assert tstPyCSW.run() == ( False, "http://localhost: service unavailable. Failed to update." From b5e6955878d451e79d4d64d0d3ed31297e254282 Mon Sep 17 00:00:00 2001 From: "Morten W. Hansen" Date: Tue, 12 Nov 2024 21:26:12 +0100 Subject: [PATCH 2/2] #236: fix flake errors --- tests/test_dist/test_pycsw_dist.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_dist/test_pycsw_dist.py b/tests/test_dist/test_pycsw_dist.py index ac123bd..bc2ee44 100644 --- a/tests/test_dist/test_pycsw_dist.py +++ b/tests/test_dist/test_pycsw_dist.py @@ -121,8 +121,8 @@ def testDistPyCSW_Update(monkeypatch, mockXml, mockXslt, tmpUUID, tmpConf): tstPyCSW._worker = tstWorker tstPyCSW._conf.mmd_xsl_path = mockXslt assert tstPyCSW.run() == (True, "Mock response") - #tstPyCSW._worker._namespace = "test.no" - #assert tstPyCSW.run() == (True, "Mock response") + tstPyCSW._worker._namespace = "test.no" + assert tstPyCSW.run() == (True, "Mock response") # Update returns False with monkeypatch.context() as mp: @@ -148,9 +148,11 @@ def testDistPyCSW_Update(monkeypatch, mockXml, mockXslt, tmpUUID, tmpConf): False, "http://localhost: service unavailable. Failed to update." ) + # Insert within update fails def new_delete(cls, *a, **k): return True, "" + with mock.patch.object(PyCSWDist, '_delete', new=new_delete): mp.setattr( "dmci.distributors.pycsw_dist.requests.post", causeException)