def test_getDatastream(self): ds_profile, url = self.rest_api.getDatastream(self.pid, "DC") self.assert_("<datastreamProfile" in ds_profile) self.assert_('pid="%s"' % self.pid in ds_profile) self.assert_('dsID="DC" ' in ds_profile) self.assert_("<dsLabel>Dublin Core</dsLabel>" in ds_profile) self.assert_("<dsVersionID>DC.0</dsVersionID>" in ds_profile) self.assert_("<dsCreateDate>%s" % self.today in ds_profile) self.assert_("<dsState>A</dsState>" in ds_profile) self.assert_("<dsMIME>text/xml</dsMIME>" in ds_profile) self.assert_("<dsControlGroup>X</dsControlGroup>" in ds_profile) self.assert_("<dsVersionable>true</dsVersionable>" in ds_profile) # get server datetime param (the hard way) for testing dsprofile_node = etree.fromstring(ds_profile, base_url=url) created_s = dsprofile_node.xpath("string(m:dsCreateDate)", namespaces={"m": FEDORA_MANAGE_NS}) created = fedoratime_to_datetime(created_s) # with date param ds_profile_now, url = self.rest_api.getDatastream(self.pid, "DC", asOfDateTime=created + ONE_SEC) # NOTE: contents are not exactly equal because 'now' version includes a dateTime attribute self.assert_("<dsLabel>Dublin Core</dsLabel>" in ds_profile_now) self.assert_("<dsVersionID>DC.0</dsVersionID>" in ds_profile_now) # bogus datastream id on valid pid self.assertRaises(Exception, self.rest_api.getDatastream, self.pid, "BOGUS") # bogus pid self.assertRaises(Exception, self.rest_api.getDatastream, "bogus:pid", "DC")
def test_getObjectProfile(self): r = self.rest_api.getObjectProfile(self.pid) profile = r.text self.assert_('<objectProfile' in profile) self.assert_('pid="%s"' % self.pid in profile) self.assert_( '<objLabel>A partially-prepared test object</objLabel>' in profile) self.assert_('<objOwnerId>tester</objOwnerId>' in profile) self.assert_('<objCreateDate>%s' % self.today in profile) self.assert_('<objLastModDate>%s' % self.today in profile) self.assert_('<objState>A</objState>' in profile) # unchecked: objDissIndexViewURL, objItemIndexViewURL # get server datetime param (the hard way) for testing profile_node = etree.fromstring(r.content, base_url=r.url) created_s = profile_node.xpath('string(a:objCreateDate)', namespaces={'a': FEDORA_ACCESS_NS}) created = fedoratime_to_datetime(created_s) # with time r = self.rest_api.getObjectProfile(self.pid, asOfDateTime=created + ONE_SEC) profile_now = r.text # NOTE: profile content is not exactly the same because it includes a datetime attribute self.assert_('pid="%s"' % self.pid in profile_now) self.assert_('<objLabel>A partially-prepared test object</objLabel>' in profile_now) # bogus pid self.assertRaises(Exception, self.rest_api.getObjectHistory, "bogus:pid")
def test_getObjectProfile(self): r = self.rest_api.getObjectProfile(self.pid) profile = r.text self.assert_("<objectProfile" in profile) self.assert_('pid="%s"' % self.pid in profile) self.assert_("<objLabel>A partially-prepared test object</objLabel>" in profile) self.assert_("<objOwnerId>tester</objOwnerId>" in profile) self.assert_("<objCreateDate>%s" % self.today in profile) self.assert_("<objLastModDate>%s" % self.today in profile) self.assert_("<objState>A</objState>" in profile) # unchecked: objDissIndexViewURL, objItemIndexViewURL # get server datetime param (the hard way) for testing profile_node = etree.fromstring(r.content, base_url=r.url) created_s = profile_node.xpath("string(a:objCreateDate)", namespaces={"a": FEDORA_ACCESS_NS}) created = fedoratime_to_datetime(created_s) # with time r = self.rest_api.getObjectProfile(self.pid, asOfDateTime=created + ONE_SEC) profile_now = r.text # NOTE: profile content is not exactly the same because it includes a datetime attribute self.assert_('pid="%s"' % self.pid in profile_now) self.assert_("<objLabel>A partially-prepared test object</objLabel>" in profile_now) # bogus pid self.assertRaises(Exception, self.rest_api.getObjectHistory, "bogus:pid")
def test_getDatastreamDissemination(self): dc, url = self.rest_api.getDatastreamDissemination(self.pid, "DC") self.assert_("<dc:title>A partially-prepared test object</dc:title>" in dc) self.assert_("<dc:description>This object has more data" in dc) self.assert_("<dc:identifier>%s</dc:identifier>" % self.pid in dc) # get server datetime param (the hard way) for testing dsprofile_data, url = self.rest_api.getDatastream(self.pid, "DC") dsprofile_node = etree.fromstring(dsprofile_data, base_url=url) created_s = dsprofile_node.xpath("string(m:dsCreateDate)", namespaces={"m": FEDORA_MANAGE_NS}) created = fedoratime_to_datetime(created_s) # with date-time param postcreate_dc, url = self.rest_api.getDatastreamDissemination(self.pid, "DC", asOfDateTime=created + ONE_SEC) self.assertEqual(dc, postcreate_dc) # unchanged within its first sec # bogus datastream self.assertRaises(Exception, self.rest_api.getDatastreamDissemination, self.pid, "BOGUS") # bogus pid self.assertRaises(Exception, self.rest_api.getDatastreamDissemination, "bogus:pid", "BOGUS") # return_http_response response = self.rest_api.getDatastreamDissemination(self.pid, "DC", return_http_response=True) self.assert_( isinstance(response, httplib.HTTPResponse), "getDatastreamDissemination should return an HTTPResponse when return_http_response is True", ) # datastream content should still be accessible self.assertEqual(dc, response.read())
def test_getDatastream(self): r = self.rest_api.getDatastream(self.pid, "DC") ds_profile = r.content ds_profile_text = r.text self.assert_('<datastreamProfile' in ds_profile_text) self.assert_('pid="%s"' % self.pid in ds_profile_text) self.assert_('dsID="DC"' in ds_profile_text) self.assert_('<dsLabel>Dublin Core</dsLabel>' in ds_profile_text) self.assert_('<dsVersionID>DC.0</dsVersionID>' in ds_profile_text) self.assert_('<dsCreateDate>%s' % self.today in ds_profile_text) self.assert_('<dsState>A</dsState>' in ds_profile_text) self.assert_('<dsMIME>text/xml</dsMIME>' in ds_profile_text) self.assert_('<dsControlGroup>X</dsControlGroup>' in ds_profile_text) self.assert_('<dsVersionable>true</dsVersionable>' in ds_profile_text) # get server datetime param (the hard way) for testing dsprofile_node = etree.fromstring(ds_profile, base_url=r.url) created_s = dsprofile_node.xpath('string(m:dsCreateDate)', namespaces={'m': FEDORA_MANAGE_NS}) created = fedoratime_to_datetime(created_s) # with date param r = self.rest_api.getDatastream(self.pid, "DC", asOfDateTime=created + ONE_SEC) ds_profile_now = r.text # NOTE: contents are not exactly equal because 'now' version includes a dateTime attribute self.assert_('<dsLabel>Dublin Core</dsLabel>' in ds_profile_now) self.assert_('<dsVersionID>DC.0</dsVersionID>' in ds_profile_now) # bogus datastream id on valid pid self.assertRaises(Exception, self.rest_api.getDatastream, self.pid, "BOGUS") # bogus pid self.assertRaises(Exception, self.rest_api.getDatastream, "bogus:pid", "DC")
def test_getDatastreamDissemination(self): r = self.rest_api.getDatastreamDissemination(self.pid, "DC") dc = r.text self.assert_("<dc:title>A partially-prepared test object</dc:title>" in dc) self.assert_("<dc:description>This object has more data" in dc) self.assert_("<dc:identifier>%s</dc:identifier>" % self.pid in dc) # get server datetime param (the hard way) for testing r = self.rest_api.getDatastream(self.pid, "DC") dsprofile_node = etree.fromstring(r.content, base_url=r.url) created_s = dsprofile_node.xpath('string(m:dsCreateDate)', namespaces={'m': FEDORA_MANAGE_NS}) created = fedoratime_to_datetime(created_s) # with date-time param r = self.rest_api.getDatastreamDissemination(self.pid, "DC", asOfDateTime=created + ONE_SEC) postcreate_dc = r.text self.assertEqual(dc, postcreate_dc) # unchanged within its first sec # bogus datastream self.assertRaises(Exception, self.rest_api.getDatastreamDissemination, self.pid, "BOGUS") # bogus pid self.assertRaises(Exception, self.rest_api.getDatastreamDissemination, "bogus:pid", "BOGUS") # return_http_response response = self.rest_api.getDatastreamDissemination(self.pid, 'DC') self.assert_(isinstance(response, requests.Response), 'getDatastreamDissemination should return a response object') # datastream content should still be accessible self.assertEqual(dc, response.text)
def test_getDatastreamDissemination(self): r = self.rest_api.getDatastreamDissemination(self.pid, "DC") dc = r.content self.assert_("<dc:title>A partially-prepared test object</dc:title>" in dc) self.assert_("<dc:description>This object has more data" in dc) self.assert_("<dc:identifier>%s</dc:identifier>" % self.pid in dc) # get server datetime param (the hard way) for testing r = self.rest_api.getDatastream(self.pid, "DC") dsprofile_node = etree.fromstring(r.content, base_url=r.url) created_s = dsprofile_node.xpath('string(m:dsCreateDate)', namespaces={'m': FEDORA_MANAGE_NS}) created = fedoratime_to_datetime(created_s) # with date-time param r = self.rest_api.getDatastreamDissemination(self.pid, "DC", asOfDateTime=created + ONE_SEC) postcreate_dc = r.content self.assertEqual(dc, postcreate_dc) # unchanged within its first sec # bogus datastream self.assertRaises(Exception, self.rest_api.getDatastreamDissemination, self.pid, "BOGUS") # bogus pid self.assertRaises(Exception, self.rest_api.getDatastreamDissemination, "bogus:pid", "BOGUS") # return_http_response response = self.rest_api.getDatastreamDissemination(self.pid, 'DC') self.assert_(isinstance(response, requests.Response), 'getDatastreamDissemination should return a response object') # datastream content should still be accessible self.assertEqual(dc, response.content)
def to_python(self, node): rep = self.XPATH(node) return fedoratime_to_datetime(rep)