Exemplo n.º 1
0
    def test_copy(self):

        # create 1 SupportedResTypes obj with required params
        resource.create_metadata_element(
            self.resWebApp.short_id,
            'SupportedResTypes',
            supported_res_types=['NetcdfResource'])
        self.assertEqual(SupportedResTypes.objects.all().count(), 1)

        # set url launching pattern for aggregations
        metadata = [{
            'requesturlbaseaggregation': {
                'value': 'https://www.google.com?agg_path=${HS_AGG_PATH}'
            }
        }]
        self.resWebApp.metadata.update(metadata, self.user)
        resource.create_metadata_element(
            self.resWebApp.short_id,
            'SupportedAggTypes',
            supported_agg_types=['GeoRasterLogicalFile'])

        self.assertEqual(1, SupportedAggTypes.objects.all().count())

        # make a new copy of web app
        new_web_app = create_empty_resource(self.resWebApp.short_id,
                                            self.user,
                                            action='copy')

        new_web_app = copy_resource(self.resWebApp, new_web_app)

        # test the new copy is a web app
        self.assertTrue(isinstance(new_web_app, ToolResource))
        # test that added types are copied
        self.assertEqual(2, SupportedResTypes.objects.all().count())
        self.assertEqual(2, SupportedAggTypes.objects.all().count())
Exemplo n.º 2
0
 def test_update_variable_orig(self):
     self.assertEqual(len(self.refts_res.metadata.variables.all()), 0)
     resource.create_metadata_element(
             self.refts_res.short_id,
             'Variable',
             name='test variable name',
             code='test code',
             data_type='test data type',
             sample_medium='test sample medium')
     self.assertEqual(len(self.refts_res.metadata.variables.all()), 1)
     self.assertEqual(self.refts_res.metadata.variables.all()[0].name, 'test variable name')
     self.assertEqual(self.refts_res.metadata.variables.all()[0].code, 'test code')
     self.assertEqual(self.refts_res.metadata.variables.all()[0].data_type, 'test data type')
     self.assertEqual(self.refts_res.metadata.variables.all()[0].sample_medium, 'test sample medium')
     v = self.refts_res.metadata.variables.filter(name='test variable name')[0]
     resource.update_metadata_element(
             self.refts_res.short_id,
             'Variable',
             v.id,
             name='test variable name2',
             code='test code2',
             data_type='test data type2',
             sample_medium='test sample medium2')
     self.assertEqual(self.refts_res.metadata.variables.all()[0].name, 'test variable name2')
     self.assertEqual(self.refts_res.metadata.variables.all()[0].code, 'test code2')
     self.assertEqual(self.refts_res.metadata.variables.all()[0].data_type, 'test data type2')
     self.assertEqual(self.refts_res.metadata.variables.all()[0].sample_medium, 'test sample medium2')
Exemplo n.º 3
0
 def setUp(self):
     self.group, _ = Group.objects.get_or_create(name='Hydroshare Author')
     self.user = hydroshare.create_account(
             '*****@*****.**',
             username='******',
             first_name='Creator_FirstName',
             last_name='Creator_LastName',
             superuser=False,
             groups=[self.group]
         )
     self.refts_res = hydroshare.create_resource(
             resource_type='RefTimeSeries',
             owner=self.user,
             title='Test RefTS resource')
     resource.create_metadata_element(self.refts_res.short_id, 'QualityControlLevel', value='test quality level')
     resource.create_metadata_element(self.refts_res.short_id, 'ReferenceURL', value='www.example.com', type='REST')
     resource.create_metadata_element(self.refts_res.short_id, 'Method', value='test method')
     resource.create_metadata_element(
             self.refts_res.short_id,
             'Variable',
             name='test variable name',
             code='test code',
             data_type='test data type',
             sample_medium='test sample medium')
     resource.create_metadata_element(
             self.refts_res.short_id,
             'Site',
             name='test site name',
             code='test site code',
             latitude=150.15,
             longitude=150.15)
Exemplo n.º 4
0
 def test_update_site_orig(self):
     self.assertEqual(len(self.refts_res.metadata.sites.all()), 0)
     resource.create_metadata_element(
             self.refts_res.short_id,
             'Site',
             name='test site name',
             code='test site code',
             latitude=150.15,
             longitude=150.15)
     self.assertEqual(len(self.refts_res.metadata.sites.all()), 1)
     self.assertEqual(self.refts_res.metadata.sites.all()[0].name, 'test site name')
     self.assertEqual(self.refts_res.metadata.sites.all()[0].code, 'test site code')
     self.assertEqual(self.refts_res.metadata.sites.all()[0].latitude, Decimal('150.150000'))
     self.assertEqual(self.refts_res.metadata.sites.all()[0].longitude, Decimal('150.150000'))
     s = self.refts_res.metadata.sites.filter(name='test site name')[0]
     resource.update_metadata_element(
             self.refts_res.short_id,
             'Site',
             s.id,
             name='test site name2',
             code='test site code2',
             latitude=150.17,
             longitude=150.17)
     self.assertEqual(len(self.refts_res.metadata.sites.all()), 1)
     self.assertEqual(self.refts_res.metadata.sites.all()[0].name, 'test site name2')
     self.assertEqual(self.refts_res.metadata.sites.all()[0].code, 'test site code2')
     self.assertEqual(self.refts_res.metadata.sites.all()[0].latitude, Decimal('150.170000'))
     self.assertEqual(self.refts_res.metadata.sites.all()[0].longitude, Decimal('150.170000'))
Exemplo n.º 5
0
    def test_copy(self):

        # create 1 SupportedResTypes obj with required params
        resource.create_metadata_element(self.resWebApp.short_id, 'SupportedResTypes',
                                         supported_res_types=['NetcdfResource'])
        self.assertEqual(SupportedResTypes.objects.all().count(), 1)

        # set url launching pattern for aggregations
        metadata = [{'requesturlbaseaggregation': {
            'value': 'https://www.google.com?agg_path=${HS_AGG_PATH}'}}]
        self.resWebApp.metadata.update(metadata, self.user)
        resource.create_metadata_element(self.resWebApp.short_id, 'SupportedAggTypes',
                                         supported_agg_types=['GeoRasterLogicalFile'])

        self.assertEqual(1, SupportedAggTypes.objects.all().count())

        # make a new copy of web app
        new_web_app = create_empty_resource(self.resWebApp.short_id, self.user,
                                               action='copy')

        new_web_app = copy_resource(self.resWebApp, new_web_app)

        # test the new copy is a web app
        self.assertTrue(isinstance(new_web_app, ToolResource))
        # test that added types are copied
        self.assertEqual(2, SupportedResTypes.objects.all().count())
        self.assertEqual(2, SupportedAggTypes.objects.all().count())
Exemplo n.º 6
0
    def test_agg_types(self):
        # set url launching pattern for aggregations
        metadata = [{'requesturlbaseaggregation': {
            'value': 'https://www.google.com?agg_path=${HS_AGG_PATH}'}}]
        self.resWebApp.metadata.update(metadata, self.user)
        self.assertEqual(RequestUrlBaseAggregation.objects.all().count(), 1)

        # set web app to launch for geo raster
        self.resWebApp.metadata.update(metadata, self.user)
        resource.create_metadata_element(self.resWebApp.short_id, 'SupportedAggTypes',
                                         supported_agg_types=['GeoRasterLogicalFile'])

        self.assertEqual(1, SupportedAggTypes.objects.all().count())

        # add a geo raster aggregation to the resource
        open_file = open(self.test_file_path.format("small_logan.tif"), 'rb')
        resource_file_add_process(resource=self.resComposite,
                                  files=(open_file,), user=self.user)

        # setup the web app to be launched by the resource
        url = '/resource/' + self.resComposite.short_id + '/'
        request = self.factory.get(url)
        request.user = self.user

        self.assertEqual(self.resWebApp.extra_metadata, {})
        self.resWebApp.extra_metadata = {tool_app_key: 'test-app-value'}
        self.resWebApp.save()

        self.assertNotEqual(self.resWebApp.extra_metadata, {})
        self.assertEqual(self.resWebApp.extra_metadata[tool_app_key], 'test-app-value')

        self.assertEqual(self.resComposite.extra_metadata, {})
        self.resComposite.extra_metadata = {tool_app_key: 'test-app-value'}
        self.resComposite.save()

        self.assertNotEqual(self.resComposite.extra_metadata, {})
        self.assertEqual(self.resComposite.extra_metadata[tool_app_key], 'test-app-value')

        url = '/resource/' + self.resComposite.short_id + '/'
        request = self.factory.get(url)
        request.user = self.user

        # get the web tools and ensure agg_types is there
        relevant_tools = resource_level_tool_urls(self.resComposite, request)
        self.assertIsNotNone(relevant_tools, msg='relevant_tools should not be None with appkey '
                                                 'matching')
        tc = relevant_tools['resource_level_app_counter']
        self.assertEqual(0, tc)
        tl = relevant_tools['tool_list'][0]
        self.assertEqual(self.resWebApp.short_id, tl['res_id'])
        self.assertEqual('GeoRasterLogicalFile', tl['agg_types'])
        self.assertEqual('', tl['file_extensions'])

        # Remove appkey to turn off openwithlist for this resource
        self.resWebApp.extra_metadata = {}
        self.resWebApp.save()

        relevant_tools = resource_level_tool_urls(self.resComposite, request)
        self.assertIsNone(relevant_tools, msg='relevant_tools should have no approved resources')
Exemplo n.º 7
0
 def test_delete_method_orig(self):
     self.assertEqual(len(self.refts_res.metadata.methods.all()), 0)
     resource.create_metadata_element(self.refts_res.short_id, 'Method', value='test method')
     self.assertEqual(len(self.refts_res.metadata.methods.all()), 1)
     self.assertEqual(self.refts_res.metadata.methods.all()[0].value, 'test method')
     m = self.refts_res.metadata.methods.filter(value='test method')[0]
     resource.delete_metadata_element(self.refts_res.short_id, 'Method', m.id)
     self.assertEqual(len(self.refts_res.metadata.methods.all()), 0)
