Skip to content

Commit

Permalink
Updated the issue with unit test failure for metrics skeleton creation
Browse files Browse the repository at this point in the history
  • Loading branch information
deoyani committed Dec 8, 2023
1 parent 09a2ac4 commit 7713bf9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 5 additions & 7 deletions python/nistoar/rmm/mongo/nerdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ def init_metrics_for(db, nerdm):
"""
#Convert nderm dict to an array of dict
#nerdm_use = [nerdm]

record_collection_fields = {
"pdrid": None,
"ediid":None,
Expand All @@ -313,7 +312,7 @@ def init_metrics_for(db, nerdm):
record_fields = ['pdrid', 'ediid']

files_collection_fields = {
"pdrid": None,
"pdrid": None,
"ediid":None,
"filesize": 0,
"success_get" : 0,
Expand All @@ -326,8 +325,8 @@ def init_metrics_for(db, nerdm):
"last_time_logged" : None,
"downloadURL": None
}

nerdm['pdrid'] = nerdm.pop('@id')

records = {}
#Copy fields
for field in record_fields:
Expand All @@ -337,13 +336,11 @@ def init_metrics_for(db, nerdm):
for col in record_collection_fields.keys():
if col not in records.keys():
records[col] = record_collection_fields[col]
print("RecordsMetrics Creation")
db["recordMetrics"].insert_one(records)


#Get files from record components
files = flatten_records(nerdm, record_fields, files_collection_fields)
print("FileMetrics Creation")
db["fileMetrics"].insert_many(files)


Expand All @@ -370,7 +367,8 @@ def flatten_records(record, record_fields, initialize_fields):
file_dict[key] = record[key]
#Initialize other fields
for key in initialize_fields.keys():
file_dict[key] = initialize_fields[key]
files.append(file_dict)
if(key not in file_dict.keys()):
file_dict[key] = initialize_fields[key]
files.append(file_dict)
return files

4 changes: 3 additions & 1 deletion python/tests/nistoar/rmm/mongo/test_nerdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ def test_load_from_file(self):
def test_init_metrics_for(self):
with open(pdrfile) as fd:
rec = json.load(fd)


# print(" **** TEST ****", rec)
# this record has files in it
self.assertTrue(any(['/od/ds/' in f.get('downloadURL','') for f in rec.get('components',[])]))

Expand All @@ -198,6 +199,7 @@ def test_init_metrics_for(self):
c = self.ldr._client.get_database().recordMetrics.find()
self.assertEqual(c[0]['pdrid'], 'ark:/88434/mds2-2106')
c = self.ldr._client.get_database().fileMetrics.find()
# print(" TEST ****", c[0])
self.assertEqual(c[0]['pdrid'], 'ark:/88434/mds2-2106')
# replace this with checks of successful loading into the database
#self.fail("Tests not implemented")
Expand Down

0 comments on commit 7713bf9

Please sign in to comment.