def test_duplicate_event_id_raises_duplicate_error(self, event_xml):
        # Replace the existing hex identifier with a non-hex identifier.
        invalid_identifier = 'invalid-hex'
        xml_obj = objectify.fromstring(event_xml.obj_xml)
        xml_obj.eventIdentifier.eventIdentifierValue = invalid_identifier

        tree = objectify_to_etree(xml_obj)

        # Create an Event with the identifier.
        factories.EventFactory.create(event_identifier=invalid_identifier)
        # Try to create an Event with the same identifier (from xml).
        with pytest.raises(presentation.DuplicateEventError):
            presentation.premisEventXMLToObject(tree)
    def test_invalid_datetime_string_raises_exception(self, event_xml):
        # Replace the datetime string with an invalid datetime string.
        xml_obj = objectify.fromstring(event_xml.obj_xml)
        xml_obj.eventDateTime = 'invalid-datetime'

        tree = objectify_to_etree(xml_obj)

        with pytest.raises(Exception) as e:
            presentation.premisEventXMLToObject(tree)

        # Since the base Exception is raised from the function, we want to make
        # sure it is the correct Exception, so now check the error message and
        # see if it matches the expected message.
        assert 'Unable to parse' in str(e)
        assert 'into datetime object' in str(e)
    def test_existing_event_identifier_results_in_HttpResponse(self, event_xml):
        tree = etree.fromstring(event_xml.obj_xml)

        factories.EventFactory.create(event_identifier=event_xml.identifier)
        event_or_response = presentation.premisEventXMLToObject(tree)

        assert isinstance(event_or_response, HttpResponse)
    def test_sets_event_date_time(self, event_xml):
        tree = etree.fromstring(event_xml.obj_xml)
        event = presentation.premisEventXMLToObject(tree)
        xml_obj = etree_to_objectify(tree)

        assert isinstance(event.event_date_time, datetime)
        xsdt = xsDateTime_format(event.event_date_time)
        assert xsdt in xml_obj.eventDateTime.text
    def test_linking_objects_added(self, event_xml):
        tree = etree.fromstring(event_xml.obj_xml)
        event = presentation.premisEventXMLToObject(tree)

        xml_obj = etree_to_objectify(tree)
        linking_objects = list(xml_obj.linkingObjectIdentifier)

        assert len(linking_objects) == event.linking_objects.count()
    def test_sets_linking_agent_identifier_value(self, event_xml):
        tree = etree.fromstring(event_xml.obj_xml)
        event = presentation.premisEventXMLToObject(tree)

        xml_obj = etree_to_objectify(tree)
        assert event.linking_agent_identifier_value == (xml_obj
                                                        .linkingAgentIdentifier
                                                        .linkingAgentIdentifierValue)
    def test_sets_event_outcome_detail(self, event_xml):
        tree = etree.fromstring(event_xml.obj_xml)
        event = presentation.premisEventXMLToObject(tree)

        xml_obj = etree_to_objectify(tree)
        eodn = xml_obj.eventOutcomeInformation.eventOutcomeDetail
        eodn = eodn.eventOutcomeDetailNote
        assert event.event_outcome_detail == eodn