Exemplo n.º 8
0
 def test_delete_resource_types_orig(self):
     self.assertEqual(len(self.tool_res.metadata.res_types.all()), 0)
     resource.create_metadata_element(self.tool_res.short_id, 'ToolResourceType', tool_res_type=self.resourcetypes1)
     self.assertEqual(len(self.tool_res.metadata.res_types.all()), 1)
     self.assertEqual(self.tool_res.metadata.res_types.all()[0].tool_res_type, self.resourcetypes1)
     m = self.tool_res.metadata.res_types.filter(tool_res_type=self.resourcetypes1)[0]
     resource.delete_metadata_element(self.tool_res.short_id, 'ToolResourceType', m.id)
     self.assertEqual(len(self.tool_res.metadata.res_types.all()), 0)
Exemplo n.º 9
0
 def test_delete_url_base_orig(self):
     self.assertEqual(len(self.tool_res.metadata.url_bases.all()), 0)
     resource.create_metadata_element(self.tool_res.short_id, 'RequestUrlBase', value=self.url1)
     self.assertEqual(len(self.tool_res.metadata.url_bases.all()), 1)
     self.assertEqual(self.tool_res.metadata.url_bases.all()[0].value, self.url1)
     m = self.tool_res.metadata.url_bases.filter(value=self.url1)[0]
     resource.delete_metadata_element(self.tool_res.short_id, 'RequestUrlBase', m.id)
     self.assertEqual(len(self.tool_res.metadata.url_bases.all()), 0)
Exemplo n.º 10
0
 def test_delete_version_orig(self):
     self.assertEqual(len(self.tool_res.metadata.versions.all()), 0)
     resource.create_metadata_element(self.tool_res.short_id, 'ToolVersion', value=self.version1)
     self.assertEqual(len(self.tool_res.metadata.versions.all()), 1)
     self.assertEqual(self.tool_res.metadata.versions.all()[0].value, self.version1)
     m = self.tool_res.metadata.versions.filter(value=self.version1)[0]
     resource.delete_metadata_element(self.tool_res.short_id, 'ToolVersion', m.id)
     self.assertEqual(len(self.tool_res.metadata.versions.all()), 0)
Exemplo n.º 11
0
 def test_update_quality_control_level(self):
     self.assertEqual(len(self.refts_res.metadata.quality_levels.all()), 0)
     resource.create_metadata_element(self.refts_res.short_id, 'QualityControlLevel', value='test quality level')
     self.assertEqual(len(self.refts_res.metadata.quality_levels.all()), 1)
     self.assertEqual(self.refts_res.metadata.quality_levels.all()[0].value, 'test quality level')
     q = self.refts_res.metadata.quality_levels.filter(value='test quality level')[0]
     resource.update_metadata_element(self.refts_res.short_id, 'QualityControlLevel', q.id, value='updated value')
     self.assertEqual(self.refts_res.metadata.quality_levels.all()[0].value, 'updated value')
Exemplo n.º 12
0
 def test_delete_fee_orig(self):
     self.assertEqual(len(self.tool_res.metadata.fees.all()), 0)
     resource.create_metadata_element(self.tool_res.short_id, 'Fee', description=self.desc1, value=self.value1)
     self.assertEqual(len(self.tool_res.metadata.fees.all()), 1)
     self.assertEqual(self.tool_res.metadata.fees.all()[0].description, self.desc1)
     self.assertEqual(self.tool_res.metadata.fees.all()[0].value, self.value1)
     m = self.tool_res.metadata.fees.filter(description=self.desc1)[0]
     resource.delete_metadata_element(self.tool_res.short_id, 'Fee', m.id)
     self.assertEqual(len(self.tool_res.metadata.fees.all()), 0)
Exemplo n.º 13
0
    def test_two_authors_comma(self):
        # add a creator element
        resource.create_metadata_element(self.res.short_id, 'creator', name='Smith, John')

        citation = self.res.get_citation()
        hs_identifier = self.res.metadata.identifiers.all().filter(name="hydroShareIdentifier")[0]
        hs_url = hs_identifier.url
        hs_date = str(date.today().year)
        correct_citation = 'Creator_LastName, C., ' \
                           'J. Smith ({}). Generic resource, HydroShare, {}'.format(hs_date, hs_url)
        self.assertEqual(citation, correct_citation)
Exemplo n.º 14
0
    def test_agg_types(self):
        # set url launching pattern for aggregations
        metadata = [{'requesturlbaseaggregation': {
            'value': 'https://www.google.com?agg_path=${HS_AGG_PATH}'}}]
        self.resWebApp.metadata.update(metadata, self.user)
        self.assertEqual(RequestUrlBaseAggregation.objects.all().count(), 1)

        # set web app to launch for geo raster
        self.resWebApp.metadata.update(metadata, self.user)
        resource.create_metadata_element(self.resWebApp.short_id, 'SupportedAggTypes',
                                         supported_agg_types=['GeoRasterLogicalFile'])

        self.assertEqual(1, SupportedAggTypes.objects.all().count())

        # add a geo raster aggregation to the resource
        open_file = open(self.test_file_path.format("small_logan.tif"), 'r')
        resource_file_add_process(resource=self.resComposite,
                                  files=(open_file,), user=self.user)

        # setup the web app to be launched by the resource
        url = '/resource/' + self.resComposite.short_id + '/'
        request = self.factory.get(url)
        request.user = self.user

        self.assertEqual(self.resWebApp.extra_metadata, {})
        self.resWebApp.extra_metadata = {tool_app_key: 'test-app-value'}
        self.resWebApp.save()

        self.assertNotEqual(self.resWebApp.extra_metadata, {})
        self.assertEqual(self.resWebApp.extra_metadata[tool_app_key], 'test-app-value')

        self.assertEqual(self.resComposite.extra_metadata, {})
        self.resComposite.extra_metadata = {tool_app_key: 'test-app-value'}
        self.resComposite.save()

        self.assertNotEqual(self.resComposite.extra_metadata, {})
        self.assertEqual(self.resComposite.extra_metadata[tool_app_key], 'test-app-value')

        url = '/resource/' + self.resComposite.short_id + '/'
        request = self.factory.get(url)
        request.user = self.user

        # get the web tools and ensure agg_types is there
        relevant_tools = resource_level_tool_urls(self.resComposite, request)
        self.assertIsNotNone(relevant_tools, msg='relevant_tools should not be None with appkey '
                                                 'matching')
        tc = relevant_tools['resource_level_app_counter']
        self.assertEqual(0, tc)
        tl = relevant_tools['tool_list'][0]
        self.assertEqual(self.resWebApp.short_id, tl['res_id'])
        self.assertFalse(tl['approved'])
        self.assertTrue(tl['openwithlist'])
        self.assertEqual('GeoRasterLogicalFile', tl['agg_types'])
        self.assertEqual('', tl['file_extensions'])
Exemplo n.º 15
0
    def test_script_res_specific_metadata(self):

        #######################
        # Class: ScriptSpecificMetadata
        #######################
        # no ScriptSpecificMetadata obj
        self.assertEqual(ScriptSpecificMetadata.objects.all().count(), 0)

        # create 1 ScriptSpecificMetadata obj with required params
        resource.create_metadata_element(
            self.resScript.short_id,
            'ScriptSpecificMetadata',
            scriptLanguage='R',
            languageVersion='3.5',
            scriptVersion='1.0',
            scriptDependencies='None',
            scriptReleaseDate='2015-12-01 00:00',
            scriptCodeRepository='http://www.google.com')
        self.assertEqual(ScriptSpecificMetadata.objects.all().count(), 1)

        # may not create additional instance of ScriptSpecificMetadata
        with self.assertRaises(Exception):
            resource.create_metadata_element(
                self.resScript.short_id,
                'ScriptSpecificMetadata',
                scriptLanguage='R',
                languageVersion='3.5',
                scriptVersion='1.0',
                scriptDependencies='None',
                scriptReleaseDate='12/01/2015',
                scriptCodeRepository='http://www.google.com')

        self.assertEqual(ScriptSpecificMetadata.objects.all().count(), 1)

        # update existing meta
        resource.update_metadata_element(
            self.resScript.short_id,
            'ScriptSpecificMetadata',
            element_id=ScriptSpecificMetadata.objects.first().id,
            scriptLanguage='python',
            languageVersion='2.7')
        self.assertEqual(ScriptSpecificMetadata.objects.first().scriptLanguage,
                         'python')
        self.assertEqual(
            ScriptSpecificMetadata.objects.first().languageVersion, '2.7')

        # delete ScriptSpecificMetadata obj
        resource.delete_metadata_element(
            self.resScript.short_id,
            'ScriptSpecificMetadata',
            element_id=ScriptSpecificMetadata.objects.first().id)
        self.assertEqual(ScriptSpecificMetadata.objects.all().count(), 0)
Exemplo n.º 16
0
    def test_two_authors_multiple_first_and_last_names_no_comma(self):
        # add a creator element
        resource.create_metadata_element(self.res.short_id, 'creator',
                                         name='John Mason Jingle Smith William')

        citation = self.res.get_citation()
        hs_identifier = self.res.metadata.identifiers.all().filter(name="hydroShareIdentifier")[0]
        hs_url = hs_identifier.url
        hs_date = str(date.today().year)
        correct_citation = 'Creator_LastName, C., ' \
                           'J. M. J. S. William ' \
                           '({}). Generic resource, HydroShare, {}'.format(hs_date, hs_url)
        self.assertEqual(citation, correct_citation)
