Beispiel #1
0
    def test_add_registry(self, mock_identify, mock_metadata_formats,
                          mock_sets, mock_get):
        """ Test add registry
        Args:
            mock_identify:
            mock_metadata_formats:
            mock_sets:
            mock_get:

        Returns:

        """
        # Arrange
        mock_identify.return_value = OaiPmhMock.mock_oai_identify(
        ), status.HTTP_200_OK
        mock_metadata_formats.return_value = OaiPmhMock.mock_oai_metadata_format(), \
            status.HTTP_200_OK
        mock_sets.return_value = OaiPmhMock.mock_oai_set(), status.HTTP_200_OK
        text = '<test>Hello</test>'
        mock_get.return_value.status_code = status.HTTP_200_OK
        mock_get.return_value.text = text

        # Act
        result = oai_registry_api.add_registry_by_url(
            self.fixture.url, self.fixture.harvest_rate, self.fixture.harvest)

        # Assert
        self.assertIsInstance(result, OaiRegistry)
Beispiel #2
0
    def test_add_registry_by_url_raises_exception_if_bad_sets_data(
            self, mock_registry, mock_identify, mock_set, mock_transform):
        """

        Args:
            mock_registry:
            mock_identify:
            mock_set:
            mock_transform:

        Returns:

        """
        # Arrange
        mock_user = create_mock_user("1", is_superuser=True)
        mock_request = create_mock_request(user=mock_user)
        mock_registry.return_value = False
        mock_identify.return_value = OaiPmhMock.mock_oai_identify(
        ), status.HTTP_200_OK
        mock_set.return_value = [], status.HTTP_200_OK
        exception_message = "Bad sets"
        mock_transform.side_effect = Exception(exception_message)

        # Act + Assert
        with self.assertRaises(
                oai_pmh_exceptions.OAIAPILabelledException) as ex:
            oai_registry_api.add_registry_by_url(self.url,
                                                 self.harvest_rate,
                                                 self.harvest,
                                                 request=mock_request)

        self.assertTrue(exception_message in ex.exception.message)
        self.assertEqual(ex.exception.status_code, status.HTTP_400_BAD_REQUEST)
Beispiel #3
0
    def test_add_registry_metadata_format(self, mock_identify,
                                          mock_metadata_formats, mock_sets,
                                          mock_get):
        """ Test add registry metadata formats
        Args:
            mock_identify:
            mock_metadata_formats:
            mock_sets:
            mock_get:

        Returns:

        """
        # Arrange
        mock_identify.return_value = OaiPmhMock.mock_oai_identify(
        ), status.HTTP_200_OK
        list_metadata_formats = OaiPmhMock.mock_oai_metadata_format()
        mock_metadata_formats.return_value = list_metadata_formats, status.HTTP_200_OK
        mock_sets.return_value = [], status.HTTP_200_OK
        text = '<test>Hello</test>'
        mock_get.return_value.status_code = status.HTTP_200_OK
        mock_get.return_value.text = text

        # Act
        result = oai_registry_api.add_registry_by_url(
            self.fixture.url, self.fixture.harvest_rate, self.fixture.harvest)

        # Assert
        _assert_metadata_format(self, list_metadata_formats, result.id)
Beispiel #4
0
    def test_add_registry_sets(self, mock_identify, mock_metadata_formats,
                               mock_sets, mock_get):
        """Test add registry sets
        Args:
            mock_identify:
            mock_metadata_formats:
            mock_sets:
            mock_get:

        Returns:

        """
        # Arrange
        mock_user = create_mock_user("1", is_superuser=True)
        mock_request = create_mock_request(user=mock_user)
        mock_identify.return_value = OaiPmhMock.mock_oai_identify(
        ), status.HTTP_200_OK
        mock_metadata_formats.return_value = [], status.HTTP_200_OK
        list_sets = OaiPmhMock.mock_oai_set()
        mock_sets.return_value = list_sets, status.HTTP_200_OK
        text = "<test>Hello</test>"
        mock_get.return_value.status_code = status.HTTP_200_OK
        mock_get.return_value.text = text

        # Act
        result = oai_registry_api.add_registry_by_url(
            self.fixture.url,
            self.fixture.harvest_rate,
            self.fixture.harvest,
            request=mock_request,
        )

        # Assert
        _assert_set(self, list_sets, result.id)
