コード例 #1
0
 def test_credentials_missing_key(self):
     """Test error when creating Credentials without supplying 
     required key.
     """
     with self.assertRaises(SystemExit) as cm:
         epicclient.Credentials(
             'os',
             '../tests/resources/epic_credentials_missing_key').parse()
         self.assertEqual(cm.exception.code, 1)
コード例 #2
0
 def test_credentials_missing_prefix(self):
     """Test that prefix is set to specified username when creating
     Credentials without explicitly setting the prefix key.
     """
     credentials = epicclient.Credentials(
         'os', '../tests/resources/epic_credentials_missing_prefix')
     credentials.parse()
     self.assertIsInstance(
         credentials, epicclient.Credentials,
         'Credentials constructor returns unexpected object instance')
     self.assertEqual(credentials.prefix, credentials.username)
コード例 #3
0
ファイル: ckan_api.py プロジェクト: themiszamani/md-ingestion
def call_action(CKAN, options, action, object):
    write_log(options.log, "Call the action %s!\n" % action)
    if (options.epic):
        credentials = None
        ec = None
        try:
            credentials = epicclient.Credentials('os', options.epic)
            credentials.parse()
        except Exception, err:
            print("%s Could not create credentials from credstore %s" %
                  (err, options.epic))
        else:
            print "Create EPIC client instance to add uuid to handle server"
            ec = epicclient.EpicClient(credentials)
コード例 #4
0
 def test_credentials(self):
     """Test Credentials creation from local file."""
     credentials = epicclient.Credentials(
         'os', '../tests/resources/epic_credentials_example')
     credentials.parse()
     self.assertIsInstance(
         credentials, epicclient.Credentials,
         'Credentials constructor returns unexpected object instance')
     self.assertEqual(credentials.baseuri,
                      'https://epic.service.eu/api/v2/handles/',
                      'Credentials object returns unexpected base URI')
     self.assertEqual(credentials.prefix, '90210',
                      'Credentials object returns unexpected prefix')
     self.assertEqual(credentials.username, 'foobaruser',
                      'Credentials object returns unexpected username')
     self.assertEqual(credentials.password, 'bigsecret',
                      'Credentials object returns unexpected password')
     self.assertEqual(
         credentials.accept_format, 'application/json',
         'Credentials object returns unexpected accept_format')
     self.assertEqual(credentials.debug, False,
                      'Credentials object returns unexpected debug')
コード例 #5
0
 def test_credentials_invalid_store(self):
     """Test error when creating Credentials from invalid storage."""
     with self.assertRaises(SystemExit) as cm:
         epicclient.Credentials('BAR', 'FOO').parse()
         self.assertEqual(cm.exception.code, 1)
コード例 #6
0
 def setUp(self):
     """Setup testB2SafeCmd environment before the tests have run"""
     self.cred = epicclient.Credentials(
         CRED_STORE, TEST_RESOURCES_PATH+CRED_FILENAME)
     self.cred.parse()
     self.client = epicclient.EpicClient(self.cred)
コード例 #7
0
def call_action(CKAN, options, action, object):
    write_log(options.log, "Call the action %s!\n" % action)
    if (options.epic):
        credentials = None
        ec = None
        try:
            credentials = epicclient.Credentials('os', options.epic)
            credentials.parse()
        except Exception as err:
            print(("%s Could not create credentials from credstore %s" %
                   (err, options.epic)))
        else:
            print("Create EPIC client instance to add uuid to handle server")
            ec = epicclient.EpicClient(credentials)

    if (action == 'package_delete_all'):
        list = []
        if ('group' in object):
            data = CKAN.action('member_list', {
                "id": object['group'],
                "object_type": "package"
            })
            for d in data['result']:
                list.append(d[0])
        elif ('list' in object):
            list = object['list']

        list.reverse()

        print('Total number of datasets to delete: ' + str(len(list)))

        pcount = 0
        results = {"CKAN": 0, "EPIC": 0}

        start_time = time.time()
        for dataset in list:
            pcount += 1

            update_progress(
                'CKAN: %d, EPIC: %d\t' % (results['CKAN'], results['EPIC']),
                pcount, len(list), start_time)

            write_log(options.log, "%s\n" % dataset)
            if ((CKAN.action('package_update', {
                    "name": dataset,
                    "state": "delete"
            }))['success']):
                results['CKAN'] += 1
                write_log(options.log, "\t#Deleted in CKAN\n")
                if (options.epic):
                    if (ec.deleteHandle(credentials.prefix + '/eudat-jmd_' +
                                        dataset)):
                        results['EPIC'] += 1
                        write_log(options.log, "\t#Deleted in EPIC\n")

        print('\n')
        print("%s" % ('-' * 100))
        print(
            "\nTotal number of dataset: %d\nDeleted in CKAN: %d\nDeleted in EPIC: %d"
            % (len(list), results['CKAN'], results['EPIC']))

    else:
        out = CKAN.action(action, object)
        print(out)