示例#1
0
    def test_upsert_oai_settings_raises_exception_if_save_failed(
            self, mock_save):
        # Arrange
        oai_settings = _create_oai_settings()

        mock_save.side_effect = Exception()

        # Act + Assert
        with self.assertRaises(Exception):
            settings_api.upsert(oai_settings)
示例#2
0
 def update(self, instance, validated_data):
     instance.repository_name = validated_data.get('repository_name',
                                                   instance.repository_name)
     instance.repository_identifier = validated_data.get(
         'repository_identifier', instance.repository_identifier)
     instance.enable_harvesting = validated_data.get(
         'enable_harvesting', instance.enable_harvesting)
     return oai_settings_api.upsert(instance)
示例#3
0
def init():
    """Init settings for the OAI-PMH feature.
    Set the name, identifier and the harvesting information
    """
    logger.info("START oai settings discovery.")

    try:
        # Get OAI-PMH settings information about this server
        oai_settings_api.get()
    except exceptions.DoesNotExist:
        oai_settings = OaiSettings(
            repository_name=settings.OAI_NAME,
            repository_identifier=settings.OAI_REPO_IDENTIFIER,
            enable_harvesting=settings.OAI_ENABLE_HARVESTING,
        )
        oai_settings_api.upsert(oai_settings)
    except Exception as e:
        logger.error("Impossible to init the settings: %s" % str(e))

    logger.info("FINISH oai settings discovery.")
示例#4
0
 def _save(self, form):
     # Save treatment.
     try:
         oai_settings_api.upsert(self.object)
     except Exception as e:
         form.add_error(None, str(e))