Exemplo n.º 1
0
    def test_resolve_id(self):
        metadir = os.path.join(self.bagdir, 'metadata')
        self.assertFalse(os.path.exists(self.bagdir))

        mdata = self.srv.resolve_id(self.midasid)

        loader = ejs.SchemaLoader.from_directory(schemadir)
        val = ejs.ExtValidator(loader, ejsprefix='_')
        val.validate(mdata, False, True)

        # resolve_id() needs to be indepodent
        data = self.srv.resolve_id(self.midasid)
        self.assertEqual(data, mdata)

        with self.assertRaises(serv.SIPDirectoryNotFound):
            self.srv.resolve_id("asldkfjsdalfk")
Exemplo n.º 2
0
    def test_resolve_arkid(self):
        indir = os.path.join(self.workdir, os.path.basename(self.testsip))
        shutil.copytree(self.testsip, indir)
        self.upldir = os.path.join(indir, "upload")
        self.revdir = os.path.join(indir, "review")

        podf = os.path.join(self.upldir, "1491", "_pod.json")
        with open(podf) as fd:
            pod = json.load(fd)
        pod['identifier'] = self.arkid
        with open(podf, 'w') as fd:
            json.dump(pod, fd, indent=2)
        podf = os.path.join(self.revdir, "1491", "_pod.json")
        with open(podf, 'w') as fd:
            json.dump(pod, fd, indent=2)

        self.config = {
            'working_dir': self.workdir,
            'review_dir': self.revdir,
            'upload_dir': self.upldir,
            'id_registry_dir': self.workdir,
            'bagger': {
                'bag_builder': {
                    'validate_id': r'(pdr\d)|(mds[01])'
                }
            }
        }
        self.srv = serv.PrePubMetadataService(self.config)
        self.bagdir = os.path.join(self.bagparent, self.arkid[11:])

        metadir = os.path.join(self.bagdir, 'metadata')
        self.assertFalse(os.path.exists(metadir))

        mdata = self.srv.resolve_id(self.arkid)
        self.assertIn("ediid", mdata)
        self.assertEquals(mdata['ediid'], self.arkid)
        self.assertEquals(mdata['@id'], self.arkid)

        # just for testing purposes, a pdr_status property will appear
        # in the record if this dataset is an update to a previous
        # release.
        self.assertNotIn("pdr_status", mdata)

        loader = ejs.SchemaLoader.from_directory(schemadir)
        val = ejs.ExtValidator(loader, ejsprefix='_')
        val.validate(mdata, False, True)
Exemplo n.º 3
0
    def test_resolve_id(self):
        metadir = os.path.join(self.bagdir, 'metadata')
        self.assertFalse(os.path.exists(self.bagdir))

        mdata = self.srv.resolve_id(self.midasid)
        self.assertIn("ediid", mdata)

        # just for testing purposes, a pdr_status property will appear
        # in the record if this dataset is an update to a previous
        # release.
        self.assertNotIn("pdr_status", mdata)

        loader = ejs.SchemaLoader.from_directory(schemadir)
        val = ejs.ExtValidator(loader, ejsprefix='_')
        val.validate(mdata, False, True)

        # resolve_id() is not indepodent with async file examination turned on!
        #
        ## resolve_id() needs to be indepodent
        #data = self.srv.resolve_id(self.midasid)
        #self.assertEqualOD(data, mdata)

        with self.assertRaises(serv.IDNotFound):
            self.srv.resolve_id("asldkfjsdalfk")
Exemplo n.º 4
0
 def setUp(self):
     loader = ejs.SchemaLoader.from_directory(schemadir)
     self.val = ejs.ExtValidator(loader, ejsprefix='_')
Exemplo n.º 5
0
#!/usr/bin/python
#
import os, unittest, json, subprocess as subproc, types, pdb
import ejsonschema as ejs

nerdm = "https://data.nist.gov/od/dm/nerdm-schema/v0.2#"
nerdmpub = "https://data.nist.gov/od/dm/nerdm-schema/pub/v0.2#"
podds = "https://data.nist.gov/od/dm/pod-schema/v1.1#/definitions/Dataset"
jqlib = os.path.dirname(os.path.abspath(os.path.dirname(__file__)))
schemadir = os.path.join(os.path.dirname(jqlib), "model")
datadir = os.path.join(schemadir,"examples")

loader = ejs.SchemaLoader.from_directory(schemadir)
val = ejs.ExtValidator(loader, ejsprefix='_')


class TestSamples(unittest.TestCase):

    def convert(self, filename):
        nerdfile = os.path.join(datadir, filename)
        return send_file_thru_jq('nerdm::resource2midaspodds', nerdfile)

    def test_janaf(self):
        pod = self.convert("janaf.json")
        val.validate(pod, schemauri=podds)

        for key in "references landingPage distribution issued license".split():
            self.assertIn(key, pod)

        self.assertEqual(len(pod['references']), 2)
        self.assertEqual(len(pod['distribution']), 319)