Beispiel #8
0
    def test_sets_event_date_time(self, event_xml):
        tree = etree.fromstring(event_xml.obj_xml)
        event = presentation.premisEventXMLToObject(tree)
        xml_obj = etree_to_objectify(tree)

        # The XML datetime string may contain milliseconds and/or timezone
        # information. Here, we check that the Event datetime string, which
        # will never have milliseconds or timzone information, is present
        # in the XML datetime string.
        assert str(event.event_date_time) in xml_obj.eventDateTime.text
        assert isinstance(event.event_date_time, datetime)
    def test_datetime_without_milliseconds(self, event_xml):
        """Test that a datetime string that does not contains milliseconds
        is properly converted to a datetime object.
        """
        # Replace the datetime string with a valid datetime string that
        # does not contain milliseconds.
        date_string = '1997-07-16T19:20:30'
        xml_obj = objectify.fromstring(event_xml.obj_xml)
        xml_obj.eventDateTime = date_string

        tree = objectify_to_etree(xml_obj)
        event = presentation.premisEventXMLToObject(tree)

        assert isinstance(event.event_date_time, datetime)
    def test_linking_objects_attributes(self, event_xml):
        tree = etree.fromstring(event_xml.obj_xml)
        event = presentation.premisEventXMLToObject(tree)

        xml_obj = etree_to_objectify(tree)
        xml_linking_object_id = xml_obj.linkingObjectIdentifier.linkingObjectIdentifierValue.text
        xml_linking_object_type = xml_obj.linkingObjectIdentifier.linkingObjectIdentifierType.text

        # Get the newly created LinkObject from the database.
        linking_object = event.linking_objects.get(object_identifier=xml_linking_object_id)

        # Assert that the database version matches the values defined in the XML.
        assert xml_linking_object_id == linking_object.object_identifier
        assert xml_linking_object_type == linking_object.object_type
 def test_returns_event_without_some_elements(self):
     # The event XML is valid but lacks some elements.
     obj_xml = """<?xml version="1.0"?>
         <premis:event xmlns:premis="info:lc/xmlns/premis-v2">
             <premis:eventIdentifier>
                 <premis:eventIdentifierType>http://purl.org/net/untl/vocabularies/identifier-qualifiers/#UUID</premis:eventIdentifierType>
                 <premis:eventIdentifierValue>1a81d172ce8f465fbcb52d146485f882</premis:eventIdentifierValue>
             </premis:eventIdentifier>
             <premis:eventType>http://purl.org/net/untl/vocabularies/preservationEvents/#fixityCheck</premis:eventType>
             <premis:eventDateTime>2017-05-13T09:14:55-05:00</premis:eventDateTime>
         </premis:event>
     """
     tree = etree.fromstring(obj_xml)
     event = presentation.premisEventXMLToObject(tree)
     assert isinstance(event, models.Event)
Beispiel #12
0
    def test_new_identifier_created_if_not_valid_uuid4(self, event_xml):
        # Replace the existing hex identifier with a non-hex identifier.
        invalid_identifier = 'invalid-hex'
        xml_obj = objectify.fromstring(event_xml.obj_xml)
        xml_obj.eventIdentifier.eventIdentifierValue = invalid_identifier

        tree = objectify_to_etree(xml_obj)

        # Create an Event with the same non-hex identifier.
        factories.EventFactory.create(event_identifier=invalid_identifier)
        event = presentation.premisEventXMLToObject(tree)

        # Make sure the returned Event is given a new hex identifier.
        assert event.event_identifier != invalid_identifier
        assert uuid.UUID(event.event_identifier, version=4)
    def test_sets_event_outcome(self, event_xml):
        tree = etree.fromstring(event_xml.obj_xml)
        event = presentation.premisEventXMLToObject(tree)

        xml_obj = etree_to_objectify(tree)
        assert event.event_outcome == xml_obj.eventOutcomeInformation.eventOutcome
    def test_sets_event_detail(self, event_xml):
        tree = etree.fromstring(event_xml.obj_xml)
        event = presentation.premisEventXMLToObject(tree)

        xml_obj = etree_to_objectify(tree)
        assert event.event_detail == xml_obj.eventDetail
    def test_sets_identifier_type(self, event_xml):
        tree = etree.fromstring(event_xml.obj_xml)
        event = presentation.premisEventXMLToObject(tree)

        xml_obj = etree_to_objectify(tree)
        assert event.event_identifier_type == xml_obj.eventIdentifier.eventIdentifierType
 def test_returns_event(self, event_xml):
     tree = etree.fromstring(event_xml.obj_xml)
     event = presentation.premisEventXMLToObject(tree)
     assert isinstance(event, models.Event)