Пример #1
0
 def testTemplateInit(self):
     dc = DublinCore()
     dc.title = 'foo'  # if dc namespace is not used it will be cleaned/removed
     dc_xml = dc.serialize()
     self.assert_(b'<oai_dc:dc ' in dc_xml)
     self.assert_(b'xmlns:dc="http://purl.org/dc/elements/1.1/"' in dc_xml)
     self.assert_(b'xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"' in dc_xml)
Пример #2
0
    def dublin_core(self):
        dc = DublinCore()
        dc.title = self.title
        dc.creator_list.extend([n.reg for n in self.header.author_list])
        dc.contributor_list.extend([n.reg for n in self.header.editor_list])
        dc.publisher = self.header.publisher
        dc.date = self.header.publication_date
        dc.rights = self.header.availability
        dc.source = self.header.source_description
        dc.subject_list.extend(self.lcsh_subjects)
        dc.description = self.project_desc
        dc.identifier = self.identifier_ark


        if self.geo_coverage:
            dc.coverage_list.append(self.geo_coverage)
        if self.creation_date:
            dc.coverage_list.append(self.creation_date)

        if self.header.series_statement:
            dc.relation_list.append(self.header.series_statement)
        # FIXME: should we also include url? site name & url are currently
        # hard-coded when setting dc:relation in postcard ingest

        return dc
Пример #3
0
    def test_create_save_errors(self):
        'Test fedora error handling when saving a collection object'
        # simulate fedora errors with mock objects

        # log in as repository editor
        self.client.post(settings.LOGIN_URL, ADMIN_CREDENTIALS)

        testobj = Mock(name='MockDigitalObject')
        testobj.dc.content = DublinCore()
        # Create a RequestFailed exception to simulate Fedora error
        # - eulcore.fedora wrap around an httplib response
        err_resp = Mock()
        err_resp.status = 500
        err_resp.read.return_value = 'error message'
        # generate Fedora error on object save
        testobj.save.side_effect = RequestFailed(err_resp)

        # valid form data to post
        test_data = {'title': 'foo', 'description': 'bar'}

        # 500 error / request failed
        # patch the repository class to return the mock object instead of a real one
        with patch.object(Repository,
                          'get_object',
                          new=Mock(return_value=testobj)):
            response = self.client.post(self.new_coll_url,
                                        test_data,
                                        follow=True)
            expected, code = 500, response.status_code
            self.assertEqual(
                code, expected,
                'Expected %s but returned %s for %s (Fedora 500 error)' %
                (expected, code, self.new_coll_url))
            messages = [str(msg) for msg in response.context['messages']]
            self.assert_(
                'error communicating with the repository' in messages[0])

        # update the mock error to generate a permission denied error
        err_resp.status = 401
        err_resp.read.return_value = 'denied'
        # generate Fedora error on object save
        testobj.save.side_effect = PermissionDenied(err_resp)

        # 401 error -  permission denied
        with patch.object(Repository,
                          'get_object',
                          new=Mock(return_value=testobj)):
            response = self.client.post(self.new_coll_url,
                                        test_data,
                                        follow=True)
            expected, code = 401, response.status_code
            self.assertEqual(
                code, expected,
                'Expected %s but returned %s for %s (Fedora 401 error)' %
                (expected, code, self.new_coll_url))
            messages = [str(msg) for msg in response.context['messages']]
            self.assert_("You don't have permission to create a collection" in
                         messages[0])
Пример #4
0
    def test_edit_save_errors(self):
        self.client.post(settings.LOGIN_URL, ADMIN_CREDENTIALS)
        data = self.edit_mgmt_data.copy()
        data.update({'title': 'foo', 'description': 'bar', 'creator': 'baz', 'file_name': 'foo.txt'})
        # simulate fedora errors with mock objects
        testobj = Mock(spec=FileObject, name='MockDigitalObject')
        # django templates recognize this as a callable; set to return itself when called
        testobj.return_value = testobj
        # create a Mock object, but use a DublinCore instance for xmlobjectform to inspect
        testobj.dc.content = DublinCore()
        testobj.pid = 'pid:1'	# required for url generation 
        # Create a RequestFailed exception to simulate Fedora error 
        # - eulcore.fedora wrap around an httplib response
        err_resp = Mock()
        err_resp.status = 500
   	err_resp.read.return_value = 'error message'
        # generate Fedora error on object save
        testobj.save.side_effect = RequestFailed(err_resp)

        # 500 error / request failed
        # patch the repository class to return the mock object instead of a real one
	#with patch.object(Repository, 'get_object', new=Mock(return_value=testobj)):
        with patch('genrepo.file.views.init_by_cmodel', new=Mock(return_value=testobj)):            
            response = self.client.post(self.edit_url, data, follow=True)
            expected, code = 500, response.status_code
            self.assertEqual(code, expected,
            	'Expected %s but returned %s for %s (Fedora 500 error)'
                % (expected, code, self.edit_url))
            messages = [ str(msg) for msg in response.context['messages'] ]
            self.assert_('error communicating with the repository' in messages[0])

        # update the mock object to generate a permission denied error
        err_resp.status = 401
        err_resp.read.return_value = 'denied'
        # generate Fedora error on object save
        testobj.save.side_effect = PermissionDenied(err_resp)
        
        # 401 error -  permission denied
	#with patch.object(Repository, 'get_object', new=Mock(return_value=testobj)):            
        with patch('genrepo.file.views.init_by_cmodel', new=Mock(return_value=testobj)):
            response = self.client.post(self.edit_url, data, follow=True)
            expected, code = 401, response.status_code
            self.assertEqual(code, expected,
            	'Expected %s but returned %s for %s (Fedora 401 error)'
                % (expected, code, self.edit_url))
            messages = [ str(msg) for msg in response.context['messages'] ]
            self.assert_("You don't have permission to modify this object"
                         in messages[0])
Пример #5
0
class DublinCoreEditForm(XmlObjectForm):
    """Form to edit Dublin Core metadata for a
    :class:`~genrepo.file.models.FileObject`."""
    # make title required
    title = forms.CharField(required=True)
    # configure dc:type as a choice field populated by DCMI type vocabulary
    _type_choices = [(t, t) for t in DublinCore().dcmi_types]
    # add a blank value first so there is no default value
    _type_choices.insert(0, (None, ''))
    type = forms.ChoiceField(choices=_type_choices, required=False)
    # TODO: possibly make type a repeating field?

    # TODO: sort order is a little strange because of xmlobject formsets
    # May need additional help text about not turning off OAI publication once it's enabled
    enable_oai = forms.BooleanField(
        label='Publish via OAI',
        required=False,
        help_text=
        'Should this item be made available via the Repository OAI provider?')

    file_name = forms.CharField(
        required=True,
        help_text=
        'Default file name that should be used for anyone downloads this file.'
    )

    class Meta:
        model = DublinCore
        fields = [
            'title', 'description', 'creator_list', 'contributor_list', 'date',
            'coverage_list', 'language', 'publisher', 'relation_list',
            'rights', 'source', 'subject_list', 'type', 'format', 'identifier'
        ]
        widgets = {
            'description': forms.Textarea,
            'format': ReadOnlyInput,
            'identifier': ReadOnlyInput,
        }
Пример #6
0
 def testTemplateInit(self):
     dc = DublinCore()
     dc_xml = dc.serialize()
     self.assert_('<oai_dc:dc ' in dc_xml)
     self.assert_('xmlns:dc="http://purl.org/dc/elements/1.1/"' in dc_xml)
     self.assert_('xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"' in dc_xml)