Exemple #1
0
    def test_harvest_records_returns_errors_if_not_HTTP_200_OK(
            self, mock_list_records):
        """

        Args:
            mock_list_records:

        Returns:

        """
        # Arrange
        resumption_token = None
        content = OaiPmhMessage.get_message_labelled("Error")
        status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
        mock_list_records.return_value = (
            Response(content, status=status_code),
            resumption_token,
        )
        expected_error = [{"status_code": status_code, "error": "Error"}]
        registry = Mock(spec=OaiRegistry())
        registry.url = "dummy_url"
        metadata_format = Mock(spec=OaiHarvesterMetadataFormat())
        metadata_format.metadata_prefix = "oai_dummy"
        last_update = registry_all_sets = None

        # Act
        result = oai_registry_api._harvest_records(registry, metadata_format,
                                                   last_update,
                                                   registry_all_sets)

        # Assert
        self.assertEquals(result, expected_error)
def get_all():
    """ Returns all OaiRegistry

    Returns:
        List of OaiRegistry

    """
    return OaiRegistry.get_all()
Exemple #3
0
def check_registry_url_already_exists(oai_registry_url):
    """ Checks if an OaiRegistry with the given url already exists.

    Returns:
        Yes or No (bool).

    """
    return OaiRegistry.check_registry_url_already_exists(oai_registry_url=oai_registry_url)
Exemple #4
0
def get_all_activated_registry(order_by_field=None):
    """ Returns all activated OaiRegistry.

        Returns:
            List of OaiRegistry

        """
    return OaiRegistry.get_all_by_is_activated(is_activated=True, order_by_field=order_by_field)
Exemple #5
0
def _create_oai_registry():
    """Get an OaiRegistry object.

    Returns:
        OaiRegistry instance.

    """
    oai_registry = OaiRegistry()
    _set_oai_registry_fields(oai_registry)

    return oai_registry
Exemple #6
0
def _create_mock_oai_identify():
    """ Mock an OaiIdentify.

    Returns:
        OaiIdentify mock.

    """
    mock_oai_identify = Mock(spec=OaiIdentify)
    mock_oai_identify.registry = OaiRegistry()

    return mock_oai_identify
def get_by_name(oai_registry_name):
    """ Returns an OaiRegistry by its name.

    Args:
        oai_registry_name: OaiRegistry name.

    Returns: The OaiRegistry instance.

    Raises:
        DoesNotExist: The registry doesn't exist
        ModelError: Internal error during the process

    """
    return OaiRegistry.get_by_name(oai_registry_name=oai_registry_name)
Exemple #8
0
    def insert_registry(self,
                        name='Registry',
                        insert_related_collections=True,
                        insert_records=True):
        self.registry = OaiRegistry(name=name,
                                    url=self.url,
                                    harvest_rate=self.harvest_rate,
                                    harvest=self.harvest).save()
        if insert_related_collections:
            self.oai_identify = self.insert_oai_identify()
            self.oai_sets = self.insert_oai_sets()
            self.oai_metadata_formats = self.insert_oai_metadata_formats()

        if insert_records:
            self.oai_records = self.insert_oai_records()
Exemple #9
0
def _set_oai_harvester_set_fields(oai_harvester_set):
    """ Set OaiHarvesterSet fields.

    Args:
        oai_harvester_set:

    Returns:
        OaiHarvesterSet with assigned fields.

    """
    oai_harvester_set.set_spec = "oai_test"
    oai_harvester_set.set_name = "test"
    oai_harvester_set.raw = dict()
    oai_harvester_set.registry = OaiRegistry()
    oai_harvester_set.harvest = True

    return oai_harvester_set
Exemple #10
0
def _init_registry(url, harvest, harvest_rate, repository_name, description):
    """ Returns an init OaiRegistry object.

    Args:
        url: url of the registry.
        harvest: True or False
        harvest_rate: Harvest rate. Use to harvest data every harvest_rate seconds.
        repository_name: Repository name.
        description: Description.

    Returns:
        The OaiRegistry instance.

    """
    registry = OaiRegistry(name=repository_name, url=url, harvest_rate=harvest_rate,
                           description=description, harvest=harvest, is_activated=True)
    return registry
Exemple #11
0
def _set_oai_harvester_metadata_format_fields(oai_harvester_metadata_format):
    """ Set OaiHarvesterMetadataFormat fields.

    Args:
        oai_harvester_metadata_format:

    Returns:
        OaiHarvesterMetadataFormat with assigned fields.

    """
    oai_harvester_metadata_format.metadata_prefix = "test"
    oai_harvester_metadata_format.schema = "http://test.com/test.xsd"
    oai_harvester_metadata_format.metadataNamespace = 'http://test.com/meta'
    oai_harvester_metadata_format.raw = dict()
    oai_harvester_metadata_format.registry = OaiRegistry()
    oai_harvester_metadata_format.harvest = True
    oai_harvester_metadata_format.last_update = datetime.datetime.now()

    return oai_harvester_metadata_format
def _set_oai_record_fields(oai_record):
    """Set OaiRecord fields.

    Args:
        oai_record:

    Returns:
        OaiRecord with assigned fields.

    """
    oai_record.identifier = "oai:test/id.0006"
    oai_record.last_modification_date = datetime.datetime.now()
    oai_record.deleted = False
    oai_record.harvester_sets = [OaiHarvesterSet(), OaiHarvesterSet()]
    oai_record.harvester_metadata_format = OaiHarvesterMetadataFormat()
    oai_record.registry = OaiRegistry()
    oai_record.xml_content = "<test><message>Hello</message></test>"

    return oai_record
Exemple #13
0
    def test_harvest_records_returns_errors_if_transform_raises(
            self, mock_list_records, mock_transform_operations):
        """

        Args:
            mock_list_records:
            mock_transform_operations:

        Returns:

        """
        # Arrange
        resumption_token = None
        content = []
        status_code = status.HTTP_200_OK
        mock_list_records.return_value = (
            Response(content, status=status_code),
            resumption_token,
        )
        error_message = "Error"
        expected_error = [{
            "status_code": status.HTTP_400_BAD_REQUEST,
            "error": error_message
        }]
        registry = Mock(spec=OaiRegistry())
        registry.url = "dummy_url"
        metadata_format = Mock(spec=OaiHarvesterMetadataFormat())
        metadata_format.metadata_prefix = "oai_dummy"
        last_update = registry_all_sets = None
        mock_transform_operations.side_effect = Exception(error_message)

        # Act
        result = oai_registry_api._harvest_records(registry, metadata_format,
                                                   last_update,
                                                   registry_all_sets)

        # Assert
        self.assertEquals(result, expected_error)