Skip to content

Commit

Permalink
#119: Fix foreign keys not being added to dictionary conversions
Browse files Browse the repository at this point in the history
- The edits to test data return the tests back to how they should be, where they were edited to test what was going on
  • Loading branch information
MRichards99 committed Jan 28, 2021
1 parent 1f05f6c commit 42739e4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
16 changes: 3 additions & 13 deletions datagateway_api/common/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,9 @@ def to_dict(self):
"""
dictionary = {}
for column in self.__table__.columns:
camel_case_column_name = None
attribute = None

# Case insensitive alternative to getattr() - needed because column names
# are defined in SNAKE_CASE, class column variables named using camelCase to
# match Python ICAT backend
for a in dir(self):
if a.lower() == column.name.replace("_", "").lower():
attribute = getattr(self, a)
camel_case_column_name = a

if camel_case_column_name is not None and attribute is not None:
dictionary[camel_case_column_name] = self._make_serializable(attribute)
attribute_field_name = self.__mapper__.get_property_by_column(column).key
attribute = getattr(self, attribute_field_name)
dictionary[attribute_field_name] = self._make_serializable(attribute)

return dictionary

Expand Down
6 changes: 3 additions & 3 deletions test/db/test_entity_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ def test_valid_to_dict(self, datafile_entity):
"fileSize": 64,
"datafileModTime": str(Constants.TEST_MOD_CREATE_DATETIME),
"datafileCreateTime": str(Constants.TEST_MOD_CREATE_DATETIME),
"dataset1": 1,
"dataset": 1,
"doi": "test doi",
"description": "test description",
"createId": "test create id",
"modId": "test mod id",
"datafileFormat1": 1,
"datafileFormat": 1,
"createTime": str(Constants.TEST_MOD_CREATE_DATETIME),
}

Expand Down Expand Up @@ -189,7 +189,7 @@ def test_valid_update_from_dict(self, datafile_entity):
"description": "test description",
"createId": "test create id",
"modId": "test mod id",
"datefileFormat": 1,
"datafileFormat": 1,
"createTime": str(Constants.TEST_MOD_CREATE_DATETIME),
}

Expand Down

0 comments on commit 42739e4

Please sign in to comment.