Skip to content

Commit

Permalink
closes #72: put fails
Browse files Browse the repository at this point in the history
  • Loading branch information
runderwood committed Mar 16, 2017
1 parent 4c9ff0e commit cfa3c32
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
15 changes: 15 additions & 0 deletions premis_event_service/presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@
"linkingAgentIdentifier", "linkingAgentIdentifierValue"
]

xpath_map = collections.OrderedDict()
xpath_map['@namespaces'] = PREMIS_NSMAP
xpath_map["event_identifier_type"] = 'premis:eventIdentifier/eventIdentifierType'
xpath_map["event_identifier"] = 'premis:eventIdentifier/premis:eventIdentifierValue'
xpath_map["event_type"] = 'premis:eventType'
xpath_map["event_date_time"] = 'premis:eventDateTime'
xpath_map["event_detail"] = 'premis:eventDetail'
xpath_map["event_outcome"] = 'premis:eventOutcomeInformation/premis:eventOutcome'
xpath_map["event_outcome_detail"] = 'premis:eventOutcomeInformation' + \
'/premis:eventOutcomeDetail/premis:eventOutcomeDetailNote'
xpath_map["linking_agent_identifier_type"] = 'premis:linkingAgentIdentifier' + \
'/premis:linkingAgentIdentifierType'
xpath_map["linking_agent_identifier_value"] = 'premis:linkingAgentIdentifier' + \
'/premis:linkingAgentIdentifierValue'


class DuplicateEventError(Exception):
pass
Expand Down
26 changes: 13 additions & 13 deletions premis_event_service/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@
from codalib.xsdatetime import xsDateTime_parse
from .forms import EventSearchForm
from .models import Event, Agent, AGENT_TYPE_CHOICES
from .presentation import (premisEventXMLToObject, premisEventXMLgetObject,
premisAgentXMLToObject, premisAgentXMLgetObject,
objectToPremisEventXML, objectToPremisAgentXML,
objectToAgentXML, translateDict, DuplicateEventError,
PREMIS_NSMAP)
from .presentation import (premisEventXMLToObject, premisAgentXMLToObject,
premisAgentXMLgetObject, objectToPremisEventXML,
objectToPremisAgentXML, objectToAgentXML,
DuplicateEventError, PREMIS_NSMAP, xpath_map)
from settings import ARK_NAAN

ARK_ID_REGEX = re.compile(r'ark:/'+str(ARK_NAAN)+r'/\w.*')
MAINTENANCE_MSG = settings.MAINTENANCE_MSG
EVENT_UPDATE_TRANSLATION_DICT = translateDict
EVENT_UPDATE_TRANSLATION_DICT = xpath_map
XML_HEADER = "<?xml version=\"1.0\"?>\n%s"

EVENT_SEARCH_PER_PAGE = 20
Expand Down Expand Up @@ -626,13 +625,14 @@ def app_event(request, identifier=None):
content_type='text/plain',
status=400
)
updatedEvent = updateObjectFromXML(
xmlObject=xmlDoc,
XMLToObjectFunc=premisEventXMLgetObject,
topLevelName="event",
idKey="event_identifier",
updateList=EVENT_UPDATE_TRANSLATION_DICT,
)
event = Event.objects.get(event_identifier=identifier)
if not event:
return HttpResponse(
'Event not found',
content_type='text/plain',
status=404
)
updatedEvent = updateObjectFromXML(xmlDoc, event, EVENT_UPDATE_TRANSLATION_DICT)
# If XML identifier and resource ID don't match, bail.
if updatedEvent.event_identifier != identifier:
return HttpResponse(
Expand Down
9 changes: 6 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest
import os
from lxml import etree
import datetime

from codalib.xsdatetime import xsDateTime_format

from . import factories
Expand Down Expand Up @@ -44,9 +46,10 @@ def entry_xml(self):
</content>
</entry>
"""
self.attributes["event_date_time"] = xsDateTime_format(
self.attributes["event_date_time"]
)
if isinstance(self.attributes['event_date_time'], datetime.datetime):
self.attributes["event_date_time"] = xsDateTime_format(
self.attributes["event_date_time"]
)
return xml.format(
linking_objects=self._linking_objects_xml(),
**self.attributes)
Expand Down
4 changes: 2 additions & 2 deletions tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

URL_TYPE = 'http://purl.org/net/untl/vocabularies/identifier-qualifiers/#URL'

EVENT_TYPES = [value for value, _ in settings.EVENT_TYPE_CHOICES]
EVENT_TYPES = [value for value, _ in settings.EVENT_TYPE_CHOICES if value]

EVENT_OUTCOMES = [value for value, _ in settings.EVENT_OUTCOME_CHOICES]
EVENT_OUTCOMES = [value for value, _ in settings.EVENT_OUTCOME_CHOICES if value]

AGENTS = [
'http://example.com/agent/codareplicationverification',
Expand Down
2 changes: 0 additions & 2 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,6 @@ def test_post_creates_event(self, event_xml, rf):
views.app_event(request)
assert models.Event.objects.count() == 1

@pytest.mark.xfail(reason='Call to updateObjectFromXML fails unexpectedly.')
def test_put_returns_ok(self, event_xml, rf):
identifier = event_xml.identifier
factories.EventFactory.create(event_identifier=identifier)
Expand All @@ -473,7 +472,6 @@ def test_put_returns_ok(self, event_xml, rf):

assert response.status_code == 200

@pytest.mark.xfail(reason='Call to updateObjectFromXML fails unexpectedly.')
def test_put_response_content_type(self, event_xml, rf):
identifier = event_xml.identifier
factories.EventFactory.create(event_identifier=identifier)
Expand Down

0 comments on commit cfa3c32

Please sign in to comment.