def test_get_by_metadata_format_and_set_raises_exception_if_internal_error( self, get_by_metadata_format_and_set): # Arrange mock_absent_metadata_format = ObjectId() mock_absent_set = ObjectId() get_by_metadata_format_and_set.side_effect = exceptions.ModelError( "Error.") # Act + Assert with self.assertRaises(exceptions.ModelError): harvester_metadata_format_set_api.get_by_metadata_format_and_set( mock_absent_metadata_format, mock_absent_set)
def test_get_by_metadata_format_and_set_raises_exception_if_object_does_not_exist( self, get_by_metadata_format_and_set): # Arrange mock_absent_metadata_format = ObjectId() mock_absent_set = ObjectId() get_by_metadata_format_and_set.side_effect = exceptions.DoesNotExist( "Error.") # Act + Assert with self.assertRaises(exceptions.DoesNotExist): harvester_metadata_format_set_api.get_by_metadata_format_and_set( mock_absent_metadata_format, mock_absent_set)
def test_harvest_by_metadata_formats_and_sets_updates_dates( self, mock_convert_file, mock_get): """ Test harvest by metadata formats and sets update Args: mock_get: Returns: """ # Arrange mock_get.return_value.status_code = status.HTTP_200_OK mock_get.return_value.text = OaiPmhMock.\ mock_oai_response_list_records(with_resumption_token=False) metadata_format = self.fixture.oai_metadata_formats[0] set_ = self.fixture.oai_sets[0] mock_convert_file.return_value = None # Assert # Metadata Format date self.assertEquals(metadata_format.last_update, None) # Metadata Format + Set date with self.assertRaises(exceptions.DoesNotExist): oai_harvester_metadata_format_set_api.get_by_metadata_format_and_set( metadata_format, set_) # Act result = oai_registry_api._harvest_by_metadata_formats_and_sets( self.fixture.registry, [metadata_format], [set_], self.fixture.oai_sets) # Assert self.assertEquals(result, []) # Metadata Format date metadata_format_in_database = oai_harvester_metadata_format_api.\ get_by_id(metadata_format.id) self.assertNotEquals(metadata_format_in_database.last_update, None) # Metadata Format + Set date oai_h_mf_set = oai_harvester_metadata_format_set_api.\ get_by_metadata_format_and_set(metadata_format, set_) self.assertNotEquals(oai_h_mf_set.last_update, None)
def test_get_by_metadata_format_and_set_return_object( self, get_by_metadata_format_and_set ): # Arrange mock_oai_harvester_metadata_format_set = ( _create_mock_oai_harvester_metadata_format_set() ) get_by_metadata_format_and_set.return_value = ( mock_oai_harvester_metadata_format_set ) # Act result = harvester_metadata_format_set_api.get_by_metadata_format_and_set( mock_oai_harvester_metadata_format_set.harvester_metadata_format, mock_oai_harvester_metadata_format_set.harvester_set, ) # Assert self.assertIsInstance(result, OaiHarvesterMetadataFormatSet)