Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue236 update #249

Merged
merged 3 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions dmci/distributors/pycsw_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,13 @@ 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'<?xml version="1.0" encoding="UTF-8"?>'
b'<csw:Transaction xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" '
b'xmlns:ows="http://www.opengis.net/ows" '
b'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
b'xsi:schemaLocation="http://www.opengis.net/cat/csw/2.0.2 '
b'http://schemas.opengis.net/csw/2.0.2/CSW-publication.xsd" '
b'service="CSW" version="2.0.2"><csw:Update>'
)
xml += self._translate()
xml += b"</csw:Update></csw:Transaction>"
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.replace("delete", "update")
ins_status, ins_response_text = self._insert()
response_text = ins_response_text.replace("insert", "update")
# Handle insertion
return ins_status, response_text

def _delete(self):
"""Delete entry with a specified metadata_id."""
Expand Down
21 changes: 20 additions & 1 deletion tests/test_dist/test_pycsw_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
import os
import pytest
import requests
from tools import causeException

from lxml import etree
from unittest import mock
from tools import causeException

from dmci.api.worker import Worker
from dmci.distributors.pycsw_dist import PyCSWDist
Expand Down Expand Up @@ -106,6 +107,7 @@ def testDistPyCSW_Update(monkeypatch, mockXml, mockXslt, tmpUUID, tmpConf):

tstWorker = Worker("update", None, None)
tstWorker._file_metadata_id = tmpUUID
tstWorker._namespace = "no.test"
tstWorker._conf = tmpConf

# Update returns True
Expand Down Expand Up @@ -136,15 +138,32 @@ def testDistPyCSW_Update(monkeypatch, mockXml, mockXslt, tmpUUID, tmpConf):

# Update returns False if the http post request fails
with monkeypatch.context() as mp:
# Delete within update fails
mp.setattr(
"dmci.distributors.pycsw_dist.requests.post", causeException)
tstPyCSW = PyCSWDist("update", xml_file=mockXml)
tstPyCSW._worker = tstWorker
tstPyCSW._conf = tmpConf
assert tstPyCSW.run() == (
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)
tstPyCSW = PyCSWDist("update", xml_file=mockXml)
tstPyCSW._worker = tstWorker
tstPyCSW._conf = tmpConf
assert tstPyCSW.run() == (
False,
"http://localhost: service unavailable. Failed to update."
)

# END Test testDistPyCSW_Update


Expand Down
Loading