Exemplo n.º 17
0
    def test_two_authors_and_organization(self):
        # add a creator element
        resource.create_metadata_element(self.res.short_id, 'creator',
                                         name='Smith William, John Mason Jingle')
        resource.create_metadata_element(self.res.short_id, 'creator',
                                         organization='U.S. Geological Survey')

        citation = self.res.get_citation()
        hs_identifier = self.res.metadata.identifiers.all().filter(name="hydroShareIdentifier")[0]
        hs_url = hs_identifier.url
        hs_date = str(date.today().year)
        correct_citation = 'Creator_LastName, C., ' \
                           'J. M. J. Smith William, ' \
                           'U.S. Geological Survey ' \
                           '({}). Generic resource, HydroShare, {}'.format(hs_date, hs_url)
        self.assertEqual(citation, correct_citation)
Exemplo n.º 18
0
    def test_script_res_specific_metadata(self):

        #######################
        # Class: ScriptSpecificMetadata
        #######################
        # no ScriptSpecificMetadata obj
        self.assertEqual(ScriptSpecificMetadata.objects.all().count(), 0)

        # create 1 ScriptSpecificMetadata obj with required params
        resource.create_metadata_element(self.resScript.short_id, 'ScriptSpecificMetadata', scriptLanguage='R',
                                         languageVersion='3.5', scriptVersion='1.0',
                                         scriptDependencies='None', scriptReleaseDate='2015-12-01 00:00',
                                         scriptCodeRepository='http://www.google.com')
        self.assertEqual(ScriptSpecificMetadata.objects.all().count(), 1)

        # may not create additional instance of ScriptSpecificMetadata
        with self.assertRaises(Exception):
            resource.create_metadata_element(self.resScript.short_id, 'ScriptSpecificMetadata', scriptLanguage='R',
                                             languageVersion='3.5', scriptVersion='1.0',
                                             scriptDependencies='None', scriptReleaseDate='12/01/2015',
                                             scriptCodeRepository='http://www.google.com')

        self.assertEqual(ScriptSpecificMetadata.objects.all().count(), 1)

        # update existing meta
        resource.update_metadata_element(self.resScript.short_id, 'ScriptSpecificMetadata',
                                         element_id=ScriptSpecificMetadata.objects.first().id,
                                         scriptLanguage='python',
                                         languageVersion='2.7')
        self.assertEqual(ScriptSpecificMetadata.objects.first().scriptLanguage, 'python')
        self.assertEqual(ScriptSpecificMetadata.objects.first().languageVersion, '2.7')

        # delete ScriptSpecificMetadata obj
        resource.delete_metadata_element(self.resScript.short_id, 'ScriptSpecificMetadata',
                                         element_id=ScriptSpecificMetadata.objects.first().id)
        self.assertEqual(ScriptSpecificMetadata.objects.all().count(), 0)
Exemplo n.º 19
0
 def test_create_quality_control_level_duplicate(self):
     self.assertEqual(len(self.refts_res.metadata.quality_levels.all()), 0)
     self.assertRaises(ValidationError, resource.create_metadata_element(
         self.refts_res.short_id,
         'QualityControlLevel',
         value='test quality level'))
Exemplo n.º 20
0
 def test_create_quality_control_level_orig(self):
     self.assertEqual(len(self.refts_res.metadata.quality_levels.all()), 0)
     resource.create_metadata_element(self.refts_res.short_id, 'QualityControlLevel', value='test quality level')
     self.assertEqual(len(self.refts_res.metadata.quality_levels.all()), 1)
     self.assertEqual(self.refts_res.metadata.quality_levels.all()[0].value, 'test quality level')
Exemplo n.º 21
0
    def test_geo_feature_res_specific_metadata(self):

        # originalcoverage
        # no OriginalCoverage obj
        self.assertEqual(OriginalCoverage.objects.all().count(), 0)

        # create OriginalCoverage obj without a required para: southlimit
        with self.assertRaises(Exception):
            resource.create_metadata_element(self.resGeoFeature.short_id, 'originalcoverage',
                                             northlimit='1', eastlimit='2', southlimit='3')

        # no OriginalCoverage obj
        self.assertEqual(OriginalCoverage.objects.all().count(), 0)

        # create 1 OriginalCoverage obj with required para
        resource.create_metadata_element(self.resGeoFeature.short_id, 'originalcoverage',
                                         northlimit='1',  eastlimit='2',
                                         southlimit='3',  westlimit='4')
        self.assertEqual(OriginalCoverage.objects.all().count(), 1)

        # may not create any more OriginalCoverage
        with self.assertRaises(Exception):
            resource.create_metadata_element(self.resGeoFeature.short_id, 'originalcoverage',
                                             northlimit='1', eastlimit='2',
                                             southlimit='3', westlimit='4')

        self.assertEqual(OriginalCoverage.objects.all().count(), 1)
        # update existing meta
        resource.update_metadata_element(self.resGeoFeature.short_id, 'originalcoverage',
                                         element_id=OriginalCoverage.objects.first().id,
                                         northlimit='11',  eastlimit='22',
                                         southlimit='33',  westlimit='44',
                                         projection_string='projection_string1',
                                         projection_name='projection_name1',
                                         datum='datum1', unit='unit1')
        self.assertEqual(OriginalCoverage.objects.first().unit, 'unit1')

        # delete OriginalCoverage obj
        resource.delete_metadata_element(self.resGeoFeature.short_id, 'originalcoverage',
                                         element_id=OriginalCoverage.objects.first().id)
        self.assertEqual(OriginalCoverage.objects.all().count(), 0)

        # GeometryInformation
        # no GeometryInformation obj
        self.assertEqual(GeometryInformation.objects.all().count(), 0)

        # no GeometryInformation obj
        self.assertEqual(GeometryInformation.objects.all().count(), 0)

        # create 1 GeometryInformation obj with required para
        resource.create_metadata_element(self.resGeoFeature.short_id, 'GeometryInformation',
                                         featureCount='1', geometryType='Polygon_test')
        self.assertEqual(GeometryInformation.objects.all().count(), 1)

        # may not create any more GeometryInformation
        with self.assertRaises(Exception):
            resource.create_metadata_element(self.resGeoFeature.short_id, 'GeometryInformation',
                                             featureCount='1', geometryType='Polygon_test')

        # update existing meta
        resource.update_metadata_element(self.resGeoFeature.short_id, 'GeometryInformation',
                                         element_id=GeometryInformation.objects.first().id,
                                         featureCount='2', geometryType='Point_test')
        self.assertEqual(GeometryInformation.objects.first().geometryType, 'Point_test')
        self.assertEqual(GeometryInformation.objects.first().featureCount, 2)

        # delete GeometryInformation obj
        resource.delete_metadata_element(self.resGeoFeature.short_id, 'GeometryInformation',
                                         element_id=GeometryInformation.objects.first().id)
        self.assertEqual(GeometryInformation.objects.all().count(), 0)

        # FieldInformation
        # no FieldInformation obj
        self.assertEqual(FieldInformation.objects.all().count(), 0)

        # no FieldInformation obj
        self.assertEqual(FieldInformation.objects.all().count(), 0)

        # create 1 FieldInformation obj with required para
        resource.create_metadata_element(self.resGeoFeature.short_id, 'FieldInformation',
                                         fieldName='fieldName1', fieldType='fieldType1')
        self.assertEqual(FieldInformation.objects.all().count(), 1)

        resource.create_metadata_element(self.resGeoFeature.short_id, 'FieldInformation',
                                         fieldName='fieldName2', fieldType='fieldType2')
        self.assertEqual(FieldInformation.objects.all().count(), 2)

        # update existing meta
        field_info_obj_list = FieldInformation.objects.filter(fieldName='fieldName1')
        self.assertEqual(field_info_obj_list.count(), 1)
        field_1_ele_id_old = field_info_obj_list[0].id
        resource.update_metadata_element(self.resGeoFeature.short_id, 'FieldInformation',
                                         element_id=field_1_ele_id_old,
                                         fieldName='fieldName1_new',
                                         fieldType='fieldType1_new')

        field_info_obj_list = FieldInformation.objects.filter(fieldName='fieldName1_new')
        self.assertEqual(field_info_obj_list.count(), 1)
        field_1_ele_id_new = field_info_obj_list[0].id
        # ele_id should not change
        self.assertEqual(field_1_ele_id_new, field_1_ele_id_old)
        # old value is gone
        field_info_obj_list = FieldInformation.objects.filter(fieldName='fieldName1')
        self.assertEqual(field_info_obj_list.count(), 0)

        field_info_obj_list = FieldInformation.objects.filter(fieldName='fieldName2')
        self.assertEqual(field_info_obj_list.count(), 1)
        field_2_ele_id_old = field_info_obj_list[0].id

        self.assertEqual(FieldInformation.objects.all().count(), 2)

        # delete FieldInformation obj
        resource.delete_metadata_element(self.resGeoFeature.short_id, 'FieldInformation',
                                         element_id=field_1_ele_id_old)
        self.assertEqual(FieldInformation.objects.all().count(), 1)

        field_info_obj_list = FieldInformation.objects.filter(fieldName='fieldName1_new')
        self.assertEqual(field_info_obj_list.count(), 0)

        field_info_obj_list = FieldInformation.objects.filter(fieldName='fieldName2')
        self.assertEqual(field_info_obj_list.count(), 1)

        resource.delete_metadata_element(self.resGeoFeature.short_id, 'FieldInformation',
                                         element_id=field_2_ele_id_old)
        self.assertEqual(FieldInformation.objects.all().count(), 0)
        self.resGeoFeature.delete()
