Пример #1
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')
Пример #2
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'))
Пример #3
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')
Пример #4
0
 def test_update_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.update_metadata_element(self.tool_res.short_id, 'ToolResourceType', m.id, tool_res_type=self.resourcetypes2)
     self.assertEqual(self.tool_res.metadata.res_types.all()[0].tool_res_type, self.resourcetypes2)
Пример #5
0
 def test_update_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.update_metadata_element(self.refts_res.short_id, 'Method', m.id, value='updated method')
     self.assertEqual(self.refts_res.metadata.methods.all()[0].value, 'updated method')
Пример #6
0
 def test_update_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.update_metadata_element(self.tool_res.short_id, 'RequestUrlBase', m.id, value=self.url2)
     self.assertEqual(self.tool_res.metadata.url_bases.all()[0].value, self.url2)
Пример #7
0
 def test_update_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.update_metadata_element(self.tool_res.short_id, 'ToolVersion', m.id, value=self.version2)
     self.assertEqual(self.tool_res.metadata.versions.all()[0].value, self.version2)
Пример #8
0
 def test_update_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.update_metadata_element(self.tool_res.short_id, 'Fee', m.id, description=self.desc2, value=self.value2)
     self.assertEqual(self.tool_res.metadata.fees.all()[0].description, self.desc2)
     self.assertEqual(self.tool_res.metadata.fees.all()[0].value, self.value2)
    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)
Пример #10
0
    def test_xml_creation(self):
        xml_doc = self.refts_res.metadata.get_xml()
        self.assertTrue('test quality level' in xml_doc)
        self.assertTrue('test method' in xml_doc)
        self.assertTrue('test variable name' in xml_doc)
        self.assertTrue('test code' in xml_doc)
        self.assertTrue('test data type' in xml_doc)
        self.assertTrue('test sample medium' in xml_doc)
        self.assertTrue('test site name' in xml_doc)
        self.assertTrue('test site code' in xml_doc)
        self.assertTrue('150.150000' in xml_doc)

        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='testing quality leve')
        m = self.refts_res.metadata.methods.filter(value='test method')[0]
        resource.update_metadata_element(self.refts_res.short_id, 'Method', m.id, value='testing metho')
        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='testing variable nam',
                code='testing cod',
                data_type='testing data typ',
                sample_medium='testing sample mediu')
        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='testing site nam',
                code='testing site cod',
                latitude=150.17,
                longitude=150.17)

        xml_doc = self.refts_res.metadata.get_xml()
        self.assertTrue('testing quality leve' in xml_doc)
        self.assertTrue('testing metho' in xml_doc)
        self.assertTrue('testing variable nam' in xml_doc)
        self.assertTrue('testing cod' in xml_doc)
        self.assertTrue('testing data typ' in xml_doc)
        self.assertTrue('testing sample mediu' in xml_doc)
        self.assertTrue('testing site nam' in xml_doc)
        self.assertTrue('testing site cod' in xml_doc)
        self.assertTrue('150.170000' in xml_doc)

        self.assertFalse('test quality level' in xml_doc)
        self.assertFalse('test method' in xml_doc)
        self.assertFalse('test variable name' in xml_doc)
        self.assertFalse('test code' in xml_doc)
        self.assertFalse('test data type' in xml_doc)
        self.assertFalse('test sample medium' in xml_doc)
        self.assertFalse('test site name' in xml_doc)
        self.assertFalse('test site code' in xml_doc)
        self.assertFalse('150.150000' in xml_doc)
Пример #11
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)
Пример #12
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()
Пример #13
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)
Пример #14
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)
Пример #15
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()