def insert_data_task(): """Insert XML data into OAI Data to allow for harvesting.""" logger.info("START OAI Data discovery...") # Exit early if harvesting is disable oai_settings = oai_settings_api.get() if not oai_settings.enable_harvesting: logger.info("Harvesting OFF. Exiting discovery...") return try: # Retrieve the Data ids in OAI Data oai_data = oai_data_api.get_all() oai_data_ids = oai_data.only("data").to_json() registered_data_id = [ data["data"]["$oid"] for data in json.loads(oai_data_ids) ] # Retrieve all data not registered in OAI and insert them in OAI data data = data_system_api.get_all_except(registered_data_id) logger.debug("XML Data retrieved.") for document in data: oai_data_api.upsert_from_data(document, force_update=False) logger.debug("OAI Data inserted.") except Exception as e: logger.error("Impossible to init the OAI-PMH data: %s" % str(e)) logger.info("OAI Data discovery done")
def test_system_get_all_except_inexistant_id_return_correct_count( self, mock_get_all_except): mock_data = Data(template=_get_template(), user_id='1', dict_content=OrderedDict(), title='title') mock_get_all_except.return_value = [mock_data] result = system_api.get_all_except(["1"]) self.assertEqual(len(result), 1)
def test_system_get_all_except_inexistant_id_return_data_object( self, mock_get_all_except): mock_data = Data(template=_get_template(), user_id='1', dict_content=OrderedDict(), title='title') mock_get_all_except.return_value = [mock_data] result = system_api.get_all_except(["1"]) self.assertTrue(all(isinstance(item, Data) for item in result))
def test_system_get_all_except_empty_list_return_correct_count( self, mock_get_all_except): mock_data = Data( template=_get_template(), user_id="1", dict_content=OrderedDict(), title="title", ) mock_get_all_except.return_value = [mock_data] result = system_api.get_all_except([]) self.assertEqual(len(result), 1)