Exemplo n.º 22
0
    def test_geo_feature_basic_metadata(self):
        # add another creator with all sub_elements
        cr_name = 'Creator A'
        cr_des = 'http://hydroshare.org/user/001'
        cr_org = "BYU"
        cr_email = '*****@*****.**'
        cr_address = "Provo, UT, USA"
        cr_phone = '123-456-7890'
        cr_homepage = 'http://home.byu.edu/'
        resource.create_metadata_element(self.resGeoFeature.short_id,
                                         'creator',
                                         name=cr_name,
                                         description=cr_des,
                                         organization=cr_org,
                                         email=cr_email,
                                         address=cr_address,
                                         phone=cr_phone,
                                         homepage=cr_homepage,
                                         identifiers={'ORCID': 'https://orcid.org/john',
                                                      'ResearchGateID':
                                                          'https://www.researchgate.net/john'})

        # add another creator with only the name
        resource.create_metadata_element(self.resGeoFeature.short_id, 'creator', name='Creator B')

        # test adding a contributor with all sub_elements
        con_name = 'Contributor A'
        con_des = 'http://hydroshare.org/user/002'
        con_org = "BYU"
        con_email = '*****@*****.**'
        con_address = "Provo, UT, USA"
        con_phone = '123-456-7890'
        con_homepage = 'http://usu.edu/homepage/009'
        resource.create_metadata_element(self.resGeoFeature.short_id,
                                         'contributor',
                                         name=con_name,
                                         description=con_des,
                                         organization=con_org,
                                         email=con_email,
                                         address=con_address,
                                         phone=con_phone,
                                         homepage=con_homepage,
                                         identifiers={'ORCID': 'https://orcid.org/john',
                                                      'ResearchGateID':
                                                          'https://www.researchgate.net/john'})

        # add another creator with only the name
        resource.create_metadata_element(self.resGeoFeature.short_id,
                                         'contributor', name='Contributor B')

        # add a period type coverage
        value_dict = {'name': 'Name for period coverage', 'start': '1/1/2015', 'end': '12/31/2015'}
        resource.create_metadata_element(self.resGeoFeature.short_id,
                                         'coverage',
                                         type='period',
                                         value=value_dict)

        # add a point type coverage
        value_dict = {'name': 'Name for box coverage',
                      'northlimit': '80', 'eastlimit': '130',
                      'southlimit': '70', 'westlimit': '120'}

        value_dict["projection"] = "WGS 84 EPSG:4326"
        value_dict["units"] = "Decimal degrees"
        resource.create_metadata_element(self.resGeoFeature.short_id,
                                         'coverage', type='box', value=value_dict)

        # add date of type 'valid'
        resource.create_metadata_element(self.resGeoFeature.short_id,
                                         'date',
                                         type='valid',
                                         start_date=parser.parse('1/1/2012'),
                                         end_date=parser.parse('12/31/2012'))

        # add a format element
        format = 'shp'
        resource.create_metadata_element(self.resGeoFeature.short_id, 'format', value=format)

        # add a relation element of uri type
        resource.create_metadata_element(self.resGeoFeature.short_id, 'relation', type='isPartOf',
                                         value='http://hydroshare.org/resource/001')

        # add another relation element of non-uri type
        resource.create_metadata_element(self.resGeoFeature.short_id, 'relation', type='isDataFor',
                                         value='This resource is for another resource')

        # add a source element of uri type
        resource.create_metadata_element(self.resGeoFeature.short_id, 'source',
                                         derived_from='http://hydroshare.org/resource/0002')

        # add a subject element
        resource.create_metadata_element(self.resGeoFeature.short_id, 'subject', value='sub-1')

        # add another subject element
        resource.create_metadata_element(self.resGeoFeature.short_id, 'subject', value='sub-2')
        self.resGeoFeature.delete()
Exemplo n.º 23
0
    def test_metadata(self):
        # add a type element
        resource.create_metadata_element(self.resTimeSeries.short_id,
                                         'type',
                                         url="http://hydroshare.org/netcdf")

        # add another creator with all sub_elements
        cr_name = 'Mike Sundar'
        cr_des = 'http://hydroshare.org/user/001'
        cr_org = "USU"
        cr_email = '*****@*****.**'
        cr_address = "11 River Drive, Logan UT-84321, USA"
        cr_phone = '435-567-0989'
        cr_homepage = 'http://usu.edu/homepage/001'
        cr_res_id = 'http://research.org/001'
        cr_res_gate_id = 'http://research-gate.org/001'
        resource.create_metadata_element(self.resTimeSeries.short_id,
                                         'creator',
                                         name=cr_name,
                                         description=cr_des,
                                         organization=cr_org,
                                         email=cr_email,
                                         address=cr_address,
                                         phone=cr_phone,
                                         homepage=cr_homepage,
                                         researcherID=cr_res_id,
                                         researchGateID=cr_res_gate_id)

        # add another creator with only the name
        resource.create_metadata_element(self.resTimeSeries.short_id,
                                         'creator',
                                         name='Lisa Holley')

        #test adding a contributor with all sub_elements
        con_name = 'Sujan Peterson'
        con_des = 'http://hydroshare.org/user/002'
        con_org = "USU"
        con_email = '*****@*****.**'
        con_address = "101 Center St, Logan UT-84321, USA"
        con_phone = '435-567-3245'
        con_homepage = 'http://usu.edu/homepage/009'
        con_res_id = 'http://research.org/009'
        con_res_gate_id = 'http://research-gate.org/009'
        resource.create_metadata_element(self.resTimeSeries.short_id,
                                         'contributor',
                                         name=con_name,
                                         description=con_des,
                                         organization=con_org,
                                         email=con_email,
                                         address=con_address,
                                         phone=con_phone,
                                         homepage=con_homepage,
                                         researcherID=con_res_id,
                                         researchGateID=con_res_gate_id)

        # add another creator with only the name
        resource.create_metadata_element(self.resTimeSeries.short_id,
                                         'contributor',
                                         name='Andrew Smith')

        # add a period type coverage
        # add a period type coverage
        value_dict = {
            'name': 'Name for period coverage',
            'start': '1/1/2000',
            'end': '12/12/2012'
        }
        resource.create_metadata_element(self.resTimeSeries.short_id,
                                         'coverage',
                                         type='period',
                                         value=value_dict)

        # add a point type coverage
        value_dict = {
            'name': 'Name for point coverage',
            'east': '56.45678',
            'north': '12.6789'
        }
        resource.create_metadata_element(self.resTimeSeries.short_id,
                                         'coverage',
                                         type='point',
                                         value=value_dict)

        # add date of type 'valid'
        resource.create_metadata_element(self.resTimeSeries.short_id,
                                         'date',
                                         type='valid',
                                         start_date='8/10/2011',
                                         end_date='8/11/2012')

        # add a format element
        format_nc = 'netcdf'
        resource.create_metadata_element(self.resTimeSeries.short_id,
                                         'format',
                                         value=format_nc)

        # add 'DOI' identifier
        #resource.create_metadata_element(self.resTimeSeries.short_id,'identifier', name='DOI', url="http://dx.doi.org/001")

        # add a language element
        resource.create_metadata_element(self.resTimeSeries.short_id,
                                         'language',
                                         code='eng')

        # add 'Publisher' element
        original_file_name = 'original.txt'
        original_file = open(original_file_name, 'w')
        original_file.write("original text")
        original_file.close()

        original_file = open(original_file_name, 'r')
        # add the file to the resource
        hydroshare.add_resource_files(self.resTimeSeries.short_id,
                                      original_file)
        resource.create_metadata_element(self.resTimeSeries.short_id,
                                         'publisher',
                                         name="HydroShare",
                                         url="http://hydroshare.org")

        # add a relation element of uri type
        resource.create_metadata_element(
            self.resTimeSeries.short_id,
            'relation',
            type='isPartOf',
            value='http://hydroshare.org/resource/001')

        # add another relation element of non-uri type
        resource.create_metadata_element(
            self.resTimeSeries.short_id,
            'relation',
            type='isDataFor',
            value='This resource is for another resource')

        # add a source element of uri type
        resource.create_metadata_element(
            self.resTimeSeries.short_id,
            'source',
            derived_from='http://hydroshare.org/resource/0002')

        # add a rights element
        resource.create_metadata_element(
            self.resTimeSeries.short_id,
            'rights',
            statement='This is the rights statement for this resource',
            url='http://rights.ord/001')

        # add a subject element
        resource.create_metadata_element(self.resTimeSeries.short_id,
                                         'subject',
                                         value='sub-1')

        # add another subject element
        resource.create_metadata_element(self.resTimeSeries.short_id,
                                         'subject',
                                         value='sub-2')

        # add time series specific metadata elements
        self.resTimeSeries.metadata.create_element(
            'site',
            site_code='LR_WaterLab_AA',
            site_name='Logan River at the Utah Water Research Laboratory '
            'west bridge',
            elevation_m=1414,
            elevation_datum='EGM96',
            site_type='Stream')

        self.resTimeSeries.metadata.create_element(
            'variable',
            variable_code='ODO',
            variable_name='Oxygen, dissolved',
            variable_type='Concentration',
            no_data_value=-9999,
            variable_definition=
            'Concentration of oxygen gas dissolved in water.',
            speciation='Not Applicable')

        self.resTimeSeries.metadata.create_element(
            'method',
            method_code=59,
            method_name='Optical DO',
            method_type='Instrument deployment',
            method_description='Dissolved oxygen concentration measured '
            'optically using a YSI EXO multi-parameter water '
            'quality sonde.',
            method_link='http://www.exowater.com')

        exp_text = """Raw and unprocessed data and data products that have not undergone quality control.
        Depending on the variable, data type, and data transmission system, raw data may be available within seconds
        or minutes after the measurements have been made. Examples include real time precipitation, streamflow and
        water quality measurements."""
        self.resTimeSeries.metadata.create_element('processinglevel',
                                                   processing_level_code=0,
                                                   definition='Raw data',
                                                   explanation=exp_text)

        self.resTimeSeries.metadata.create_element(
            'timeseriesresult',
            units_type='Concentration',
            units_name='milligrams per liter',
            units_abbreviation='mg/L',
            status='Complete',
            sample_medium='Surface water',
            value_count=11283,
            aggregation_statistics="Average")

        print self.resTimeSeries.metadata.get_xml()

        print(bad)
