Exemple #1
0
    def test_generate_ark_nodomain(self):
        # missing config settings for pid domain
        del(settings.PIDMAN_DOMAIN)
        # capture the exception to inspect it
        try:
            utils.generate_ark(self.valid_ead)
        except Exception as e:
            ex = e

        self.assert_('PID manager domain is not configured' in str(ex))
Exemple #2
0
    def test_generate_ark_badconfig(self):
        # missing config settings required for initializing pidman client
        del(settings.PIDMAN_HOST)
        # capture the exception to do minimal inspecting
        try:
            utils.generate_ark(self.valid_ead)
        except Exception as e:
            ex = e

        self.assert_('Error initializing' in str(ex))
Exemple #3
0
 def test_generate_ark(self):
     # successful case
     utils.generate_ark(self.valid_ead)
     self.assertEqual(MockDjangoPidmanClient.url,
                     settings.SITE_BASE_URL.rstrip('/') + '/documents/hartsfield558/',
                     'pid target URI is site url for ead document')
     self.assertEqual(MockDjangoPidmanClient.name, unicode(self.valid_ead.unittitle),
                     'pid name is ead document unittitle')
     self.assertEqual(settings.PIDMAN_DOMAIN, MockDjangoPidmanClient.domain,
                     'create pid used configured site pid domain')
Exemple #4
0
 def test_generate_ark_serviceerror(self):
     MockDjangoPidmanClient.raise_error = (401, 'unauthorized')
     # handle errors that could come back from the server
     try:
         utils.generate_ark(self.valid_ead)
     except Exception as e:
         ex = e
     self.assert_(isinstance(ex, Exception),
         "an exception should be raised when PID client gets a 401 response")
     self.assert_('Error generating ARK' in str(ex),
         'exception text indicates the error was while attempting to generate an ARK')
     self.assert_('unauthorized' in str(ex),
         'exception text includes error detail from pidmanclient exception')
Exemple #5
0
    def test_generate_ark_existing_pids(self):
        # simulate search finding multiple pids
        found_ark = 'http://pid.emory.edu/ark:/78912/16x3n'
        # create mock search result with two matches
        MockDjangoPidmanClient.search_result = {
            'results_count': 2,
            'results': [
                {
                    'pid': '16x3n',
                    'targets': [{'access_uri': found_ark}, ]
                },
            ]
        }
        # capture logging output in a stream
        buffer = cStringIO.StringIO()
        logger = logging.getLogger()
        sh = logging.StreamHandler(buffer)
        sh.setLevel(logging.DEBUG)
        logger.addHandler(sh)

        ark = utils.generate_ark(self.valid_ead)

        logger.removeHandler(sh)
        log_output = buffer.getvalue()

        self.assertEqual(found_ark, ark,
            'generate ark returns access uri from search results')
        self.assert_('Found 2 ARKs' in log_output,
            'log reports that multiple ARKs were found')
Exemple #6
0
    def test_generate_ark_existing_pid(self):
        # simulate search finding one ark before new ark is generated
        found_ark = 'http://pid.emory.edu/ark:/78912/16x3n'
        # create mock search result with one match
        MockDjangoPidmanClient.search_result = {
            'results_count': 1,
            'results': [
                {
                    'pid': '16x3n',
                    'targets': [{'access_uri': found_ark}, ]
                },
            ]
        }

        # capture logging output in a stream
        buffer = cStringIO.StringIO()
        logger = logging.getLogger()
        sh = logging.StreamHandler(buffer)
        sh.setLevel(logging.DEBUG)
        logger.addHandler(sh)

        ark = utils.generate_ark(self.valid_ead)

        logger.removeHandler(sh)
        log_output = buffer.getvalue()

        self.assertEqual(found_ark, ark,
            'generate ark returns access uri from search results')
        search_args = MockDjangoPidmanClient.search_args
        self.assertEqual(settings.PIDMAN_DOMAIN, search_args['domain_uri'],
            'pid search uses configured PID domain')
        self.assertEqual('ark', search_args['type'],
            'pid search is restricted to type=ark')
        self.assert_(search_args['target'].endswith('/documents/hartsfield558/'))
        self.assert_('Using existing ARK' in log_output,
            'log reports an existing ARK was used')