Skip to content

Commit

Permalink
Merge pull request #32 from unt-libraries/presentation/object-fetcher…
Browse files Browse the repository at this point in the history
…-tests

Tests for premisEventXMLgetObject and premisAgentXMLgetObject.
  • Loading branch information
damonkelley committed Oct 21, 2015
2 parents 9c5d504 + c6666db commit 9b6b4a1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def entry_xml(self):
xml = """<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<title>{event_identifier}</title>
<id>http://example.com/APP/event/{event_identifier}/</id>
<id>{event_identifier}</id>
<updated>2015-10-02T19:59:22Z</updated>
<content type="application/xml">
<premis:event xmlns:premis="info:lc/xmlns/premis-v2">
Expand Down
44 changes: 43 additions & 1 deletion tests/test_presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from lxml import etree, objectify
import pytest

from django.http import HttpResponse
from django.http import HttpResponse, Http404

from premis_event_service import presentation, models
from . import factories
Expand Down Expand Up @@ -283,3 +283,45 @@ def test_exception_not_raised_when_agent_note_is_missing(self, agent_xml):
presentation.premisAgentXMLToObject(etree.tostring(xml_obj))
# No assertions here. We only want to make sure that no exceptions
# were raised.


@pytest.mark.django_db
class TestPremisEventXMLGetObjects:

def test_returns_correct_event_object(self, event_xml):
tree = etree.fromstring(event_xml.entry_xml)
factories.EventFactory(event_identifier=event_xml.identifier)
event_obj = presentation.premisEventXMLgetObject(tree)
assert event_obj.event_identifier == event_xml.identifier
assert isinstance(event_obj, models.Event)

def test_raises_Http404_if_object_not_found(self, event_xml):
tree = etree.fromstring(event_xml.entry_xml)
with pytest.raises(Http404):
presentation.premisEventXMLgetObject(tree)

def test_raises_Http404_when_xml_has_no_id(self, event_xml):
xml_obj = objectify.fromstring(event_xml.entry_xml)
del xml_obj.id
tree = objectify_to_etree(xml_obj)

factories.EventFactory(event_identifier=event_xml.identifier)

with pytest.raises(Http404):
presentation.premisEventXMLgetObject(tree)


@pytest.mark.django_db
class TestPremisAgentXMLGetObjects:

def test_returns_correct_agent_object(self, agent_xml):
tree = etree.fromstring(agent_xml.obj_xml)
factories.AgentFactory(agent_identifier=agent_xml.identifier)
agent_obj = presentation.premisAgentXMLgetObject(tree)
assert agent_obj.agent_identifier == agent_xml.identifier
assert isinstance(agent_obj, models.Agent)

def test_raises_Http404_if_object_not_found(self, agent_xml):
tree = etree.fromstring(agent_xml.obj_xml)
with pytest.raises(Http404):
presentation.premisAgentXMLgetObject(tree)

0 comments on commit 9b6b4a1

Please sign in to comment.