Exemplo n.º 24
0
    def test_geo_feature_basic_metadata(self):
        # add another creator with all sub_elements
        cr_name = 'Creator A'
        cr_des = 'http://hydroshare.org/user/001'
        cr_org = "BYU"
        cr_email = '*****@*****.**'
        cr_address = "Provo, UT, USA"
        cr_phone = '123-456-7890'
        cr_homepage = 'http://home.byu.edu/'
        cr_res_id = 'http://research.org/001'
        cr_res_gate_id = 'http://research-gate.org/001'
        resource.create_metadata_element(self.resGeoFeature.short_id,
                                         'creator',
                                         name=cr_name,
                                         description=cr_des,
                                         organization=cr_org,
                                         email=cr_email,
                                         address=cr_address,
                                         phone=cr_phone,
                                         homepage=cr_homepage,
                                         profile_links=[{'type': 'researchID',
                                                         'url': cr_res_id},
                                                        {'type': 'researchGateID',
                                                         'url': cr_res_gate_id}])

        # add another creator with only the name
        resource.create_metadata_element(self.resGeoFeature.short_id, 'creator', name='Creator B')

        # test adding a contributor with all sub_elements
        con_name = 'Contributor A'
        con_des = 'http://hydroshare.org/user/002'
        con_org = "BYU"
        con_email = '*****@*****.**'
        con_address = "Provo, UT, USA"
        con_phone = '123-456-7890'
        con_homepage = 'http://usu.edu/homepage/009'
        con_res_id = 'http://research.org/009'
        con_res_gate_id = 'http://research-gate.org/009'
        resource.create_metadata_element(self.resGeoFeature.short_id,
                                         'contributor',
                                         name=con_name,
                                         description=con_des,
                                         organization=con_org,
                                         email=con_email,
                                         address=con_address,
                                         phone=con_phone,
                                         homepage=con_homepage,
                                         profile_links=[{'type': 'researchID',
                                                         'url': con_res_id},
                                                        {'type': 'researchGateID',
                                                         'url': con_res_gate_id}])

        # add another creator with only the name
        resource.create_metadata_element(self.resGeoFeature.short_id,
                                         'contributor', name='Contributor B')

        # add a period type coverage
        value_dict = {'name': 'Name for period coverage', 'start': '1/1/2015', 'end': '12/31/2015'}
        resource.create_metadata_element(self.resGeoFeature.short_id,
                                         'coverage',
                                         type='period',
                                         value=value_dict)

        # add a point type coverage
        value_dict = {'name': 'Name for box coverage',
                      'northlimit': '80', 'eastlimit': '130',
                      'southlimit': '70', 'westlimit': '120'}

        value_dict["projection"] = "WGS 84 EPSG:4326"
        value_dict["units"] = "Decimal degrees"
        resource.create_metadata_element(self.resGeoFeature.short_id,
                                         'coverage', type='box', value=value_dict)

        # add date of type 'valid'
        resource.create_metadata_element(self.resGeoFeature.short_id,
                                         'date',
                                         type='valid',
                                         start_date=parser.parse('1/1/2012'),
                                         end_date=parser.parse('12/31/2012'))

        # add a format element
        format = 'shp'
        resource.create_metadata_element(self.resGeoFeature.short_id, 'format', value=format)

        # add a relation element of uri type
        resource.create_metadata_element(self.resGeoFeature.short_id, 'relation', type='isPartOf',
                                         value='http://hydroshare.org/resource/001')

        # add another relation element of non-uri type
        resource.create_metadata_element(self.resGeoFeature.short_id, 'relation', type='isDataFor',
                                         value='This resource is for another resource')

        # add a source element of uri type
        resource.create_metadata_element(self.resGeoFeature.short_id, 'source',
                                         derived_from='http://hydroshare.org/resource/0002')

        # add a subject element
        resource.create_metadata_element(self.resGeoFeature.short_id, 'subject', value='sub-1')

        # add another subject element
        resource.create_metadata_element(self.resGeoFeature.short_id, 'subject', value='sub-2')
        self.resGeoFeature.delete()
Exemplo n.º 25
0
    def test_geo_feature_res_specific_metadata(self):

        # originalcoverage
        # no OriginalCoverage obj
        self.assertEqual(OriginalCoverage.objects.all().count(), 0)

        # create OriginalCoverage obj without a required para: southlimit
        with self.assertRaises(Exception):
            resource.create_metadata_element(self.resGeoFeature.short_id, 'originalcoverage',
                                             northlimit='1', eastlimit='2', southlimit='3')

        # no OriginalCoverage obj
        self.assertEqual(OriginalCoverage.objects.all().count(), 0)

        # create 1 OriginalCoverage obj with required para
        resource.create_metadata_element(self.resGeoFeature.short_id, 'originalcoverage',
                                         northlimit='1',  eastlimit='2',
                                         southlimit='3',  westlimit='4')
        self.assertEqual(OriginalCoverage.objects.all().count(), 1)

        # may not create any more OriginalCoverage
        with self.assertRaises(Exception):
            resource.create_metadata_element(self.resGeoFeature.short_id, 'originalcoverage',
                                             northlimit='1', eastlimit='2',
                                             southlimit='3', westlimit='4')

        self.assertEqual(OriginalCoverage.objects.all().count(), 1)
        # update existing meta
        resource.update_metadata_element(self.resGeoFeature.short_id, 'originalcoverage',
                                         element_id=OriginalCoverage.objects.first().id,
                                         northlimit='11',  eastlimit='22',
                                         southlimit='33',  westlimit='44',
                                         projection_string='projection_string1',
                                         projection_name='projection_name1',
                                         datum='datum1', unit='unit1')
        self.assertEqual(OriginalCoverage.objects.first().unit, 'unit1')

        # delete OriginalCoverage obj
        resource.delete_metadata_element(self.resGeoFeature.short_id, 'originalcoverage',
                                         element_id=OriginalCoverage.objects.first().id)
        self.assertEqual(OriginalCoverage.objects.all().count(), 0)

        # GeometryInformation
        # no GeometryInformation obj
        self.assertEqual(GeometryInformation.objects.all().count(), 0)

        # no GeometryInformation obj
        self.assertEqual(GeometryInformation.objects.all().count(), 0)

        # create 1 GeometryInformation obj with required para
        resource.create_metadata_element(self.resGeoFeature.short_id, 'GeometryInformation',
                                         featureCount='1', geometryType='Polygon_test')
        self.assertEqual(GeometryInformation.objects.all().count(), 1)

        # may not create any more GeometryInformation
        with self.assertRaises(Exception):
            resource.create_metadata_element(self.resGeoFeature.short_id, 'GeometryInformation',
                                             featureCount='1', geometryType='Polygon_test')

        # update existing meta
        resource.update_metadata_element(self.resGeoFeature.short_id, 'GeometryInformation',
                                         element_id=GeometryInformation.objects.first().id,
                                         featureCount='2', geometryType='Point_test')
        self.assertEqual(GeometryInformation.objects.first().geometryType, 'Point_test')
        self.assertEqual(GeometryInformation.objects.first().featureCount, 2)

        # delete GeometryInformation obj
        resource.delete_metadata_element(self.resGeoFeature.short_id, 'GeometryInformation',
                                         element_id=GeometryInformation.objects.first().id)
        self.assertEqual(GeometryInformation.objects.all().count(), 0)

        # FieldInformation
        # no FieldInformation obj
        self.assertEqual(FieldInformation.objects.all().count(), 0)

        # no FieldInformation obj
        self.assertEqual(FieldInformation.objects.all().count(), 0)

        # create 1 FieldInformation obj with required para
        resource.create_metadata_element(self.resGeoFeature.short_id, 'FieldInformation',
                                         fieldName='fieldName1', fieldType='fieldType1')
        self.assertEqual(FieldInformation.objects.all().count(), 1)

        resource.create_metadata_element(self.resGeoFeature.short_id, 'FieldInformation',
                                         fieldName='fieldName2', fieldType='fieldType2')
        self.assertEqual(FieldInformation.objects.all().count(), 2)

        # update existing meta
        field_info_obj_list = FieldInformation.objects.filter(fieldName='fieldName1')
        self.assertEqual(field_info_obj_list.count(), 1)
        field_1_ele_id_old = field_info_obj_list[0].id
        resource.update_metadata_element(self.resGeoFeature.short_id, 'FieldInformation',
                                         element_id=field_1_ele_id_old,
                                         fieldName='fieldName1_new',
                                         fieldType='fieldType1_new')

        field_info_obj_list = FieldInformation.objects.filter(fieldName='fieldName1_new')
        self.assertEqual(field_info_obj_list.count(), 1)
        field_1_ele_id_new = field_info_obj_list[0].id
        # ele_id should not change
        self.assertEqual(field_1_ele_id_new, field_1_ele_id_old)
        # old value is gone
        field_info_obj_list = FieldInformation.objects.filter(fieldName='fieldName1')
        self.assertEqual(field_info_obj_list.count(), 0)

        field_info_obj_list = FieldInformation.objects.filter(fieldName='fieldName2')
        self.assertEqual(field_info_obj_list.count(), 1)
        field_2_ele_id_old = field_info_obj_list[0].id

        self.assertEqual(FieldInformation.objects.all().count(), 2)

        # delete FieldInformation obj
        resource.delete_metadata_element(self.resGeoFeature.short_id, 'FieldInformation',
                                         element_id=field_1_ele_id_old)
        self.assertEqual(FieldInformation.objects.all().count(), 1)

        field_info_obj_list = FieldInformation.objects.filter(fieldName='fieldName1_new')
        self.assertEqual(field_info_obj_list.count(), 0)

        field_info_obj_list = FieldInformation.objects.filter(fieldName='fieldName2')
        self.assertEqual(field_info_obj_list.count(), 1)

        resource.delete_metadata_element(self.resGeoFeature.short_id, 'FieldInformation',
                                         element_id=field_2_ele_id_old)
        self.assertEqual(FieldInformation.objects.all().count(), 0)
        self.resGeoFeature.delete()
