class OxpointsDescendantsImporterTestCase(unittest.TestCase):

    def setUp(self):
        self.sample_oxpoints = 'moxie/tests/data/sample-oxpoints.rdf'
        self.mock_kv = mock.Mock()
        self.importer = OxpointsDescendantsImporter(self.mock_kv, self.sample_oxpoints,
                                                    Org.subOrganizationOf,
                                                    rdf_media_type='xml')

    def test_importer_runs(self):
        self.importer.import_data()

    def test_importer_writes_kv(self):
        self.importer.import_data()
        self.assertTrue(self.mock_kv.set.called)
        # Sample data has 3 items
        self.assertEqual(self.mock_kv.set.call_count, 3)

    def test_university_descendants(self):
        self.importer.import_data()
        self.mock_kv.set.assert_called_with('oxpoints:00000000', '{"descendants": [{"id": "oxpoints:23232639", "title": "Mathematical, Physical and Life Sciences"}, {"id": "oxpoints:23232673", "title": "Department of Physics"}]}')

    def test_mpls_descendants(self):
        self.importer.import_data()
        self.mock_kv.set.assert_any_call('oxpoints:23232639', '{"descendants": [{"id": "oxpoints:23232673", "title": "Department of Physics"}]}')

    def test_import_only_mpls(self):
        mpls = URIRef("http://oxpoints.oucs.ox.ac.uk/id/23232639")
        desc = self.importer.import_subject(mpls)
        self.assertEqual(desc, [{'id': 'oxpoints:23232673', 'title': u'Department of Physics'}])
        self.mock_kv.set.assert_any_call('oxpoints:23232639', '{"descendants": [{"id": "oxpoints:23232673", "title": "Department of Physics"}]}')
Пример #2
0
def import_oxpoints_organisation_descendants(previous_result=None, url=None, force_update=False):
    """Run the OxPoints organisation descendants importer
    """
    if previous_result in (None, True):
        try:
            app = create_app()
            RDF_MEDIA_TYPE = 'text/turtle'  # default RDF serialization
            with app.blueprint_context(BLUEPRINT_NAME):
                url = url or app.config['OXPOINTS_IMPORT_URL']
                oxpoints = get_resource(url, force_update, media_type=RDF_MEDIA_TYPE)
                if oxpoints:
                    logger.info("OxPoints Downloaded - Stored here: %s" % oxpoints)
                    oxpoints = open(oxpoints)
                    importer = OxpointsDescendantsImporter(kv_store, oxpoints, Org.subOrganizationOf,
                                                           rdf_media_type=RDF_MEDIA_TYPE)
                    importer.import_data()
                    return True
                else:
                    logger.info("OxPoints descendants hasn't been imported - resource not loaded")
        except:
            logger.error("Error running OxPoints descendants importer", exc_info=True)
    return False
 def setUp(self):
     self.sample_oxpoints = 'moxie/tests/data/sample-oxpoints.rdf'
     self.mock_kv = mock.Mock()
     self.importer = OxpointsDescendantsImporter(self.mock_kv, self.sample_oxpoints,
                                                 Org.subOrganizationOf,
                                                 rdf_media_type='xml')