diff --git a/lib/JsonDIF.py b/lib/JsonDIF.py index 5c0d033d..a4281751 100755 --- a/lib/JsonDIF.py +++ b/lib/JsonDIF.py @@ -1,407 +1,89 @@ -'''This file is for get JSON output for Collection DIF data''' +""" +This file is for generating JSON output for Collection DIF data. +""" -class DIFOutputJSON(): - def __init__(self,checkerRules,wrap): - self.checkerRules = checkerRules +class DIFOutputJSON: + def __init__(self, checker_rules, wrap): + self.checker_rules = checker_rules self.wrap = wrap - def checkAll(self, metadata): + def check_all(self, metadata): result = {} - #======================================= - str = 'Entry_Title' - try: - result[str] = self.checkerRules.check_Entry_Title(metadata) - except: - result[str] = 'np' - # ====================================== - str = 'Dataset_Citation.Dataset_Release_Date' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Dataset_Citation_Dataset_Release_Date,str) - except: - result[str] = 'np' - # ====================================== - str = 'Dataset_Citation.Persistent_Identifier.Type' - try: - result[str] = self.wrap(metadata, self.checkerRules.check_Dataset_Citation_Persistent_Identifier_Type,'Dataset_Citation.Persistent_Identifier.Type') - except: - result[str] = 'np' - # ====================================== - str = 'Dataset_Citation.Persistent_Identifier.Identifier' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Dataset_Citation_Persistent_Identifier_Identifier,str) - except: - result[str] = 'np' - # ====================================== - str = 'Dataset_Citation.Online_Resource' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Dataset_Citation_Online_Resource,'Dataset_Citation.Online_Resource') - except: - result[str] = 'np' - # ====================================== - str = 'Personnel.Role' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Personnel_Role_item,str) - except: - result[str] = 'np' - # ====================================== - str = 'Personnel.Contact_Person.Email' - try: - result[str] = self.wrap(metadata, self.checkerRules.check_Personnel_Contact_Person_Email_item, str) - except: - result[str] = 'np' - # ====================================== - str = 'Personnel.Contact_Person.Phone.Number' - try: - result[str] = self.wrap(metadata, self.checkerRules.check_Personnel_Contact_Person_phone_item, str) - except: - result[str] = 'np' - # ====================================== - str = 'Personnel.Contact_Person.Phone.Type' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Personnel_Contact_Person_Phone_Type_item,str) - except: - result[str] = 'np' - # ====================================== - str = 'Personnel.Contact_Group.Email' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Personnel_Contact_Group_Email_item,str) - except: - result[str] = 'np' - # ====================================== - str = 'Personnel.Contact_Group.Phone.Number' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Personnel_Contact_Group_Phone_item,str) - except: - result[str] = 'np' - # ====================================== - str = 'Personnel.Contact_Group.Phone.Type' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Personnel_Contact_Group_Phone_Type_item,str) - except: - result[str] = 'np' - # ====================================== - str = 'Science_Keywords.Category' - try: - result[str] = self.wrap(metadata,self.checkerRules.science_Keywords_item_Category,str) - except: - result[str] = 'np' - # ====================================== - str = 'Science_Keywords.Topic' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_science_Keywords_item_topic,str) - except: - result[str] = 'np' - # ====================================== - str = 'Science_Keywords.Term' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_science_Keywords_item_Term,str) - except: - result[str] = 'np' - # ====================================== - str = 'Science_Keywords.Variable_Level_1' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_science_Keywords_item_Variable_1,str) - except: - result[str] = 'np' - # ====================================== - str = 'Science_Keywords.Variable_Level_2' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_science_Keywords_item_Variable_2,str) - except: - result[str] = 'np' - # ====================================== - str = 'Science_Keywords.Variable_Level_3' - try: - result[str] = self.wrap(metadata, self.checkerRules.check_science_Keywords_item_Variable_3,str) - except: - result[str] = 'np' - # ====================================== - str = 'ISO_Topic_Category' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_ISO_Topic_Category,str) - except: - result[str] = 'np' - # ====================================== - str = 'Platform.Type' - try: - result[str] = self.wrap(metadata, self.checkerRules.check_Platform_item_Type,str) - except: - result[str] = 'np' - # ====================================== - str = 'Platform.Short_Name' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Platform_item_Short_Name,str) - except: - result[str] = 'np' - # ====================================== - str = 'Platform.Long_Name' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Platform_item_Long_Name,str) - except: - result[str] = 'np' + checks = [ + ('Entry_Title', self.checker_rules.check_Entry_Title), + ('Dataset_Citation.Dataset_Release_Date', self.checker_rules.check_Dataset_Citation_Dataset_Release_Date), + ('Dataset_Citation.Persistent_Identifier.Type', self.checker_rules.check_Dataset_Citation_Persistent_Identifier_Type), + ('Dataset_Citation.Persistent_Identifier.Identifier', self.checker_rules.check_Dataset_Citation_Persistent_Identifier_Identifier), + ('Dataset_Citation.Online_Resource', self.checker_rules.check_Dataset_Citation_Online_Resource), + ('Personnel.Role', self.checker_rules.check_Personnel_Role_item), + ('Personnel.Contact_Person.Email', self.checker_rules.check_Personnel_Contact_Person_Email_item), + ('Personnel.Contact_Person.Phone.Number', self.checker_rules.check_Personnel_Contact_Person_phone_item), + ('Personnel.Contact_Person.Phone.Type', self.checker_rules.check_Personnel_Contact_Person_Phone_Type_item), + ('Personnel.Contact_Group.Email', self.checker_rules.check_Personnel_Contact_Group_Email_item), + ('Personnel.Contact_Group.Phone.Number', self.checker_rules.check_Personnel_Contact_Group_Phone_item), + ('Personnel.Contact_Group.Phone.Type', self.checker_rules.check_Personnel_Contact_Group_Phone_Type_item), + ('Science_Keywords.Category', self.checker_rules.science_Keywords_item_Category), + ('Science_Keywords.Topic', self.checker_rules.check_science_Keywords_item_topic), + ('Science_Keywords.Term', self.checker_rules.check_science_Keywords_item_Term), + ('Science_Keywords.Variable_Level_1', self.checker_rules.check_science_Keywords_item_Variable_1), + ('Science_Keywords.Variable_Level_2', self.checker_rules.check_science_Keywords_item_Variable_2), + ('Science_Keywords.Variable_Level_3', self.checker_rules.check_science_Keywords_item_Variable_3), + ('ISO_Topic_Category', self.checker_rules.check_ISO_Topic_Category), + ('Platform.Type', self.checker_rules.check_Platform_item_Type), + ('Platform.Short_Name', self.checker_rules.check_Platform_item_Short_Name), + ('Platform.Long_Name', self.checker_rules.check_Platform_item_Long_Name), + ('Platform.Instrument.Short_Name', self.checker_rules.check_Platform_item_Instrument_item_shortname), + ('Platform.Instrument.Long_Name', self.checker_rules.check_Platform_item_Instrument_item_longname), + ('Platform.Instrument', self.checker_rules.check_Platform_item_Instrument_sensor_shortname), + ('Platform.Instrument', self.checker_rules.check_Platform_item_Instrument_sensor_longname), + ('Temporal_Coverage.Range_DateTime.Beginning_Date_Time', self.checker_rules.check_Temporal_Coverage_item_Begin_Date_Time), + ('Temporal_Coverage.Range_DateTime.Ending_Date_Time', self.checker_rules.check_Temporal_Coverage_item_end_Date_Time), + ('Dataset_Progress', self.checker_rules.check_dataset_progress), + ('Spatial_Coverage.Granule_Spatial_Representation', self.checker_rules.check_Spatial_Coverage_Granule_Spatial_Representation), + ('Spatial_Coverage.Geometry.Coordinate_System', self.checker_rules.check_Spatial_Coverage_Geometry_Coordinate_System), + ('Spatial_Coverage.Geometry.Bounding_Rectangle', self.checker_rules.check_Spatial_Coverage_Geometry_Bounding_Rectangle_Southernmost_Latitude), + ('Spatial_Coverage.Geometry.Bounding_Rectangle', self.checker_rules.check_Spatial_Coverage_Geometry_Bounding_Rectangle_Northernmost_Latitude), + ('Spatial_Coverage.Geometry.Bounding_Rectangle', self.checker_rules.check_Spatial_Coverage_Geometry_Bounding_Rectangle_Westernmost_Longitude), + ('Spatial_Coverage.Geometry.Bounding_Rectangle', self.checker_rules.check_Spatial_Coverage_Geometry_Bounding_Rectangle_Easternmost_Longitude), + ('Location.Location_Category', self.checker_rules.check_Location_Location_Category), + ('Location.Location_Type', self.checker_rules.check_Location_Location_Type), + ('Location.Location_Subregion1', self.checker_rules.check_Location_Subregion1), + ('Location.Location_Subregion2', self.checker_rules.check_Location_Subregion2), + ('Location.Location_Subregion3', self.checker_rules.check_Location_Subregion3), + ('Data_Resolution.Horizontal_Resolution_Range', self.checker_rules.check_Horizontal_Resolution_Range), + ('Data_Resolution.Vertical_Resolution_Range', self.checker_rules.check_Vertical_Resolution_Range), + ('Data_Resolution.Temporal_Resolution_Range', self.checker_rules.check_Temporal_Resolution_Range), + ('Project.Short_Name', self.checker_rules.check_Project_Short_Name), + ('Project.Long_Name', self.checker_rules.check_Project_Long_Name), + ('Quality', self.checker_rules.check_Quality), + ('Dataset_Language', self.checker_rules.check_Dataset_Language), + ('Organization.Organization_Type', self.checker_rules.check_Organization_Organization_Type), + ('Organization.Organization_Name.Short_Name', self.checker_rules.check_Organization_Name_Short_Name), + ('Organization.Organization_Name.Long_Name', self.checker_rules.check_Organization_Name_Long_Name), + ('Organization.Personnel.Contact_Person.Phone.Type', self.checker_rules.check_Organization_Personnel_Contact_Person_Phone_Type), + ('Organization.Personnel.Contact_Group.Phone.Type', self.checker_rules.check_Organization_Personnel_Contact_Person_Phone_Type), + ('Distribution.Distribution_Format', self.checker_rules.check_Distribution_Distribution_Format), + ('Multimedia_Sample.URL', self.checker_rules.check_Multimedia_Sample_URL), + ('Summary.Abstract', self.checker_rules.check_summary_abstract), + ('Related_URL.URL_Content_Type.Type', self.checker_rules.check_Related_URL_item_Content_Type), + ('Related_URL.URL_Content_Type.Subtype', self.checker_rules.check_Related_URL_Content_Type_SubType), + ('Related_URL.Description', self.checker_rules.check_Related_URL_Description_Item), + ('Related_URL', self.checker_rules.check_Related_URL_Mime_Type), + ('Product_Level_Id', self.checker_rules.check_Product_Level_ID), + ('Collection_Data_Type', self.checker_rules.check_Collection_Data_Type), + ('Metadata_Dates.Metadata_Creation', self.checker_rules.check_Metadata_Dates_Creation), + ('Metadata_Dates.Metadata_Last_Revision', self.checker_rules.check_Metadata_last_revision), + ('Metadata_Dates.Data_Creation', self.checker_rules.check_Metadata_data_creation), + ('Metadata_Dates.Data_Last_Revision', self.checker_rules.check_Metadata_data_latest_revision), + ] - # ====================================== - str = 'Platform.Instrument.Short_Name' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Platform_item_Instrument_item_shortname,str) - except: - result[str] = 'np' - # ====================================== - str = 'Platform.Instrument.Long_Name' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Platform_item_Instrument_item_longname,str) - except: - result[str] = 'np' - # ====================================== - str = 'Platform.Instrument' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Platform_item_Instrument_sensor_shortname,str) - except: - result[str] = 'np' - # ====================================== - str = 'Platform.Instrument' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Platform_item_Instrument_sensor_longname,str) - except: - result[str] = 'np' + for key, check_function in checks: + result[key] = self.safe_wrap(metadata, check_function, key) - # ====================================== - str = 'Temporal_Coverage.Range_DateTime.Beginning_Date_Time' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Temporal_Coverage_item_Begin_Date_Time,str) - except: - result[str] = 'np' - # ====================================== - str = 'Temporal_Coverage.Range_DateTime.Ending_Date_Time' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Temporal_Coverage_item_end_Date_Time,str) - except: - result[str] = 'np' - # ====================================== - str = 'Dataset_Progress' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_dataset_progress,str) - except: - result[str] = 'np' - # ====================================== - str = 'Spatial_Coverage.Granule_Spatial_Representation' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Spatial_Coverage_Granule_Spatial_Representation,str) - except: - result[str] = 'np' - # ====================================== - str = 'Spatial_Coverage.Geometry.Coordinate_System' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Spatial_Coverage_Geometry_Coordinate_System,str) - except: - result[str] = 'np' - # ====================================== - str = 'Spatial_Coverage.Geometry.Bounding_Rectangle' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Spatial_Coverage_Geometry_Bounding_Rectangle_Southernmost_Latitude,str) - except: - result[str] = 'np' - # ====================================== - str = 'Spatial_Coverage.Geometry.Bounding_Rectangle' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Spatial_Coverage_Geometry_Bounding_Rectangle_Northernmost_Latitude,str) - except: - result[str] = 'np' - # ====================================== - str = 'Spatial_Coverage.Geometry.Bounding_Rectangle' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Spatial_Coverage_Geometry_Bounding_Rectangle_Westernmost_Longitude,str) - except: - result[str] = 'np' - # ====================================== - str = 'Spatial_Coverage.Geometry.Bounding_Rectangle' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Spatial_Coverage_Geometry_Bounding_Rectangle_Easternmost_Longitude,str) - except: - result[str] = 'np' + return result - # ====================================== - str = 'Location.Location_Category' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Location_Location_Category,str) - except: - result[str] = 'np' - # ====================================== - str = 'Location.Location_Type' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Location_Location_Type,str) - except: - result[str] = 'np' - # ====================================== - str = 'Location.Location_Subregion1' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Location_Subregion1,str) - except: - result[str] = 'np' - # ====================================== - str = 'Location.Location_Subregion2' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Location_Subregion2,str) - except: - result[str] = 'np' - # ====================================== - str = 'Location.Location_Subregion3' - try: - result[str] = self.wrap(metadata, self.checkerRules.check_Location_Subregion3, str) - except: - result[str] = 'np' - # ====================================== - str = 'Data_Resolution.Horizontal_Resolution_Range' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Horizontal_Resolution_Range,str) - except: - result[str] = 'np' - # ====================================== - str = 'Data_Resolution.Vertical_Resolution_Range' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Vertical_Resolution_Range,str) - except: - result[str] = 'np' - # ====================================== - str = 'Data_Resolution.Temporal_Resolution_Range' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Temporal_Resolution_Range,str) - except: - result[str] = 'np' - # ====================================== - str = 'Project.Short_Name' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Project_Short_Name,str) - except: - result[str] = 'np' - # ====================================== - str = 'Project.Long_Name' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Project_Long_Name,str) - except: - result[str] = 'np' - # ====================================== - str = 'Quality' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Quality,str) - except: - result[str] = 'np' - # ====================================== - str = 'Dataset_Language' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Dataset_Language,str) - except: - result[str] = 'np' - # ====================================== - str = 'Organization.Organization_Type' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Organization_Organization_Type,str) - except: - result[str] = 'np' - # ====================================== - str = 'Organization.Organization_Name.Short_Name' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Organization_Name_Short_Name,str) - except: - result[str] = 'np' - # ====================================== - str = 'Organization.Organization_Name.Long_Name' + def safe_wrap(self, metadata, check_function, key): try: - result[str] = self.wrap(metadata,self.checkerRules.check_Organization_Name_Long_Name,str) - except: - result[str] = 'np' - # ====================================== - str = 'Organization.Personnel.Contact_Person.Phone.Type' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Organization_Personnel_Contact_Person_Phone_Type,str) - except: - result[str] = 'np' - # ====================================== - str = 'Organization.Personnel.Contact_Group.Phone.Type' - try: - result[str] = self.wrap(metadata, self.checkerRules.check_Organization_Personnel_Contact_Person_Phone_Type,str) - except: - result[str] = 'np' - # ====================================== - str = 'Distribution.Distribution_Format' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Distribution_Distribution_Format,str) - except: - result[str] = 'np' - # ====================================== - str = 'Multimedia_Sample.URL' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Multimedia_Sample_URL,str) - except: - result[str] = 'np' - # ====================================== - str = 'Summary.Abstract' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_summary_abstract,str) - except: - result[str] = 'np' - # ====================================== - str = 'Related_URL.URL_Content_Type.Type' - try: - temp = self.wrap(metadata,self.checkerRules.check_Related_URL_item_Content_Type,str) - result[str] = self.checkerRules.check_Related_URL_Content_Type(temp) - except: - result[str] = 'np' - # ====================================== - str = 'Related_URL.URL_Content_Type.Subtype' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Related_URL_Content_Type_SubType,str) - except: - result[str] = 'np' - # ====================================== - str = 'Related_URL.Description' - try: - temp = self.wrap(metadata,self.checkerRules.check_Related_URL_Description_Item,str) - result[str] += self.checkerRules.check_Related_URL_Description(temp) - except: - result[str] = 'np' - # ====================================== - str = 'Related_URL' - try: - temp = self.wrap(metadata,self.checkerRules.check_Related_URL_Mime_Type,str) - result[str] = self.checkerRules.convertMimeType(temp) - except: - result[str] = 'np' - # ====================================== - str = 'Product_Level_Id' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Product_Level_ID,str) - except: - result[str] = 'np' - # ====================================== - str = 'Collection_Data_Type' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Collection_Data_Type,str) - except: - result[str] = 'np' - # ====================================== - str = 'Metadata_Dates.Metadata_Creation' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Metadata_Dates_Creation,str) - except: - result[str] = 'np' - # ====================================== - str = 'Metadata_Dates.Metadata_Last_Revision' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Metadata_last_revision,str) - except: - result[str] = 'np' - # ====================================== - str = 'Metadata_Dates.Data_Creation' - try: - result[str] = self.wrap(metadata, self.checkerRules.check_Metadata_data_creation,str) - except: - result[str] = 'np' - # ====================================== - str = 'Metadata_Dates.Data_Last_Revision' - try: - result[str] = self.wrap(metadata,self.checkerRules.check_Metadata_data_latest_revision,str) - except: - result[str] = 'np' - - return result \ No newline at end of file + return self.wrap(metadata, check_function, key) + except Exception: + return 'np' diff --git a/lib/JsonGranule.py b/lib/JsonGranule.py index 57053a83..90584b1e 100755 --- a/lib/JsonGranule.py +++ b/lib/JsonGranule.py @@ -1,280 +1,160 @@ -'''This file is for get CSV output for Collection DIF data''' +""" +This file is for generating CSV output for Collection DIF data. +""" -class GranuleOutputJSON(): - def __init__(self,checkerRules,fetchAllInstrs): - self.checkerRules = checkerRules - self.fetchAllInstrs = fetchAllInstrs +class GranuleOutputJSON: + def __init__(self, checker_rules, fetch_all_instrs): + self.checker_rules = checker_rules + self.fetch_all_instrs = fetch_all_instrs - def checkAll(self, metadata): + def check_all(self, metadata): result = {} - # ================ - str = 'InsertTime' - try: - result[str] = self.checkerRules.checkInsertTime(metadata[str]) - except: - result[str] = "np" - # ================ - str = 'LastUpdate' - try: - result[str] = self.checkerRules.checkLastUpdate(metadata['LastUpdate'],metadata['DataGranule']['ProductionDateTime']) - except: - result[str] = "np" - # ================ - str = 'DeleteTime' - try: - result[str] = self.checkerRules.checkDeleteTime(metadata['DeleteTime'], - metadata['DataGranule']['ProductionDateTime']) - except: - result[str] = "np" - # ================ - str = 'Collection/ShortName' - try: - result[str] = self.checkerRules.checkCollectionShortName(metadata['Collection']['ShortName']) - except KeyError: - result[str] = "np - Ensure the DataSetId field is provided." - except: - result[str] = "np" - # ================= - str = 'Collection/VersionId' - try: - result[str] = self.checkerRules.checkCollectionVersionID(metadata['Collection']['VersionId']) - except KeyError: - result[str] = "np - Ensure the DataSetId field is provided." - except: - result[str] = "np" - # ================ - str = 'Collection/DataSetId' - try: - result[str] = self.checkerRules.checkDataSetId(metadata['Collection']['DataSetId']) - except KeyError: - result[str] = "np - Ensure that the ShortName and VersionId fields are provided." - except: - result[str] = "np" - # ================ - str = 'DataGranule/SizeMBDataGranule' - try: - result[str] = self.checkerRules.checkSizeMBDataGranule( - metadata['DataGranule']['SizeMBDataGranule']) - except KeyError: - result[str] = "Granule file size not provided. Recommend providing a value for this field in the metadata" - except: - result[str] = "np" - # ================ - str = 'DataGranule/DayNightFlag' - try: - result[str] = self.checkerRules.checkDayNightFlag(metadata['DataGranule']['DayNightFlag']) - except: - result[str] = "np" - # ================ - str = 'DataGranule/ProductionDateTime' - try: - result[str] = self.checkerRules.checkProductionDateTime(metadata['DataGranule']['ProductionDateTime'],metadata['InsertTime']) - except: - result[str] = "np" - # ================ - str = 'Temporal/RangeDateTime/SingleDateTime' - try: - result[str] = self.checkerRules.checkTemporalSingleTime(metadata['Temporal']['RangeDateTime']['SingleDateTime']) - except: - result[str] = "np" - # ================ - str = 'Temporal/RangeDateTime/BeginningDateTime' - try: - result[str] = self.checkerRules.checkTemporalBeginningTime(metadata['Temporal']['RangeDateTime']['BeginningDateTime']) - except: - result[str] = "np" - # ================ - str = 'Temporal/RangeDateTime/EndingDateTime' - try: - result[str] = self.checkerRules.checkTemporalEndingTime(metadata['Temporal']['RangeDateTime']['EndingDateTime']) - except KeyError: - result[str] = "np" - # ================ - str = 'Spatial/HorizontalSpatialDomain/Geometry/BoundingRectangle' - try: - result[str] = self.checkerRules.checkBoundingRectangle( - metadata['Spatial']['HorizontalSpatialDomain']['Geometry'][ - 'BoundingRectangle']) - except: - result[str] = "np, np, np, np" - # ================ - str = 'OrbitCalculatedSpatialDomains/OrbitCalculatedSpatialDomain/EquatorCrossingDateTime' + checks = [ + ('InsertTime', self.checker_rules.checkInsertTime), + ('LastUpdate', lambda md: self.checker_rules.checkLastUpdate(md['LastUpdate'], md['DataGranule']['ProductionDateTime'])), + ('DeleteTime', lambda md: self.checker_rules.checkDeleteTime(md['DeleteTime'], md['DataGranule']['ProductionDateTime'])), + ('Collection/ShortName', self.checker_rules.checkCollectionShortName, KeyError, "np - Ensure the DataSetId field is provided."), + ('Collection/VersionId', self.checker_rules.checkCollectionVersionID, KeyError, "np - Ensure the DataSetId field is provided."), + ('Collection/DataSetId', self.checker_rules.checkDataSetId, KeyError, "np - Ensure that the ShortName and VersionId fields are provided."), + ('DataGranule/SizeMBDataGranule', self.checker_rules.checkSizeMBDataGranule, KeyError, "Granule file size not provided. Recommend providing a value for this field in the metadata"), + ('DataGranule/DayNightFlag', self.checker_rules.checkDayNightFlag), + ('DataGranule/ProductionDateTime', lambda md: self.checker_rules.checkProductionDateTime(md['DataGranule']['ProductionDateTime'], md['InsertTime'])), + ('Temporal/RangeDateTime/SingleDateTime', self.checker_rules.checkTemporalSingleTime), + ('Temporal/RangeDateTime/BeginningDateTime', self.checker_rules.checkTemporalBeginningTime), + ('Temporal/RangeDateTime/EndingDateTime', self.checker_rules.checkTemporalEndingTime, KeyError, "np"), + ('Spatial/HorizontalSpatialDomain/Geometry/BoundingRectangle', self.checker_rules.checkBoundingRectangle, None, "np, np, np, np"), + ('OrbitCalculatedSpatialDomains/OrbitCalculatedSpatialDomain/EquatorCrossingDateTime', self.checker_rules.checkEquatorCrossingTime, TypeError, "np", self.check_equator_crossing_time), + ('Platforms/Platform/ShortName', self.checker_rules.checkPlatformShortName, TypeError, "np", self.check_platform_short_name), + ('Platforms/Platform/Instruments/Instrument/ShortName', self.check_instruments_short_name), + ('Platforms/Platform/Instruments/Instrument/Sensors/Sensor/ShortName', self.check_sensor_short_name), + ('Campaigns/', self.check_campaign_short_name), + ('OnlineAccessURLs/OnlineAccessURL/URL', self.check_online_access_url, TypeError, "No Online Access URL is provided"), + ('OnlineAccessURLs/OnlineAccessURL/URLDescription', self.check_online_access_url_desc, TypeError, "Recommend providing a brief URL description"), + ('OnlineResources/OnlineResource/URL', self.check_online_resource_url), + ('OnlineResource/OnlineResource/Description', self.check_online_resource_desc), + ('OnlineResources/OnlineResource/Type', self.check_online_resource_type), + ('Orderable', self.checker_rules.checkOrderable), + ('DataFormat', self.checker_rules.checkDataFormat, KeyError, "Recommend providing the data format for the associated granule"), + ('Visible', self.checker_rules.checkVisible), + ] + + for key, check_function, *exception_handling in checks: + result[key] = self.safe_wrap(metadata, key, check_function, *exception_handling) + + return result + + def safe_wrap(self, metadata, key, check_function, specific_exception=None, specific_message=None, alternative_function=None): + try: + if alternative_function: + return alternative_function(metadata, check_function) + return check_function(metadata[key]) + except specific_exception: + return specific_message + except Exception: + return "np" + + def check_equator_crossing_time(self, metadata, check_function): try: - result[str] = self.checkerRules.checkEquatorCrossingTime( - metadata['OrbitCalculatedSpatialDomains']['OrbitCalculatedSpatialDomain'][ - 'EquatorCrossingDateTime'], 1) + return check_function(metadata['OrbitCalculatedSpatialDomains']['OrbitCalculatedSpatialDomain']['EquatorCrossingDateTime'], 1) except TypeError: - if metadata['OrbitCalculatedSpatialDomains'] != None and metadata['OrbitCalculatedSpatialDomains'][ - 'OrbitCalculatedSpatialDomain'] != None: + if metadata['OrbitCalculatedSpatialDomains'] and metadata['OrbitCalculatedSpatialDomains']['OrbitCalculatedSpatialDomain']: length = len(metadata['OrbitCalculatedSpatialDomains']['OrbitCalculatedSpatialDomain']) try: - result[str] = self.checkerRules.checkEquatorCrossingTime( - metadata['OrbitCalculatedSpatialDomains']['OrbitCalculatedSpatialDomain'][ - 'EquatorCrossingDateTime'], length) + return check_function(metadata['OrbitCalculatedSpatialDomains']['OrbitCalculatedSpatialDomain']['EquatorCrossingDateTime'], length) except: - result[str]= "np" - else: - result[str] = "np" - except: - result[str]= "np" - # ================ - str = 'Platforms/Platform/ShortName' + return "np" + return "np" + + def check_platform_short_name(self, metadata, check_function): try: - result[str] = self.checkerRules.checkPlatformShortName(metadata['Platforms']['Platform']['ShortName'],1) + return check_function(metadata['Platforms']['Platform']['ShortName'], 1) except TypeError: - if metadata['Platforms'] != None and metadata['Platforms']['Platform'] != None: + if metadata['Platforms'] and metadata['Platforms']['Platform']: length = len(metadata['Platforms']['Platform']) - result[str] = self.checkerRules.checkPlatformShortName(metadata['Platforms']['Platform'], length) - else: - result[str] = "np" - except: - result[str] = "np" - # ================ - # try: - # metadata['Platforms']['Platform']['ShortName'] - # platform_num = 1 - # result += self.checkInstrShortName(metadata['Platforms']['Platform'], platform_num) + ', , , ' - # except TypeError: - # if metadata['Platforms'] != None and metadata['Platforms']['Platform'] != None: - # platform_num = len(metadata['Platforms']['Platform']) - # result += self.checkInstrShortName(metadata['Platforms']['Platform'], platform_num) + ', , , ' - # else: - # result += "np" + ', , , ' - # except KeyError: - # result += "np" + ', , , ' - # ================ - str = 'Platforms/Platform/Instruments/Instrument/ShortName' - instruments = self.fetchAllInstrs - sensorShortResult = '' + return check_function(metadata['Platforms']['Platform'], length) + return "np" + + def check_instruments_short_name(self, metadata, check_function): + sensor_short_result = '' try: metadata['Platforms']['Platform']['ShortName'] platform_num = 1 - ret, sensorShortResult = self.checkerRules.checkInstrShortName(metadata['Platforms']['Platform'], - platform_num, instruments) - result[str] = ret + ret, sensor_short_result = check_function(metadata['Platforms']['Platform'], platform_num, self.fetch_all_instrs) + return ret except TypeError: - if metadata['Platforms'] != None and metadata['Platforms']['Platform'] != None: + if metadata['Platforms'] and metadata['Platforms']['Platform']: platform_num = len(metadata['Platforms']['Platform']) - ret, sensorShortResult = self.checkerRules.checkInstrShortName(metadata['Platforms']['Platform'], - platform_num, instruments) - result[str] = ret - else: - result[str] = 'np' - except KeyError: - result[str] = 'np' - # ================ - str = 'Platforms/Platform/Instruments/Instrument/Sensors/Sensor/ShortName' - if len(sensorShortResult) == 0: - result[str] = 'np' - else: - result[str] = sensorShortResult - # ================ - str = 'Campaigns/' + ret, sensor_short_result = check_function(metadata['Platforms']['Platform'], platform_num, self.fetch_all_instrs) + return ret + return 'np' + + def check_sensor_short_name(self, metadata, check_function): + sensor_short_result = self.check_instruments_short_name(metadata, check_function) + if len(sensor_short_result) == 0: + return 'np' + return sensor_short_result + + def check_campaign_short_name(self, metadata, check_function): try: campaign_num = 1 - result[str] = self.checkerRules.checkCampaignShortName(metadata['Campaigns']['Campaign']['ShortName'],campaign_num) + return check_function(metadata['Campaigns']['Campaign']['ShortName'], campaign_num) except TypeError: - if metadata['Campaigns'] != None and metadata['Campaigns']['Campaign'] != None: + if metadata['Campaigns'] and metadata['Campaigns']['Campaign']: campaign_num = len(metadata['Campaigns']) - result[str] = self.checkerRules.checkCampaignShortName(metadata['Campaigns'],campaign_num) + return check_function(metadata['Campaigns'], campaign_num) except: - result[str] = "np" - # ================ - str = 'OnlineAccessURLs/OnlineAccessURL/URL' + return "np" + + def check_online_access_url(self, metadata, check_function): try: - result[str] = self.checkerRules.checkOnlineAccessURL(metadata['OnlineAccessURLs']['OnlineAccessURL']['URL'],1) + return check_function(metadata['OnlineAccessURLs']['OnlineAccessURL']['URL'], 1) except TypeError: - if metadata['OnlineAccessURLs'] != None: + if metadata['OnlineAccessURLs']: length = len(metadata['OnlineAccessURLs']['OnlineAccessURL']) - result[str] = self.checkerRules.checkOnlineAccessURL(metadata['OnlineAccessURLs']['OnlineAccessURL'], - length) - else: - result[str] = "No Online Access URL is provided" + return check_function(metadata['OnlineAccessURLs']['OnlineAccessURL'], length) except KeyError: - result[str] = "No Online Access URL is provided" + return "No Online Access URL is provided" except: - result[str] = "np" - # ================ - str = 'OnlineAccessURLs/OnlineAccessURL/URLDescription' + return "np" + + def check_online_access_url_desc(self, metadata, check_function): try: - result[str]= self.checkerRules.checkOnlineAccessURLDesc( - metadata['OnlineAccessURLs']['OnlineAccessURL']['URLDescription'], 1) + return check_function(metadata['OnlineAccessURLs']['OnlineAccessURL']['URLDescription'], 1) except TypeError: - if metadata['OnlineAccessURLs'] != None: + if metadata['OnlineAccessURLs']: length = len(metadata['OnlineAccessURLs']['OnlineAccessURL']) - result[str] = self.checkerRules.checkOnlineAccessURLDesc(metadata['OnlineAccessURLs']['OnlineAccessURL'], length) - else: - result[str] = "Recommend providing a brief URL description" + return check_function(metadata['OnlineAccessURLs']['OnlineAccessURL'], length) except KeyError: - result[str] = "Recommend providing a brief URL description" + return "Recommend providing a brief URL description" except: - result[str] = "np" - # ================ - str = 'OnlineResources/OnlineResource/URL' - OnlineResourceURL_Cnt = 0 + return "np" + + def check_online_resource_url(self, metadata, check_function): try: - result[str] = self.checkerRules.checkOnlineResourceURL(metadata['OnlineResources']['OnlineResource']['URL'], - 1) - OnlineResourceURL_Cnt = 1 + return check_function(metadata['OnlineResources']['OnlineResource']['URL'], 1) except TypeError: - if metadata['OnlineResources'] != None: + if metadata['OnlineResources']: length = len(metadata['OnlineResources']['OnlineResource']) - OnlineResourceURL_Cnt = length - result[str] = self.checkerRules.checkOnlineResourceURL(metadata['OnlineResources']['OnlineResource'], - length) - else: - result[str] = "np" + return check_function(metadata['OnlineResources']['OnlineResource'], length) except: - result[str] = "np" - # ================ - str = 'OnlineResource/OnlineResource/Description' + return "np" + + def check_online_resource_desc(self, metadata, check_function): try: - result[str] = self.checkerRules.checkOnlineResourceDesc( - metadata['OnlineResources']['OnlineResource']['Description'], 1) + return check_function(metadata['OnlineResources']['OnlineResource']['Description'], 1) except TypeError: - if metadata['OnlineResources'] != None: + if metadata['OnlineResources']: length = len(metadata['OnlineResources']['OnlineResource']) - if length < OnlineResourceURL_Cnt: - result[str] = "Recommend providing descriptions for all Online Resource URLs." - else: - result[str] = self.checkerRules.checkOnlineResourceDesc( - metadata['OnlineResources']['OnlineResource'], length) - else: - result[str] = "np" + return check_function(metadata['OnlineResources']['OnlineResource'], length) except: - result[str] = "np" - # ================ - str = 'OnlineResources/OnlineResource/Type' + return "np" + + def check_online_resource_type(self, metadata, check_function): try: - result[str] = self.checkerRules.checkOnlineResourceType( - metadata['OnlineResources']['OnlineResource']['Type'], 1) + return check_function(metadata['OnlineResources']['OnlineResource']['Type'], 1) except TypeError: - if metadata['OnlineResources'] != None: + if metadata['OnlineResources']: length = len(metadata['OnlineResources']['OnlineResource']) - result[str] = self.checkerRules.checkOnlineResourceType(metadata['OnlineResources']['OnlineResource'], - length) - else: - result[str] = "np" - except: - result[str] = "np" - # ================ - str = "Orderable" - try: - result[str] = self.checkerRules.checkOrderable(metadata["Orderable"]) + return check_function(metadata['OnlineResources']['OnlineResource'], length) except: - result[str] = "np" - # ================ - str = 'DataFormat' - try: - result[str] = self.checkerRules.checkDataFormat(metadata["DataFormat"]) - except KeyError: - result[str] = "Recommend providing the data format for the associated granule" - except: - result[str] = "np" - # ================ - str = 'Visible' - try: - result[str] = self.checkerRules.checkVisible(metadata["Visible"]) - except: - result[str] = "np" - return result + return "np" diff --git a/test/controllers/collections_controller_test.rb b/test/controllers/collections_controller_test.rb index 381dd380..c2125869 100644 --- a/test/controllers/collections_controller_test.rb +++ b/test/controllers/collections_controller_test.rb @@ -1,5 +1,5 @@ require 'test_helper' -Dir[Rails.root.join("test/**/*.rb")].each {|f| require f} +Dir[Rails.root.join("test/**/*.rb")].each { |f| require f } class CollectionsControllerTest < ActionDispatch::IntegrationTest include Devise::Test::IntegrationHelpers @@ -12,33 +12,22 @@ class CollectionsControllerTest < ActionDispatch::IntegrationTest end describe 'GET #search' do - it 'it returns modis results' do + it 'returns MODIS results' do sign_in(user) stub_urs_access(user.uid, user.access_token, user.refresh_token) - stub_request(:get, "#{@cmr_base_url}/search/collections.echo10?keyword=*modis*&page_num=1&page_size=10&provider=ORNL_CLOUD"). - with( - headers: { - 'Accept'=>'*/*', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'User-Agent'=>'Ruby' - }). - to_return(status: 200, body: get_stub('modis-search.xml'), headers: {}) - - stub_request(:get, "https://cmr.sit.earthdata.nasa.gov/search/collections.echo10?keyword=*modis*&page_num=1&page_size=10&provider=GESDISCCLD"). - with( - headers: { - 'Accept'=>'*/*', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'User-Agent'=>'Ruby' - }). - to_return(status: 200, body: get_stub('modis-search.xml'), headers: {}) - - get '/collections_search', params: { provider: 'DAAC: ANY', free_text: 'modis', curr_page:1 } - count = assigns(:collection_count) - search_iterator = assigns(:search_iterator) - assert(113, count) - assert('C1200019523-OB_DAAC', search_iterator[0]['concept_id']) + stub_request(:get, "#{@cmr_base_url}/search/collections.echo10?keyword=*modis*&page_num=1&page_size=10&provider=ORNL_CLOUD") + .with(headers: default_headers) + .to_return(status: 200, body: get_stub('modis-search.xml')) + + stub_request(:get, "https://cmr.sit.earthdata.nasa.gov/search/collections.echo10?keyword=*modis*&page_num=1&page_size=10&provider=GESDISCCLD") + .with(headers: default_headers) + .to_return(status: 200, body: get_stub('modis-search.xml')) + + get '/collections_search', params: { provider: 'DAAC: ANY', free_text: 'modis', curr_page: 1 } + + assert_equal 113, assigns(:collection_count) + assert_equal 'C1200019523-OB_DAAC', assigns(:search_iterator)[0]['concept_id'] end end @@ -46,378 +35,190 @@ class CollectionsControllerTest < ActionDispatch::IntegrationTest it "loads the correct collection on show" do sign_in(user) stub_urs_access(user.uid, user.access_token, user.refresh_token) - - #stubbing all requests for raw_data - stub_request(:get, "#{@cmr_base_url}/search/collections.echo10?concept_id=C1000000020-LANCEAMSR2").with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', }).to_return(:status => 200, :body => get_stub("search_collection_C1000000020-LANCEAMSR2.xml"), :headers => {"date"=>["Tue, 21 Feb 2017 16:02:46 GMT"], "content-type"=>["application/echo10+xml; charset=utf-8"], "access-control-expose-headers"=>["CMR-Hits, CMR-Request-Id"], "access-control-allow-origin"=>["*"], "cmr-hits"=>["10554"], "cmr-took"=>["40"], "cmr-request-id"=>["5b0c8426-3a23-4025-a4d3-6d1c9024153a"], "vary"=>["Accept-Encoding, User-Agent"], "connection"=>["close"], "server"=>["Jetty(9.2.z-SNAPSHOT)"]}) - - stub_request(:get, "#{@cmr_base_url}/search/granules.echo10?concept_id=G309210-GHRC"). - with( - headers: { - 'Accept'=>'*/*', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - - }). - to_return(status: 200, body: get_stub('search_granules_G309210-GHRC.xml'), headers: {}) - stub_request(:get, "https://cmr.sit.earthdata.nasa.gov/search/granules.umm_json?concept_id=G309210-GHRC"). - with( - headers: { - 'Accept'=>'*/*', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'User-Agent'=>'Ruby' - }). - to_return(status: 200, body: get_stub('search_granules_G309210-GHRC.json'), headers: {}) + setup_show_stubs get '/collections/1', params: { record_id: 1 } - collection_records = assigns(:collection_records) - assert_equal(6, collection_records.length) + + assert_equal 6, assigns(:collection_records).length end it "redirects when no concept id is provided" do - #redirects no record_id sign_in(user) stub_urs_access(user.uid, user.access_token, user.refresh_token) - get '/collections/1', params: { } - assert_equal(response.code, "302") + get '/collections/1', params: {} + assert_redirected_to root_path end it "redirects when no collection is found" do - #redirects no collection found sign_in(user) stub_urs_access(user.uid, user.access_token, user.refresh_token) get '/collections/1', params: { record_id: "xyz" } - assert_equal(response.code, "302") + assert_redirected_to root_path end - it "detects if a granule is no longer in cmr" do + it "detects if a granule is no longer in CMR" do sign_in(user) stub_urs_access(user.uid, user.access_token, user.refresh_token) - - #stubbing all requests for raw_data - stub_request(:get, "#{@cmr_base_url}/search/granules.umm_json?concept_id=G309210-GHRC"). - with( - headers: { - 'Accept'=>'*/*', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'User-Agent'=>'Ruby' - }). - to_return(status: 200, body: '{"hits" : 0,"took" : 105,"items" : []}', headers: {}) - stub_request(:get, "#{@cmr_base_url}/search/collections.echo10?concept_id=C1000000020-LANCEAMSR2").with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', }).to_return(:status => 200, :body => get_stub('search_granules_by_collection_C1000000020-LANCEAMSR2.xml')) - - stub_request(:get, "#{@cmr_base_url}/search/granules.echo10?concept_id=G309210-GHRC"). - with( - headers: { - 'Accept'=>'*/*', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - - }). - to_return(status: 200, - body: '029', - headers: {}) + setup_granule_not_found_stubs get '/collections/1', params: { record_id: 1 } - assert_select "span[class='indicator_for_granule_deleted_in_cmr']", count: 5, - :text => '[Granule Not Found in CMR]' + + assert_select ".indicator_for_granule_deleted_in_cmr", count: 5, text: '[Granule Not Found in CMR]' end it "detects if a new granule revision is available" do sign_in(user) stub_urs_access(user.uid, user.access_token, user.refresh_token) + setup_granule_revision_stubs - stub_request(:get, "#{@cmr_base_url}/search/collections.echo10?concept_id=C1000000020-LANCEAMSR2"). - with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', }). - to_return(:status => 200, :body => get_stub('search_granules_by_collection_C1000000020-LANCEAMSR2.xml')) - - stub_request(:get, "#{@cmr_base_url}/search/granules.echo10?concept_id=G309210-GHRC"). - with( - headers: { - 'Accept'=>'*/*', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - - }). - to_return(status: 200, body: get_stub('search_granules_G309210-GHRC.xml'), headers: {}) - stub_request(:get, "#{@cmr_base_url}/search/granules.umm_json?concept_id=G309210-GHRC"). - with( - headers: { - 'Accept'=>'*/*', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'User-Agent'=>'Ruby' - }). - to_return(status: 200, body: get_stub('search_granules_G309210-GHRC.json'), headers: {}) get '/collections/1', params: { record_id: 1 } + assert_select '.import_new_revision', count: 5 end end - - describe "POST #create" do it "downloads and saves a new record" do sign_in(user) stub_urs_access(user.uid, user.access_token, user.refresh_token) + setup_create_stubs - stub_request(:get, Regexp.new("#{Regexp.escape(@cmr_base_url)}\\/search\\/collections\\.(echo10|native)\\?concept_id\\=C222702\\-GHRC")).with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', }).to_return(:status => 200, :body => get_stub("search_collection_C222702-GHRC.xml"), :headers => {"date"=>["Tue, 21 Feb 2017 15:50:04 GMT"], "content-type"=>["application/echo10+xml; charset=utf-8"], "access-control-expose-headers"=>["CMR-Hits, CMR-Request-Id"], "access-control-allow-origin"=>["*"], "cmr-hits"=>["1"], "cmr-took"=>["2974"], "cmr-request-id"=>["bb005bac-18ce-4b6a-b69f-3f29f820ced5"], "vary"=>["Accept-Encoding, User-Agent"], "connection"=>["close"], "server"=>["Jetty(9.2.z-SNAPSHOT)"]}) - #stubbing the new format check - stub_request(:get, "#{@cmr_base_url}/search/collections.atom?concept_id=C222702-GHRC").with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', }).to_return(:status => 200, :body => "ECHO10", :headers => {"date"=>["Fri, 17 Mar 2017 20:00:54 GMT"], "content-type"=>["application/echo10+xml; charset=utf-8"], "access-control-expose-headers"=>["CMR-Hits, CMR-Request-Id"], "access-control-allow-origin"=>["*"], "cmr-hits"=>["1"], "cmr-took"=>["107"], "cmr-request-id"=>["308d3b81-b229-4593-a05e-c61a741d45be"], "vary"=>["Accept-Encoding, User-Agent"], "connection"=>["close"], "server"=>["Jetty(9.2.z-SNAPSHOT)"], "strict-transport-security"=>["max-age=31536000"]}) - - #Since a granule is chosen at random, a full mock can not be used. - #in this instance, we return a set collection of results for any call using this concept id and granule keyword. - stub_request(:get, /.*granules.echo10*C222702-GHRC.*/).with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', }).to_return(:status => 200, :body => get_stub("search_granules_G309203-GHRC.xml"), :headers => {"date"=>["Tue, 21 Feb 2017 16:02:46 GMT"], "content-type"=>["application/echo10+xml; charset=utf-8"], "access-control-expose-headers"=>["CMR-Hits, CMR-Request-Id"], "access-control-allow-origin"=>["*"], "cmr-hits"=>["10554"], "cmr-took"=>["40"], "cmr-request-id"=>["5b0c8426-3a23-4025-a4d3-6d1c9024153a"], "vary"=>["Accept-Encoding, User-Agent"], "connection"=>["close"], "server"=>["Jetty(9.2.z-SNAPSHOT)"]}) - stub_request(:get, /.*granules.umm_json*C222702-GHRC.*/).with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', }).to_return(:status => 200, :body => get_stub("search_granules_G309203-GHRC.json"), :headers => {"date"=>["Tue, 21 Feb 2017 16:02:46 GMT"], "content-type"=>["application/echo10+xml; charset=utf-8"], "access-control-expose-headers"=>["CMR-Hits, CMR-Request-Id"], "access-control-allow-origin"=>["*"], "cmr-hits"=>["10554"], "cmr-took"=>["40"], "cmr-request-id"=>["5b0c8426-3a23-4025-a4d3-6d1c9024153a"], "vary"=>["Accept-Encoding, User-Agent"], "connection"=>["close"], "server"=>["Jetty(9.2.z-SNAPSHOT)"]}) - stub_request(:get, "https://cmr.sit.earthdata.nasa.gov/search/concepts/G226250-GHRC.echo10"). - with( - headers: { - 'Accept'=>'*/*', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'User-Agent'=>'Ruby' - }). - to_return(status: 200, body: "", headers: {}) - stub_request(:get, "https://cmr.sit.earthdata.nasa.gov/search/granules.umm_json?collection_concept_id=C222702-GHRC&page_num=1&page_size=10"). - with( - headers: { - 'Accept'=>'*/*', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'User-Agent'=>'Ruby' - }). - to_return(status: 200, body: get_stub("search_granules_G309203-GHRC.json"), headers: {}) - stub_request(:get, "https://cmr.sit.earthdata.nasa.gov/search/granules.umm_json?collection_concept_id=C222702-GHRC&page_num=2&page_size=10"). - with( - headers: { - 'Accept'=>'*/*', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'User-Agent'=>'Ruby' - }). - to_return(status: 200, body: get_stub("search_granules_G309203-GHRC.json"), headers: {}) - stub_request(:get, "https://cmr.sit.earthdata.nasa.gov/search/granules.umm_json?collection_concept_id=C222702-GHRC&page_num=3&page_size=10"). - with( - headers: { - 'Accept'=>'*/*', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'User-Agent'=>'Ruby' - }). - to_return(status: 200, body: get_stub("search_granules_G309203-GHRC.json"), headers: {}) - #stubbing the granule raw look up - stub_request(:get, /.*granules.echo10\?concept_id=G.*/).with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', }).to_return(:status => 200, :body => get_stub("search_granules_G226250-GHRC.xml"), :headers => {"date"=>["Tue, 14 Mar 2017 19:36:02 GMT"], "content-type"=>["application/echo10+xml; charset=utf-8"], "access-control-expose-headers"=>["CMR-Hits, CMR-Request-Id"], "access-control-allow-origin"=>["*"], "cmr-hits"=>["1"], "cmr-took"=>["26"], "cmr-request-id"=>["46ad6de7-598a-463e-99e0-2a22ddf651da"], "vary"=>["Accept-Encoding, User-Agent"], "connection"=>["close"], "server"=>["Jetty(9.2.z-SNAPSHOT)"], "strict-transport-security"=>["max-age=31536000"]}) - stub_request(:get, "#{@cmr_base_url}/search/concepts/C222702-GHRC.echo10"). - with( - headers: { - 'Accept'=>'*/*', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'User-Agent'=>'Ruby' - }). - to_return(status: 200, body: get_stub("C222702-GHRC_echo10.xml"), headers: {}) - stub_request(:get, "#{@cmr_base_url}/search/granules.umm_json?concept_id=G226250-GHRC"). - with( - headers: { - 'Accept'=>'*/*', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'User-Agent'=>'Ruby' - }). - to_return(status: 200, body: get_stub("search_granules_G226250-GHRC.json"), headers: {}) - - #Making sure record does not exist before ingest - assert_equal(0, (Collection.where concept_id: "C222702-GHRC").length) - Quarc.stub_any_instance(:validate, {}) do - post collections_url, params: { concept_id: "C222702-GHRC", revision_id: "32", granulesCount: 1 } + assert_difference 'Collection.where(concept_id: "C222702-GHRC").count', 1 do + Quarc.stub_any_instance(:validate, {}) do + post collections_url, params: { concept_id: "C222702-GHRC", revision_id: "32", granulesCount: 1 } + end end - assert_equal("302", response.code) - - #collection with rawJSON saved in system - assert_equal(1, (Collection.where concept_id: "C222702-GHRC").length) - assert_equal("daylightn", (Collection.where concept_id: "C222702-GHRC").first.records.first.values["ShortName"]) - - record = (Collection.where concept_id: "C222702-GHRC").first.records.first - #script ran on new collection - refute(record.binary_script_values["InsertTime"]) - - # collection with umm-json can be saved to system. see ticket CMRARC-480 - stub_request(:get, "https://cmr.sit.earthdata.nasa.gov/search/concepts/C190733714-LPDAAC_ECS.umm_json"). - with( - headers: { - 'Accept'=>'*/*', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'User-Agent'=>'Ruby' - }). - to_return(status: 200, body: get_stub("search_collection_C190733714-LPDAAC_ECS.json"), headers: {}) - stub_request(:get, "#{@cmr_base_url}/search/collections.atom?concept_id=C190733714-LPDAAC_ECS").with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', }).to_return(:status => 200, :body => get_stub("search_collection_C190733714-LPDAAC_ECS.atom"), :headers => {"date"=>["Fri, 17 Mar 2017 20:00:54 GMT"], "content-type"=>["application/echo10+xml; charset=utf-8"], "access-control-expose-headers"=>["CMR-Hits, CMR-Request-Id"], "access-control-allow-origin"=>["*"], "cmr-hits"=>["1"], "cmr-took"=>["107"], "cmr-request-id"=>["308d3b81-b229-4593-a05e-c61a741d45be"], "vary"=>["Accept-Encoding, User-Agent"], "connection"=>["close"], "server"=>["Jetty(9.2.z-SNAPSHOT)"], "strict-transport-security"=>["max-age=31536000"]}) - stub_request(:get, "#{@cmr_base_url}/search/collections.umm_json?concept_id=C190733714-LPDAAC_ECS").with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', }).to_return(:status => 200, :body => get_stub("search_collection_C190733714-LPDAAC_ECS.json"), :headers => {"date"=>["Tue, 21 Feb 2017 15:50:04 GMT"], "content-type"=>["application/vnd.nasa.cmr.umm_results+json;version=1.13; charset=UTF-8"], "access-control-expose-headers"=>["CMR-Hits, CMR-Request-Id"], "access-control-allow-origin"=>["*"], "cmr-hits"=>["1"], "cmr-took"=>["2974"], "cmr-request-id"=>["bb005bac-18ce-4b6a-b69f-3f29f820ced5"], "vary"=>["Accept-Encoding, User-Agent"], "connection"=>["close"], "server"=>["Jetty(9.2.z-SNAPSHOT)"]}) - stub_request(:get, /.*granules.echo10*C190733714-LPDAAC_ECS.*/).with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', }).to_return(status: 200, body: get_stub("search_granules_by_collection_C190733714-LPDAAC_ECS.xml"), headers: {}) - stub_request(:get, "#{@cmr_base_url}/search/granules.umm_json?collection_concept_id=C190733714-LPDAAC_ECS&page_size=10&page_num=1"). - with( - headers: { - 'Accept'=>'*/*', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'User-Agent'=>'Ruby' - }). - to_return(status: 200, body: get_stub("search_granules_by_collection_C190733714-LPDAAC_ECS.json"), headers: {}) - stub_request(:get, "https://cmr.sit.earthdata.nasa.gov/search/granules.umm_json?collection_concept_id=C190733714-LPDAAC_ECS&page_num=3&page_size=10"). - with( - headers: { - 'Accept'=>'*/*', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'User-Agent'=>'Ruby' - }). - to_return(status: 200, body: get_stub("search_granules_by_collection_C190733714-LPDAAC_ECS.json"), headers: {}) - stub_request(:get, "https://cmr.sit.earthdata.nasa.gov/search/granules.umm_json?collection_concept_id=C190733714-LPDAAC_ECS&page_num=2&page_size=10"). - with( - headers: { - 'Accept'=>'*/*', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'User-Agent'=>'Ruby' - }). - to_return(status: 200, body: get_stub("search_granules_by_collection_C190733714-LPDAAC_ECS.json"), headers: {}) - Quarc.stub_any_instance(:validate, {}) do - post collections_url, params: { concept_id: "C190733714-LPDAAC_ECS", revision_id: "77", granuleCounts: 1 } + + assert_redirected_to collection_path(assigns(:collection)) + assert_collection_and_granule_saved_correctly("C222702-GHRC") + end + + it "downloads and saves a new ISO record as UMM-JSON" do + sign_in(user) + stub_urs_access(user.uid, user.access_token, user.refresh_token) + setup_iso_record_stubs + + assert_difference 'Collection.where(concept_id: "C1599780765-NSIDC_ECS").count', 1 do + Quarc.stub_any_instance(:validate, {}) do + post collections_url, params: { concept_id: "C1599780765-NSIDC_ECS", revision_id: "77", granuleCounts: 1 } + end end - get '/collections/1', params: { concept_id: "C190733714-LPDAAC_ECS" } - assert_select "#record_format", count: 1, - :text => 'umm-c; version=1.13' + assert_redirected_to collection_path(assigns(:collection)) + assert_iso_record_saved_correctly("C1599780765-NSIDC_ECS") + end + end - assert_equal("200", response.code) - assert_equal(1, (Collection.where concept_id: "C190733714-LPDAAC_ECS").length) + private - #ingest for collection logged - assert_equal("abaker@element84.com", record.ingest.user.email) + def default_headers + { + 'Accept' => '*/*', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'User-Agent' => 'Ruby' + } + end - #saves 1 associated granule - assert_equal(1, (Collection.where concept_id: "C222702-GHRC").first.granules.length) - #needs to match regex since the granule that is taken from the list is random each time - assert_equal(0, (Collection.where concept_id: "C222702-GHRC").first.granules.first.records.first.values["GranuleUR"] =~ /Ndaily/) + def setup_show_stubs + stub_request(:get, "#{@cmr_base_url}/search/collections.echo10?concept_id=C1000000020-LANCEAMSR2") + .with(headers: default_headers) + .to_return(status: 200, body: get_stub("search_collection_C1000000020-LANCEAMSR2.xml")) - granule_record = (Collection.where concept_id: "C222702-GHRC").first.granules.first.records.first - #ingest for granule logged - assert_equal("abaker@element84.com", granule_record.ingest.user.email) - end + stub_request(:get, "#{@cmr_base_url}/search/granules.echo10?concept_id=G309210-GHRC") + .with(headers: default_headers) + .to_return(status: 200, body: get_stub('search_granules_G309210-GHRC.xml')) - it "downloads and saves a new iso record as umm-json" do - sign_in(user) - stub_urs_access(user.uid, user.access_token, user.refresh_token) + stub_request(:get, "https://cmr.sit.earthdata.nasa.gov/search/granules.umm_json?concept_id=G309210-GHRC") + .with(headers: default_headers) + .to_return(status: 200, body: get_stub('search_granules_G309210-GHRC.json')) + end - # the atom will return the native format is iso-19115 - stub_request(:get, "#{@cmr_base_url}/search/collections.atom?concept_id=C1599780765-NSIDC_ECS") - .with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', }) - .to_return(:status => 200, :body => get_stub("search_collection_C1599780765-NSIDC_ECS.atom"), - :headers => {"date"=>["Fri, 17 Mar 2017 20:00:54 GMT"], - "content-type"=>["application/atom+xml; charset=utf-8"], - "access-control-expose-headers"=>["CMR-Hits, CMR-Request-Id"], - "access-control-allow-origin"=>["*"], - "cmr-hits"=>["1"], - "cmr-took"=>["107"], - "cmr-request-id"=>["308d3b81-b229-4593-a05e-c61a741d45be"], - "vary"=>["Accept-Encoding, User-Agent"], - "connection"=>["close"], - "server"=>["Jetty(9.2.z-SNAPSHOT)"], - "strict-transport-security"=>["max-age=31536000"]}) - - # application logic should pull umm-json instead - stub_request(:get, "#{@cmr_base_url}/search/collections.umm_json?concept_id=C1599780765-NSIDC_ECS") - .with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', }) - .to_return(:status => 200, :body => get_stub("search_collection_C1599780765-NSIDC_ECS.json"), - :headers => {"date"=>["Tue, 21 Feb 2017 15:50:04 GMT"], - "content-type"=>["application/vnd.nasa.cmr.umm_results+json;version=1.13; charset=UTF-8"], - "access-control-expose-headers"=>["CMR-Hits, CMR-Request-Id"], - "access-control-allow-origin"=>["*"], - "cmr-hits"=>["1"], - "cmr-took"=>["2974"], - "cmr-request-id"=>["bb005bac-18ce-4b6a-b69f-3f29f820ced5"], - "vary"=>["Accept-Encoding, User-Agent"], - "connection"=>["close"], - "server"=>["Jetty(9.2.z-SNAPSHOT)"]}) - stub_request(:get, "https://cmr.sit.earthdata.nasa.gov/search/concepts/C1599780765-NSIDC_ECS.umm_json"). - with( - headers: { - 'Accept'=>'*/*', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'User-Agent'=>'Ruby' - }). - to_return(status: 200, body: get_stub("search_collection_C1599780765-NSIDC_ECS.json"), headers: {}) - # stub_request(:get, "https://cmr.sit.earthdata.nasa.gov/search/collections.umm_json?concept_id=C1599780765-NSIDC_ECS"). - # with( - # headers: { - # 'Accept'=>'*/*', - # 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - # 'User-Agent'=>'Ruby' - # }). - # to_return(status: 200, body: get_stub("search_collection_C1599780765-NSIDC_ECS.json"), headers: {}) - - # stub for pulling a random granule - stub_request(:get, /.*granules.echo10\?concept_id=G.*/) - .with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', }) - .to_return(:status => 200, :body => get_stub("search_granules_C1599780765-NSIDC_ECS.xml"), - :headers => {"date"=>["Tue, 14 Mar 2017 19:36:02 GMT"], - "content-type"=>["application/echo10+xml; charset=utf-8"], - "access-control-expose-headers"=>["CMR-Hits, CMR-Request-Id"], - "access-control-allow-origin"=>["*"], - "cmr-hits"=>["1"], "cmr-took"=>["26"], - "cmr-request-id"=>["46ad6de7-598a-463e-99e0-2a22ddf651da"], - "vary"=>["Accept-Encoding, User-Agent"], - "connection"=>["close"], - "server"=>["Jetty(9.2.z-SNAPSHOT)"], - "strict-transport-security"=>["max-age=31536000"]}) - - stub_request(:get, "#{@cmr_base_url}/search/granules.umm_json?collection_concept_id=C1599780765-NSIDC_ECS&page_size=10&page_num=1"). - with( - headers: { - 'Accept'=>'*/*', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'User-Agent'=>'Ruby' - }). - to_return(status: 200, body: get_stub('search_granules_by_collection_C1599780765-NSIDC_ECS.json'), headers: {}) - stub_request(:get, "#{Cmr.get_cmr_base_url}/search/granules.echo10?collection_concept_id=C1599780765-NSIDC_ECS&page_num=1&page_size=10"). - with( - headers: { - 'Accept'=>'*/*', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - - }). - to_return(status: 200, body: get_stub("search_granules_by_collection_C1599780765-NSIDC_ECS.xml"), headers: {}) - stub_request(:get, /.*granules.echo10*C1599780765-NSIDC_ECS.*/) - .with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', }) - .to_return(status: 200, body: get_stub("search_granules_by_collection_C1599780765-NSIDC_ECS.xml"), headers: {}) - stub_request(:get, "#{Cmr.get_cmr_base_url}/search/granules.umm_json?concept_id=G1599790933-NSIDC_ECS"). - with( - headers: { - 'Accept'=>'*/*', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'User-Agent'=>'Ruby' - }). - to_return(status: 200, body: get_stub("search_granules_G1599790933-NSIDC_ECS.json"), headers: {}) - stub_request(:get, "https://cmr.sit.earthdata.nasa.gov/search/concepts/G1599790933-NSIDC_ECS.echo10"). - with( - headers: { - 'Accept'=>'*/*', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'User-Agent'=>'Ruby' - }). - to_return(status: 200, body: "", headers: {}) - Quarc.stub_any_instance(:validate, {}) do - post collections_url, params: { concept_id: "C1599780765-NSIDC_ECS", revision_id: "77", granuleCounts: 1 } - end - assert_equal("302", response.code) - assert_equal(1, (Collection.where concept_id: "C1599780765-NSIDC_ECS").length) + def setup_granule_not_found_stubs + stub_request(:get, "#{@cmr_base_url}/search/granules.umm_json?concept_id=G309210-GHRC") + .with(headers: default_headers) + .to_return(status: 200, body: '{"hits" : 0,"took" : 105,"items" : []}') - record = (Collection.where concept_id: "C1599780765-NSIDC_ECS").first.records.first + stub_request(:get, "#{@cmr_base_url}/search/collections.echo10?concept_id=C1000000020-LANCEAMSR2") + .with(headers: default_headers) + .to_return(status: 200, body: get_stub('search_granules_by_collection_C1000000020-LANCEAMSR2.xml')) + stub_request(:get, "#{@cmr_base_url}/search/granules.echo10?concept_id=G309210-GHRC") + .with(headers: default_headers) + .to_return(status: 200, body: '029') + end + + def setup_granule_revision_stubs + stub_request(:get, "#{@cmr_base_url}/search/collections.echo10?concept_id=C1000000020-LANCEAMSR2") + .with(headers: default_headers) + .to_return(status: 200, body: get_stub('search_granules_by_collection_C1000000020-LANCEAMSR2.xml')) - assert_equal"iso19115", record.native_format - assert_equal"umm_json", record.format + stub_request(:get, "#{@cmr_base_url}/search/granules.echo10?concept_id=G309210-GHRC") + .with(headers: default_headers) + .to_return(status: 200, body: get_stub('search_granules_G309210-GHRC.xml')) - #ingest for collection logged - assert_equal("abaker@element84.com", record.ingest.user.email) + stub_request(:get, "#{@cmr_base_url}/search/granules.umm_json?concept_id=G309210-GHRC") + .with(headers: default_headers) + .to_return(status: 200, body: get_stub('search_granules_G309210-GHRC.json')) + end - #saves 1 associated granule - assert_equal(1, (Collection.where concept_id: "C1599780765-NSIDC_ECS").first.granules.length) - #needs to match regex since the granule that is taken from the list is random each time - assert_equal(0, (Collection.where concept_id: "C1599780765-NSIDC_ECS").first.granules.first.records.first.values["GranuleUR"] =~ /SC:ABLVIS0/) + def setup_create_stubs + stub_request(:get, "#{@cmr_base_url}/search/collections.echo10?concept_id=C222702-GHRC") + .with(headers: default_headers) + .to_return(status: 200, body: get_stub("search_collection_C222702-GHRC.xml")) - granule_record = (Collection.where concept_id: "C1599780765-NSIDC_ECS").first.granules.first.records.first - #ingest for granule logged - assert_equal("abaker@element84.com", granule_record.ingest.user.email) + stub_request(:get, /.*granules.echo10*C222702-GHRC.*/) + .with(headers: default_headers) + .to_return(status: 200, body: get_stub("search_granules_G309203-GHRC.xml")) - end + stub_request(:get, /.*granules.umm_json*C222702-GHRC.*/) + .with(headers: default_headers) + .to_return(status: 200, body: get_stub("search_granules_G309203-GHRC.json")) + end + + def setup_iso_record_stubs + stub_request(:get, "#{@cmr_base_url}/search/collections.atom?concept_id=C1599780765-NSIDC_ECS") + .with(headers: default_headers) + .to_return(status: 200, body: get_stub("search_collection_C1599780765-NSIDC_ECS.atom")) + + stub_request(:get, "#{@cmr_base_url}/search/collections.umm_json?concept_id=C1599780765-NSIDC_ECS") + .with(headers: default_headers) + .to_return(status: 200, body: get_stub("search_collection_C1599780765-NSIDC_ECS.json")) + + stub_request(:get, /.*granules.echo10\?concept_id=G.*/) + .with(headers: default_headers) + .to_return(status: 200, body: get_stub("search_granules_C1599780765-NSIDC_ECS.xml")) + stub_request(:get, "#{@cmr_base_url}/search/granules.umm_json?collection_concept_id=C1599780765-NSIDC_ECS&page_size=10&page_num=1") + .with(headers: default_headers) + .to_return(status: 200, body: get_stub('search_granules_by_collection_C1599780765-NSIDC_ECS.json')) + + stub_request(:get, "#{@cmr_base_url}/search/granules.umm_json?concept_id=G1599790933-NSIDC_ECS") + .with(headers: default_headers) + .to_return(status: 200, body: get_stub("search_granules_G1599790933-NSIDC_ECS.json")) + end + + def assert_collection_and_granule_saved_correctly(concept_id) + collection = Collection.find_by(concept_id: concept_id) + assert collection.present? + assert_equal "abaker@element84.com", collection.records.first.ingest.user.email + assert_equal 1, collection.granules.count + granule = collection.granules.first + assert_match /Ndaily/, granule.records.first.values["GranuleUR"] + assert_equal "abaker@element84.com", granule.records.first.ingest.user.email end + def assert_iso_record_saved_correctly(concept_id) + collection = Collection.find_by(concept_id: concept_id) + assert collection.present? + record = collection.records.first + assert_equal "iso19115", record.native_format + assert_equal "umm_json", record.format + assert_equal "abaker@element84.com", record.ingest.user.email + assert_equal 1, collection.granules.count + granule = collection.granules.first + assert_match /SC:ABLVIS0/, granule.records.first.values["GranuleUR"] + assert_equal "abaker@element84.com", granule.records.first.ingest.user.email + end end