Exemplo n.º 26
0
    def test_web_app_res_specific_metadata(self):

        # Class: RequestUrlBase
        # no RequestUrlBase obj
        self.assertEqual(RequestUrlBase.objects.all().count(), 0)

        # create 1 RequestUrlBase obj with required params
        resource.create_metadata_element(self.resWebApp.short_id,
                                         'RequestUrlBase',
                                         value='https://www.google.com')
        self.assertEqual(RequestUrlBase.objects.all().count(), 1)

        # may not create additional instance of RequestUrlBase
        with self.assertRaises(Exception):
            resource.create_metadata_element(self.resWebApp.short_id,
                                             'RequestUrlBase',
                                             value='https://www.facebook.com')

        self.assertEqual(RequestUrlBase.objects.all().count(), 1)

        # update existing meta
        resource.update_metadata_element(
            self.resWebApp.short_id,
            'RequestUrlBase',
            element_id=RequestUrlBase.objects.first().id,
            value='https://www.yahoo.com')
        self.assertEqual(RequestUrlBase.objects.first().value,
                         'https://www.yahoo.com')

        # delete RequestUrlBase obj
        resource.delete_metadata_element(
            self.resWebApp.short_id,
            'RequestUrlBase',
            element_id=RequestUrlBase.objects.first().id)
        self.assertEqual(RequestUrlBase.objects.all().count(), 0)

        # Class: ToolVersion
        # verify no ToolVersion obj
        self.assertEqual(ToolVersion.objects.all().count(), 0)

        # no ToolVersion obj
        self.assertEqual(ToolVersion.objects.all().count(), 0)

        # create 1 ToolVersion obj with required params
        resource.create_metadata_element(self.resWebApp.short_id,
                                         'ToolVersion',
                                         value='1.0')
        self.assertEqual(ToolVersion.objects.all().count(), 1)

        # may not create additional instance of ToolVersion
        with self.assertRaises(Exception):
            resource.create_metadata_element(self.resWebApp.short_id,
                                             'ToolVersion',
                                             value='2.0')
        self.assertEqual(ToolVersion.objects.all().count(), 1)

        # update existing meta
        resource.update_metadata_element(
            self.resWebApp.short_id,
            'ToolVersion',
            element_id=ToolVersion.objects.first().id,
            value='3.0')
        self.assertEqual(ToolVersion.objects.first().value, '3.0')

        # delete ToolVersion obj
        resource.delete_metadata_element(
            self.resWebApp.short_id,
            'ToolVersion',
            element_id=ToolVersion.objects.first().id)
        self.assertEqual(ToolVersion.objects.all().count(), 0)

        # Class: SupportedResTypes
        # no SupportedResTypes obj
        self.assertEqual(SupportedResTypes.objects.all().count(), 0)

        # create 2 SupportedResTypes obj with required params
        resource.create_metadata_element(
            self.resWebApp.short_id,
            'SupportedResTypes',
            supported_res_types=['NetcdfResource'])
        resource.create_metadata_element(
            self.resWebApp.short_id,
            'SupportedResTypes',
            supported_res_types=['NetcdfResource'])
        self.assertEqual(SupportedResTypes.objects.all().count(), 2)

        # update existing meta
        resource.update_metadata_element(
            self.resWebApp.short_id,
            'SupportedResTypes',
            element_id=SupportedResTypes.objects.first().id,
            supported_res_types=['TimeSeriesResource'])
        self.assertEqual(
            SupportedResTypes.objects.first().supported_res_types.all()
            [0].description, 'TimeSeriesResource')

        # try to delete 1st SupportedResTypes obj
        with self.assertRaises(Exception):
            resource.delete_metadata_element(
                self.resWebApp.short_id,
                'SupportedResTypes',
                element_id=SupportedResTypes.objects.first().id)
        self.assertEqual(SupportedResTypes.objects.all().count(), 2)

        # Class: ToolIcon
        # verify no ToolIcon obj
        self.assertEqual(ToolIcon.objects.all().count(), 0)

        # no ToolIcon obj
        self.assertEqual(ToolIcon.objects.all().count(), 0)

        # create 1 ToolIcon obj with required params
        resource.create_metadata_element(
            self.resWebApp.short_id,
            'ToolIcon',
            value='https://www.hydroshare.org/static/img/logo-sm.png')
        self.assertEqual(ToolIcon.objects.all().count(), 1)

        # may not create additional instance of ToolIcon
        with self.assertRaises(Exception):
            resource.\
                create_metadata_element(self.resWebApp.short_id,
                                        'ToolIcon',
                                        value='https://www.hydroshare.org/static/img/logo-sm.png')
        self.assertEqual(ToolIcon.objects.all().count(), 1)

        # update existing meta
        resource.\
            update_metadata_element(self.resWebApp.short_id, 'ToolIcon',
                                    element_id=ToolIcon.objects.first().id,
                                    value='https://www.hydroshare.org/static/img/logo-sm.png')
        self.assertEqual(ToolIcon.objects.first().value,
                         'https://www.hydroshare.org/static/img/logo-sm.png')

        # delete ToolIcon obj
        resource.delete_metadata_element(
            self.resWebApp.short_id,
            'ToolIcon',
            element_id=ToolIcon.objects.first().id)
        self.assertEqual(ToolIcon.objects.all().count(), 0)

        # Class: AppHomePageUrl
        # verify no AppHomePageUrl obj
        self.assertEqual(AppHomePageUrl.objects.all().count(), 0)

        # create 1 AppHomePageUrl obj with required params
        resource.create_metadata_element(self.resWebApp.short_id,
                                         'AppHomePageUrl',
                                         value='https://my_web_app.com')
        self.assertEqual(AppHomePageUrl.objects.all().count(), 1)

        # may not create additional instance of AppHomePageUrl
        with self.assertRaises(Exception):
            resource.create_metadata_element(self.resWebApp.short_id,
                                             'AppHomePageUrl',
                                             value='https://my_web_app_2.com')
        self.assertEqual(AppHomePageUrl.objects.all().count(), 1)

        # update existing meta
        resource.update_metadata_element(
            self.resWebApp.short_id,
            'AppHomePageUrl',
            element_id=AppHomePageUrl.objects.first().id,
            value='http://my_web_app_3.com')
        self.assertEqual(AppHomePageUrl.objects.first().value,
                         'http://my_web_app_3.com')

        # delete AppHomePageUrl obj
        resource.delete_metadata_element(
            self.resWebApp.short_id,
            'AppHomePageUrl',
            element_id=AppHomePageUrl.objects.first().id)
        self.assertEqual(AppHomePageUrl.objects.all().count(), 0)
Exemplo n.º 27
0
    def test_netcdf_metadata(self):
        # add a type element
        resource.create_metadata_element(self.resNetCDF.short_id,
                                         'type',
                                         url="http://hydroshare.org/netcdf")

        # add another creator with all sub_elements
        cr_name = 'Mike Sundar'
        cr_des = 'http://hydroshare.org/user/001'
        cr_org = "USU"
        cr_email = '*****@*****.**'
        cr_address = "11 River Drive, Logan UT-84321, USA"
        cr_phone = '435-567-0989'
        cr_homepage = 'http://usu.edu/homepage/001'
        cr_res_id = 'http://research.org/001'
        cr_res_gate_id = 'http://research-gate.org/001'
        resource.create_metadata_element(self.resNetCDF.short_id,
                                         'creator',
                                         name=cr_name,
                                         description=cr_des,
                                         organization=cr_org,
                                         email=cr_email,
                                         address=cr_address,
                                         phone=cr_phone,
                                         homepage=cr_homepage,
                                         researcherID=cr_res_id,
                                         researchGateID=cr_res_gate_id)

        # add another creator with only the name
        resource.create_metadata_element(self.resNetCDF.short_id,
                                         'creator',
                                         name='Lisa Holley')

        #test adding a contributor with all sub_elements
        con_name = 'Sujan Peterson'
        con_des = 'http://hydroshare.org/user/002'
        con_org = "USU"
        con_email = '*****@*****.**'
        con_address = "101 Center St, Logan UT-84321, USA"
        con_phone = '435-567-3245'
        con_homepage = 'http://usu.edu/homepage/009'
        con_res_id = 'http://research.org/009'
        con_res_gate_id = 'http://research-gate.org/009'
        resource.create_metadata_element(self.resNetCDF.short_id,
                                         'contributor',
                                         name=con_name,
                                         description=con_des,
                                         organization=con_org,
                                         email=con_email,
                                         address=con_address,
                                         phone=con_phone,
                                         homepage=con_homepage,
                                         researcherID=con_res_id,
                                         researchGateID=con_res_gate_id)

        # add another creator with only the name
        resource.create_metadata_element(self.resNetCDF.short_id,
                                         'contributor',
                                         name='Andrew Smith')

        # add a period type coverage
        # add a period type coverage
        value_dict = {
            'name': 'Name for period coverage',
            'start': '1/1/2000',
            'end': '12/12/2012'
        }
        resource.create_metadata_element(self.resNetCDF.short_id,
                                         'coverage',
                                         type='period',
                                         value=value_dict)

        # add a point type coverage
        value_dict = {
            'name': 'Name for point coverage',
            'east': '56.45678',
            'north': '12.6789'
        }
        resource.create_metadata_element(self.resNetCDF.short_id,
                                         'coverage',
                                         type='point',
                                         value=value_dict)

        # add date of type 'valid'
        resource.create_metadata_element(self.resNetCDF.short_id,
                                         'date',
                                         type='valid',
                                         start_date='8/10/2011',
                                         end_date='8/11/2012')

        # add a format element
        format_nc = 'netcdf'
        resource.create_metadata_element(self.resNetCDF.short_id,
                                         'format',
                                         value=format_nc)

        # add 'DOI' identifier
        #resource.create_metadata_element(self.resNetCDF.short_id,'identifier', name='DOI', url="http://dx.doi.org/001")

        # add a language element
        resource.create_metadata_element(self.resNetCDF.short_id,
                                         'language',
                                         code='eng')

        # add 'Publisher' element
        original_file_name = 'original.txt'
        original_file = open(original_file_name, 'w')
        original_file.write("original text")
        original_file.close()

        original_file = open(original_file_name, 'r')
        # add the file to the resource
        hydroshare.add_resource_files(self.resNetCDF.short_id, original_file)
        resource.create_metadata_element(self.resNetCDF.short_id,
                                         'publisher',
                                         name="HydroShare",
                                         url="http://hydroshare.org")

        # add a relation element of uri type
        resource.create_metadata_element(
            self.resNetCDF.short_id,
            'relation',
            type='isPartOf',
            value='http://hydroshare.org/resource/001')

        # add another relation element of non-uri type
        resource.create_metadata_element(
            self.resNetCDF.short_id,
            'relation',
            type='isDataFor',
            value='This resource is for another resource')

        # add a source element of uri type
        resource.create_metadata_element(
            self.resNetCDF.short_id,
            'source',
            derived_from='http://hydroshare.org/resource/0002')

        # add a rights element
        resource.create_metadata_element(
            self.resNetCDF.short_id,
            'rights',
            statement='This is the rights statement for this resource',
            url='http://rights.ord/001')

        # add a subject element
        resource.create_metadata_element(self.resNetCDF.short_id,
                                         'subject',
                                         value='sub-1')

        # add another subject element
        resource.create_metadata_element(self.resNetCDF.short_id,
                                         'subject',
                                         value='sub-2')

        # add a netcdf specific element (variable)
        resource.create_metadata_element(self.resNetCDF.short_id,
                                         'variable',
                                         name='temp',
                                         unit='deg C',
                                         type='float',
                                         shape='shape_unknown')

        print self.resNetCDF.metadata.get_xml()

        print(bad)