Beispiel #5
0
    def test_upsert_creates_if_does_not_exist(self):
        """ Test upsert create
        """
        # Arrange
        oai_identify = OaiPmhMock.mock_oai_identify()
        self.fixture.insert_registry(insert_related_collections=False)

        # Act
        oai_registry_api._upsert_identify_for_registry(oai_identify, self.fixture.registry)

        # Assert
        identify_in_database = oai_identify_api.get_by_registry_id(self.fixture.registry.id)
        self.assertEquals(identify_in_database, oai_identify)
Beispiel #6
0
    def test_update_registry(self, mock_identify, mock_metadata_formats, mock_sets, mock_get):
        # Arrange
        identify = OaiPmhMock.mock_oai_identify(version=2)
        mock_identify.return_value = identify, status.HTTP_200_OK
        first_metadata_format = OaiPmhMock.mock_oai_metadata_format(version=2)
        mock_metadata_formats.return_value = first_metadata_format, status.HTTP_200_OK
        first_set = OaiPmhMock.mock_oai_set(version=2)
        mock_sets.return_value = first_set, status.HTTP_200_OK
        text = '<test>Hello</test>'
        mock_get.return_value.status_code = status.HTTP_200_OK
        mock_get.return_value.text = text

        # Act
        result = oai_registry_api.update_registry_info(self.fixture.registry)

        # Assert
        _assert_identify(self, identify, result.id)
        _assert_metadata_format(self, first_metadata_format, result.id)
        _assert_set(self, first_set, result.id)
    def test_update_registry_info(self, mock_identify, mock_metadata_formats,
                                  mock_sets, mock_get):
        # Arrange
        identify = OaiPmhMock.mock_oai_identify(version=2)
        mock_identify.return_value = identify, status.HTTP_200_OK
        first_metadata_format = OaiPmhMock.mock_oai_metadata_format(version=2)
        mock_metadata_formats.return_value = first_metadata_format, status.HTTP_200_OK
        first_set = OaiPmhMock.mock_oai_set(version=2)
        mock_sets.return_value = first_set, status.HTTP_200_OK
        text = '<test>Hello</test>'
        mock_get.return_value.status_code = status.HTTP_200_OK
        mock_get.return_value.text = text

        # Act
        response = RequestMock.do_request_patch(
            rest_oai_registry.InfoRegistry.as_view(),
            user=create_mock_user('1', is_staff=True),
            param=self.param)

        # Assert
        self.assertEqual(response.status_code, status.HTTP_200_OK)
Beispiel #8
0
    def test_update_registry(self, mock_identify, mock_metadata_formats,
                             mock_sets, mock_get):
        # Arrange
        mock_user = create_mock_user("1", is_superuser=True)
        mock_request = create_mock_request(user=mock_user)
        identify = OaiPmhMock.mock_oai_identify(version=2)
        mock_identify.return_value = identify, status.HTTP_200_OK
        first_metadata_format = OaiPmhMock.mock_oai_metadata_format(version=2)
        mock_metadata_formats.return_value = first_metadata_format, status.HTTP_200_OK
        first_set = OaiPmhMock.mock_oai_set(version=2)
        mock_sets.return_value = first_set, status.HTTP_200_OK
        text = "<test>Hello</test>"
        mock_get.return_value.status_code = status.HTTP_200_OK
        mock_get.return_value.text = text

        # Act
        result = oai_registry_api.update_registry_info(self.fixture.registry,
                                                       request=mock_request)

        # Assert
        _assert_identify(self, identify, result.id)
        _assert_metadata_format(self, first_metadata_format, result.id)
        _assert_set(self, first_set, result.id)