Skip to content

Commit

Permalink
Changes to make UUID value handling a little more generalizable when … (
Browse files Browse the repository at this point in the history
#259)

* Changes to make UUID value handling a little more generalizable when making object hashlists for use in EUS syncing

* Refactoring for less complexity

* Style fix

* Fixing test glitch

* More additions to the hashlist generating code

* More code fixes

* Have I mentioned recently how much I despise Code Climate??

* More fixes

* Style fixes

* Fixing test

* Testing fix

* More test fixes

* test fixes

* Testing fixes
  • Loading branch information
kauberry authored and dmlb2000 committed Oct 30, 2019
1 parent db987f5 commit baa794d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
20 changes: 13 additions & 7 deletions pacifica/metadata/orm/base.py
Expand Up @@ -249,27 +249,33 @@ def last_change_date(cls):
return text_type(last_change_string)

@classmethod
def available_hash_list(cls, columns=None):
def available_hash_list(cls, columns_and_where_clause=None):
"""
Generate a hashable structure of all keys and values of keys.
This structure allows for easy evaluation of updates or current vs old data
for any object in the database.
"""
where_clause = {k: v for k, v in columns_and_where_clause.items() if v}
columns = columns_and_where_clause.keys()

if not columns:
columns = cls.get_primary_keys()

hash_list = []
hash_dict = {}
all_keys_query = cls.select(*[getattr(cls, key) for key in columns]).dicts()
# all_keys_query = cls.select(*[getattr(cls, key) for key in columns])
all_keys_query = cls.select().where(cls.where_clause(where_clause))

# pylint: disable=no-value-for-parameter
for obj in all_keys_query.execute():
for entry in all_keys_query.execute():
# pylint: enable=no-value-for-parameter
inst_key = index_hash(*obj.values())
obj = entry.to_hash()
reporting_columns = {k: obj[k] for k in columns if k in obj}
inst_key = index_hash(*reporting_columns.values())
hash_list.append(inst_key)
if 'uuid' in obj:
obj['uuid'] = str(obj['uuid'])
entry = {
'key_list': obj,
'key_list': reporting_columns,
'index_hash': inst_key
}
hash_dict[inst_key] = entry
Expand Down
2 changes: 1 addition & 1 deletion pacifica/metadata/rest/objectinfo.py
Expand Up @@ -48,7 +48,7 @@ def GET(cls, object_class_name=None, operation=None, **where_clause):

myclass = ObjectInfoAPI.get_class_object_from_name(object_class_name)
if operation == 'hashlist':
available_hash_list, hash_dict = myclass.available_hash_list(where_clause.keys())
available_hash_list, hash_dict = myclass.available_hash_list(where_clause)
js_object = {
'hash_list': available_hash_list,
'hash_lookup': hash_dict
Expand Down
3 changes: 1 addition & 2 deletions tests/orm/available_hash_list_test.py
Expand Up @@ -51,13 +51,12 @@ def test_hash_list_with_keys(self):
self.base_create_obj(Keys, sample_key2)
self.base_create_obj(Keys, sample_key3)
third_obj = Keys()
hash_list, hash_dict = third_obj.available_hash_list()
hash_list, hash_dict = third_obj.available_hash_list({'key': None, 'encoding': None})
self.assertTrue(len(hash_list) == 3)
# some sanity checking for the layout of the two objects
for hashed_key in hash_list:
self.assertTrue(hashed_key in hash_dict)
obj_key_meta = hash_dict[hashed_key]
self.assertTrue('index_hash' in obj_key_meta)
self.assertTrue('key_list' in obj_key_meta)
self.assertTrue('id' in obj_key_meta['key_list'])
self.assertTrue(hashed_key == obj_key_meta['index_hash'])

0 comments on commit baa794d

Please sign in to comment.