Exemplo n.º 28
0
    def test_web_app_res_specific_metadata(self):

        # Class: RequestUrlBase
        # no RequestUrlBase obj
        self.assertEqual(RequestUrlBase.objects.all().count(), 0)

        # create 1 RequestUrlBase obj with required params
        resource.create_metadata_element(self.resWebApp.short_id,
                                         'RequestUrlBase',
                                         value='https://www.google.com')
        self.assertEqual(RequestUrlBase.objects.all().count(), 1)

        # may not create additional instance of RequestUrlBase
        with self.assertRaises(Exception):
            resource.create_metadata_element(self.resWebApp.short_id, 'RequestUrlBase',
                                             value='https://www.facebook.com')

        self.assertEqual(RequestUrlBase.objects.all().count(), 1)

        # update existing meta
        resource.update_metadata_element(self.resWebApp.short_id, 'RequestUrlBase',
                                         element_id=RequestUrlBase.objects.first().id,
                                         value='https://www.yahoo.com')
        self.assertEqual(RequestUrlBase.objects.first().value, 'https://www.yahoo.com')

        # delete RequestUrlBase obj
        resource.delete_metadata_element(self.resWebApp.short_id, 'RequestUrlBase',
                                         element_id=RequestUrlBase.objects.first().id)
        self.assertEqual(RequestUrlBase.objects.all().count(), 0)

        # Class: ToolVersion
        # verify no ToolVersion obj
        self.assertEqual(ToolVersion.objects.all().count(), 0)

        # no ToolVersion obj
        self.assertEqual(ToolVersion.objects.all().count(), 0)

        # create 1 ToolVersion obj with required params
        resource.create_metadata_element(self.resWebApp.short_id, 'ToolVersion', value='1.0')
        self.assertEqual(ToolVersion.objects.all().count(), 1)

        # may not create additional instance of ToolVersion
        with self.assertRaises(Exception):
            resource.create_metadata_element(self.resWebApp.short_id, 'ToolVersion', value='2.0')
        self.assertEqual(ToolVersion.objects.all().count(), 1)

        # update existing meta
        resource.update_metadata_element(self.resWebApp.short_id, 'ToolVersion',
                                         element_id=ToolVersion.objects.first().id,
                                         value='3.0')
        self.assertEqual(ToolVersion.objects.first().value, '3.0')

        # delete ToolVersion obj
        resource.delete_metadata_element(self.resWebApp.short_id, 'ToolVersion',
                                         element_id=ToolVersion.objects.first().id)
        self.assertEqual(ToolVersion.objects.all().count(), 0)

        # Class: SupportedResTypes
        # no SupportedResTypes obj
        self.assertEqual(SupportedResTypes.objects.all().count(), 0)

        # create 1 SupportedResTypes obj with required params
        resource.create_metadata_element(self.resWebApp.short_id, 'SupportedResTypes',
                                         supported_res_types=['NetcdfResource'])
        self.assertEqual(SupportedResTypes.objects.all().count(), 1)
        # Try creating the 2nd SupportedResTypes obj with required params
        with self.assertRaises(Exception):
            resource.create_metadata_element(self.resWebApp.short_id, 'SupportedResTypes',
                                             supported_res_types=['NetcdfResource'])
        self.assertEqual(SupportedResTypes.objects.all().count(), 1)

        # update existing meta
        resource.update_metadata_element(self.resWebApp.short_id, 'SupportedResTypes',
                                         element_id=SupportedResTypes.objects.first().id,
                                         supported_res_types=['TimeSeriesResource'])
        self.assertEqual(SupportedResTypes.objects.first().supported_res_types.all()[0].description,
                         'TimeSeriesResource')

        # try to delete 1st SupportedResTypes obj
        with self.assertRaises(Exception):
            resource.delete_metadata_element(self.resWebApp.short_id, 'SupportedResTypes',
                                             element_id=SupportedResTypes.objects.first().id)
        self.assertEqual(SupportedResTypes.objects.all().count(), 1)

        # Class: ToolIcon
        # verify no ToolIcon obj
        self.assertEqual(ToolIcon.objects.all().count(), 0)

        # no ToolIcon obj
        self.assertEqual(ToolIcon.objects.all().count(), 0)

        # create 1 ToolIcon obj with required params
        resource.create_metadata_element(self.resWebApp.short_id,
                                         'ToolIcon',
                                         value='https://www.hydroshare.org/static/img/logo-sm.png')
        self.assertEqual(ToolIcon.objects.all().count(), 1)

        # may not create additional instance of ToolIcon
        with self.assertRaises(Exception):
            resource. \
                create_metadata_element(self.resWebApp.short_id,
                                        'ToolIcon',
                                        value='https://www.hydroshare.org/static/img/logo-sm.png')
        self.assertEqual(ToolIcon.objects.all().count(), 1)

        # update existing meta
        resource. \
            update_metadata_element(self.resWebApp.short_id, 'ToolIcon',
                                    element_id=ToolIcon.objects.first().id,
                                    value='https://www.hydroshare.org/static/img/logo-sm.png')
        self.assertEqual(ToolIcon.objects.first().value,
                         'https://www.hydroshare.org/static/img/logo-sm.png')

        # delete ToolIcon obj
        resource.delete_metadata_element(self.resWebApp.short_id, 'ToolIcon',
                                         element_id=ToolIcon.objects.first().id)
        self.assertEqual(ToolIcon.objects.all().count(), 0)

        # Class: AppHomePageUrl
        # verify no AppHomePageUrl obj
        self.assertEqual(AppHomePageUrl.objects.all().count(), 0)

        # create 1 AppHomePageUrl obj with required params
        resource.create_metadata_element(self.resWebApp.short_id,
                                         'AppHomePageUrl',
                                         value='https://my_web_app.com')
        self.assertEqual(AppHomePageUrl.objects.all().count(), 1)

        # may not create additional instance of AppHomePageUrl
        with self.assertRaises(Exception):
            resource.create_metadata_element(self.resWebApp.short_id,
                                             'AppHomePageUrl',
                                             value='https://my_web_app_2.com')
        self.assertEqual(AppHomePageUrl.objects.all().count(), 1)

        # update existing meta
        resource.update_metadata_element(self.resWebApp.short_id, 'AppHomePageUrl',
                                         element_id=AppHomePageUrl.objects.first().id,
                                         value='http://my_web_app_3.com')
        self.assertEqual(AppHomePageUrl.objects.first().value, 'http://my_web_app_3.com')

        # delete AppHomePageUrl obj
        resource.delete_metadata_element(self.resWebApp.short_id, 'AppHomePageUrl',
                                         element_id=AppHomePageUrl.objects.first().id)
        self.assertEqual(AppHomePageUrl.objects.all().count(), 0)
