class TestUpdateRegistryInfo(MongoIntegrationBaseTestCase):
    fixture = OaiPmhFixtures()

    def setUp(self):
        super(TestUpdateRegistryInfo, self).setUp()
        self.fixture.insert_registry()
        self.param = {"registry_id": self.fixture.registry.id}

    @patch.object(requests, 'get')
    @patch.object(oai_verbs_api, 'list_sets_as_object')
    @patch.object(oai_verbs_api, 'list_metadata_formats_as_object')
    @patch.object(oai_verbs_api, 'identify_as_object')
    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)
class TestExecuteQueryView(MongoIntegrationBaseTestCase):
    fixture = OaiPmhFixtures()

    def setUp(self):
        super(TestExecuteQueryView, self).setUp()
        self.fixture.insert_registry()
        self.one_record_data = {
            "query":
            "{"
            '"experiment.experimentType.tracerDiffusivity.material.materialName": "Test 1"}'
        }
        self.user = create_mock_user("1")

    def test_post_query_zero_data_returns_zero_data(self):
        # Arrange
        data = {"query": '{"bad.path": "bad_value"}'}

        # Act
        response = RequestMock.do_request_post(
            oai_record_rest_views.ExecuteQueryView.as_view(),
            self.user,
            data=data)

        # Assert
        self.assertEqual(len(response.data), 0)

    def test_post_query_one_data_returns_http_200(self):
        # Arrange
        data = self.one_record_data

        # Act
        response = RequestMock.do_request_post(
            oai_record_rest_views.ExecuteQueryView.as_view(),
            self.user,
            data=data)

        # Assert
        self.assertEqual(response.status_code, status.HTTP_200_OK)

    def test_post_query_one_data_returns_one_data(self):
        # Arrange
        data = self.one_record_data

        # Act
        response = RequestMock.do_request_post(
            oai_record_rest_views.ExecuteQueryView.as_view(),
            self.user,
            data=data)

        # Assert
        self.assertEqual(len(response.data), 1)
class TestDeleteRegistry(MongoIntegrationBaseTestCase):
    fixture = OaiPmhFixtures()

    def setUp(self):
        super(TestDeleteRegistry, self).setUp()
        self.fixture.insert_registry()
        self.param = {"registry_id": str(self.fixture.registry.id)}

    def test_delete_registry(self):
        # Act
        response = RequestMock.do_request_delete(
            rest_oai_registry.RegistryDetail.as_view(),
            user=create_mock_user('1', is_staff=True),
            param=self.param)

        # Assert
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
class TestActivateRegistry(MongoIntegrationBaseTestCase):
    fixture = OaiPmhFixtures()

    def setUp(self):
        super(TestActivateRegistry, self).setUp()
        self.fixture.insert_registry()
        self.param = {"registry_id": self.fixture.registry.id}

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

        # Assert
        self.assertEqual(response.status_code, status.HTTP_200_OK)
class TestSelectAllRegistries(MongoIntegrationBaseTestCase):
    fixture = OaiPmhFixtures()

    def setUp(self):
        super(TestSelectAllRegistries, self).setUp()
        self.data = None

    def test_select_all_registries(self):
        # Arrange
        self.fixture.insert_registry()
        user = create_mock_user('1', has_perm=True)

        # Act
        response = RequestMock.do_request_get(
            rest_oai_registry.RegistryList.as_view(), user, self.data)

        # Assert
        self.assertEqual(response.status_code, status.HTTP_200_OK)
class TestSelectRegistry(MongoIntegrationBaseTestCase):
    fixture = OaiPmhFixtures()

    def setUp(self):
        super(TestSelectRegistry, self).setUp()
        self.fixture.insert_registry()
        self.param = {"registry_id": self.fixture.registry.id}

    def test_select_registry_returns(self):
        # Arrange
        user = create_mock_user('1', has_perm=True)

        # Act
        response = RequestMock.do_request_get(
            rest_oai_registry.RegistryDetail.as_view(),
            user=user,
            param=self.param)

        # Assert
        self.assertEqual(response.status_code, status.HTTP_200_OK)
class TestUpdateRegistryConf(MongoIntegrationBaseTestCase):
    fixture = OaiPmhFixtures()

    def setUp(self):
        super(TestUpdateRegistryConf, self).setUp()
        self.fixture.insert_registry()
        self.param = {"registry_id": str(self.fixture.registry.id)}
        self.data = {
            "harvest_rate": self.fixture.harvest_rate,
            "harvest": self.fixture.harvest
        }

    def test_update_registry_info(self):
        # Act
        response = RequestMock.do_request_patch(
            rest_oai_registry.RegistryDetail.as_view(),
            user=create_mock_user('1', is_staff=True),
            data=self.data,
            param=self.param)

        # Assert
        self.assertEqual(response.status_code, status.HTTP_200_OK)
Exemple #8
0
    as oai_harvester_metadata_format_api
from core_oaipmh_harvester_app.components.oai_harvester_metadata_format.models \
    import OaiHarvesterMetadataFormat
from core_oaipmh_harvester_app.components.oai_harvester_metadata_format_set import api as \
    oai_harvester_metadata_format_set_api
from core_oaipmh_harvester_app.components.oai_harvester_set import api as oai_harvester_set_api
from core_oaipmh_harvester_app.components.oai_identify import api as oai_identify_api
from core_oaipmh_harvester_app.components.oai_record import api as oai_record_api
from core_oaipmh_harvester_app.components.oai_record.models import OaiRecord
from core_oaipmh_harvester_app.components.oai_registry import api as oai_registry_api
from core_oaipmh_harvester_app.components.oai_registry.models import OaiRegistry
from core_oaipmh_harvester_app.components.oai_verbs import api as oai_verbs_api
from tests.components.oai_registry.fixtures.fixtures import OaiPmhFixtures
from tests.components.oai_registry.fixtures.fixtures import OaiPmhMock

fixture_data = OaiPmhFixtures()


class TestAddRegistry(MongoIntegrationBaseTestCase):
    """
    Test class
    """
    fixture = fixture_data

    @patch.object(requests, 'get')
    @patch.object(oai_verbs_api, 'list_sets_as_object')
    @patch.object(oai_verbs_api, 'list_metadata_formats_as_object')
    @patch.object(oai_verbs_api, 'identify_as_object')
    def test_add_registry(self, mock_identify, mock_metadata_formats,
                          mock_sets, mock_get):
        """ Test add registry