Exemplo n.º 29
0
    def test_netcdf_metadata(self):
        # add a type element
        resource.create_metadata_element(self.resNetCDF.short_id, 'type', url="http://hydroshare.org/netcdf")

        # add another creator with all sub_elements
        cr_name = 'Mike Sundar'
        cr_des = 'http://hydroshare.org/user/001'
        cr_org = "USU"
        cr_email = '*****@*****.**'
        cr_address = "11 River Drive, Logan UT-84321, USA"
        cr_phone = '435-567-0989'
        cr_homepage = 'http://usu.edu/homepage/001'
        cr_res_id = 'http://research.org/001'
        cr_res_gate_id = 'http://research-gate.org/001'
        resource.create_metadata_element(self.resNetCDF.short_id,'creator',
                                         name=cr_name,
                                         description=cr_des,
                                         organization=cr_org,
                                         email=cr_email,
                                         address=cr_address,
                                         phone=cr_phone,
                                         homepage=cr_homepage,
                                         researcherID=cr_res_id,
                                         researchGateID=cr_res_gate_id)

        # add another creator with only the name
        resource.create_metadata_element(self.resNetCDF.short_id,'creator', name='Lisa Holley')

        #test adding a contributor with all sub_elements
        con_name = 'Sujan Peterson'
        con_des = 'http://hydroshare.org/user/002'
        con_org = "USU"
        con_email = '*****@*****.**'
        con_address = "101 Center St, Logan UT-84321, USA"
        con_phone = '435-567-3245'
        con_homepage = 'http://usu.edu/homepage/009'
        con_res_id = 'http://research.org/009'
        con_res_gate_id = 'http://research-gate.org/009'
        resource.create_metadata_element(self.resNetCDF.short_id,'contributor',
                                         name=con_name,
                                         description=con_des,
                                         organization=con_org,
                                         email=con_email,
                                         address=con_address,
                                         phone=con_phone,
                                         homepage=con_homepage,
                                         researcherID=con_res_id,
                                         researchGateID=con_res_gate_id)

        # add another creator with only the name
        resource.create_metadata_element(self.resNetCDF.short_id,'contributor', name='Andrew Smith')

        # add a period type coverage
        # add a period type coverage
        value_dict = {'name':'Name for period coverage' , 'start':'1/1/2000', 'end':'12/12/2012'}
        resource.create_metadata_element(self.resNetCDF.short_id,'coverage', type='period', value=value_dict)

        # add a point type coverage
        value_dict = {'name':'Name for point coverage', 'east':'56.45678', 'north':'12.6789'}
        resource.create_metadata_element(self.resNetCDF.short_id,'coverage', type='point', value=value_dict)

        # add date of type 'valid'
        resource.create_metadata_element(self.resNetCDF.short_id,'date', type='valid', start_date='8/10/2011', end_date='8/11/2012')

        # add a format element
        format_nc = 'netcdf'
        resource.create_metadata_element(self.resNetCDF.short_id,'format', value=format_nc)

        # add 'DOI' identifier
        #resource.create_metadata_element(self.resNetCDF.short_id,'identifier', name='DOI', url="http://dx.doi.org/001")

        # add a language element
        resource.create_metadata_element(self.resNetCDF.short_id,'language', code='eng')

        # add 'Publisher' element
        original_file_name = 'original.txt'
        original_file = open(original_file_name, 'w')
        original_file.write("original text")
        original_file.close()

        original_file = open(original_file_name, 'r')
        # add the file to the resource
        hydroshare.add_resource_files(self.resNetCDF.short_id, original_file)
        resource.create_metadata_element(self.resNetCDF.short_id,'publisher', name="HydroShare", url="http://hydroshare.org")

        # add a relation element of uri type
        resource.create_metadata_element(self.resNetCDF.short_id,'relation', type='isPartOf',
                                         value='http://hydroshare.org/resource/001')

        # add another relation element of non-uri type
        resource.create_metadata_element(self.resNetCDF.short_id,'relation', type='isDataFor',
                                         value='This resource is for another resource')


        # add a source element of uri type
        resource.create_metadata_element(self.resNetCDF.short_id,'source', derived_from='http://hydroshare.org/resource/0002')

        # add a rights element
        resource.create_metadata_element(self.resNetCDF.short_id,'rights', statement='This is the rights statement for this resource',
                                         url='http://rights.ord/001')

        # add a subject element
        resource.create_metadata_element(self.resNetCDF.short_id,'subject', value='sub-1')

        # add another subject element
        resource.create_metadata_element(self.resNetCDF.short_id,'subject', value='sub-2')

        # add a netcdf specific element (variable)
        resource.create_metadata_element(self.resNetCDF.short_id,'variable', name='temp', unit='deg C', type='float', shape='shape_unknown')

        print self.resNetCDF.metadata.get_xml()

        print(bad)
Exemplo n.º 30
0
 def test_create_refurl_orig(self):
     self.assertEqual(len(self.refts_res.metadata.methods.all()), 0)
     resource.create_metadata_element(self.refts_res.short_id, 'ReferenceURL', value='www.google.com', type='SOAP')
     self.assertEqual(len(self.refts_res.metadata.referenceURLs.all()), 1)
     self.assertEqual(self.refts_res.metadata.referenceURLs.all()[0].value, 'www.google.com')
     self.assertEqual(self.refts_res.metadata.referenceURLs.all()[0].type, 'SOAP')
Exemplo n.º 31
0
    def test_metadata(self):
        # add a type element
        resource.create_metadata_element(self.resTimeSeries.short_id, 'type', url="http://hydroshare.org/netcdf")

        # add another creator with all sub_elements
        cr_name = 'Mike Sundar'
        cr_des = 'http://hydroshare.org/user/001'
        cr_org = "USU"
        cr_email = '*****@*****.**'
        cr_address = "11 River Drive, Logan UT-84321, USA"
        cr_phone = '435-567-0989'
        cr_homepage = 'http://usu.edu/homepage/001'
        cr_res_id = 'http://research.org/001'
        cr_res_gate_id = 'http://research-gate.org/001'
        resource.create_metadata_element(self.resTimeSeries.short_id,'creator',
                                         name=cr_name,
                                         description=cr_des,
                                         organization=cr_org,
                                         email=cr_email,
                                         address=cr_address,
                                         phone=cr_phone,
                                         homepage=cr_homepage,
                                         researcherID=cr_res_id,
                                         researchGateID=cr_res_gate_id)

        # add another creator with only the name
        resource.create_metadata_element(self.resTimeSeries.short_id,'creator', name='Lisa Holley')

        #test adding a contributor with all sub_elements
        con_name = 'Sujan Peterson'
        con_des = 'http://hydroshare.org/user/002'
        con_org = "USU"
        con_email = '*****@*****.**'
        con_address = "101 Center St, Logan UT-84321, USA"
        con_phone = '435-567-3245'
        con_homepage = 'http://usu.edu/homepage/009'
        con_res_id = 'http://research.org/009'
        con_res_gate_id = 'http://research-gate.org/009'
        resource.create_metadata_element(self.resTimeSeries.short_id,'contributor',
                                         name=con_name,
                                         description=con_des,
                                         organization=con_org,
                                         email=con_email,
                                         address=con_address,
                                         phone=con_phone,
                                         homepage=con_homepage,
                                         researcherID=con_res_id,
                                         researchGateID=con_res_gate_id)

        # add another creator with only the name
        resource.create_metadata_element(self.resTimeSeries.short_id,'contributor', name='Andrew Smith')

        # add a period type coverage
        # add a period type coverage
        value_dict = {'name':'Name for period coverage' , 'start':'1/1/2000', 'end':'12/12/2012'}
        resource.create_metadata_element(self.resTimeSeries.short_id,'coverage', type='period', value=value_dict)

        # add a point type coverage
        value_dict = {'name':'Name for point coverage', 'east':'56.45678', 'north':'12.6789'}
        resource.create_metadata_element(self.resTimeSeries.short_id,'coverage', type='point', value=value_dict)

        # add date of type 'valid'
        resource.create_metadata_element(self.resTimeSeries.short_id,'date', type='valid', start_date='8/10/2011', end_date='8/11/2012')

        # add a format element
        format_nc = 'netcdf'
        resource.create_metadata_element(self.resTimeSeries.short_id,'format', value=format_nc)

        # add 'DOI' identifier
        #resource.create_metadata_element(self.resTimeSeries.short_id,'identifier', name='DOI', url="http://dx.doi.org/001")

        # add a language element
        resource.create_metadata_element(self.resTimeSeries.short_id,'language', code='eng')

        # add 'Publisher' element
        original_file_name = 'original.txt'
        original_file = open(original_file_name, 'w')
        original_file.write("original text")
        original_file.close()

        original_file = open(original_file_name, 'r')
        # add the file to the resource
        hydroshare.add_resource_files(self.resTimeSeries.short_id, original_file)
        resource.create_metadata_element(self.resTimeSeries.short_id,'publisher', name="HydroShare", url="http://hydroshare.org")

        # add a relation element of uri type
        resource.create_metadata_element(self.resTimeSeries.short_id,'relation', type='isPartOf',
                                         value='http://hydroshare.org/resource/001')

        # add another relation element of non-uri type
        resource.create_metadata_element(self.resTimeSeries.short_id,'relation', type='isDataFor',
                                         value='This resource is for another resource')


        # add a source element of uri type
        resource.create_metadata_element(self.resTimeSeries.short_id,'source', derived_from='http://hydroshare.org/resource/0002')

        # add a rights element
        resource.create_metadata_element(self.resTimeSeries.short_id,'rights', statement='This is the rights statement for this resource',
                                         url='http://rights.ord/001')

        # add a subject element
        resource.create_metadata_element(self.resTimeSeries.short_id,'subject', value='sub-1')

        # add another subject element
        resource.create_metadata_element(self.resTimeSeries.short_id,'subject', value='sub-2')


        # add time series specific metadata elements
        self.resTimeSeries.metadata.create_element('site', site_code='LR_WaterLab_AA',
                                                   site_name='Logan River at the Utah Water Research Laboratory '
                                                             'west bridge', elevation_m=1414, elevation_datum='EGM96',
                                                   site_type='Stream')

        self.resTimeSeries.metadata.create_element('variable', variable_code='ODO', variable_name='Oxygen, dissolved',
                                                   variable_type='Concentration', no_data_value=-9999,
                                                   variable_definition='Concentration of oxygen gas dissolved in water.',
                                                   speciation='Not Applicable')

        self.resTimeSeries.metadata.create_element('method', method_code=59, method_name='Optical DO',
                                                   method_type='Instrument deployment',
                                                   method_description='Dissolved oxygen concentration measured '
                                                                      'optically using a YSI EXO multi-parameter water '
                                                                      'quality sonde.', method_link='http://www.exowater.com')

        exp_text = """Raw and unprocessed data and data products that have not undergone quality control.
        Depending on the variable, data type, and data transmission system, raw data may be available within seconds
        or minutes after the measurements have been made. Examples include real time precipitation, streamflow and
        water quality measurements."""
        self.resTimeSeries.metadata.create_element('processinglevel', processing_level_code=0, definition='Raw data',
                                                   explanation=exp_text)

        self.resTimeSeries.metadata.create_element('timeseriesresult', units_type='Concentration',
                                                   units_name='milligrams per liter', units_abbreviation='mg/L',
                                                   status='Complete', sample_medium='Surface water', value_count=11283,
                                                   aggregation_statistics="Average")

        print self.resTimeSeries.metadata.get_xml()

        print(bad)