Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 133 doidatasets primary key #134

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions metadata/orm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ def _build_object(self, attr):
@staticmethod
def get_append_item(obj_ref, fk_item_name, fk_obj_list):
"""Generate the proper item to append to the newly built object."""
# pylint: disable=protected-access
if 'key' in fk_obj_list.values() and 'value' in fk_obj_list.values():
append_item = {
'key_id': obj_ref.__data__['key'],
Expand All @@ -169,10 +168,13 @@ def _generate_fk_obj_list(self, obj_ref):
fk_obj_list = obj_ref.cls_foreignkey_rel_mods()
valid_fk_obj_list = list(
set(fk_obj_list) - set([self.__class__]))
# pylint: disable=protected-access
if len(valid_fk_obj_list) == 1:
fk_item_name = fk_obj_list[valid_fk_obj_list.pop()]
else:
fk_item_name = 'id'
fk_item_name = obj_ref.__class__._meta.__dict__[
'primary_key'].__dict__['column_name']
# pylint: enable=protected-access
return fk_item_name, fk_obj_list

def from_hash(self, obj):
Expand Down
2 changes: 1 addition & 1 deletion metadata/orm/doi_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DOIRelease(CherryPyAPI):
"""

doi = ForeignKeyField(
DOIDataSets, related_name='doi_releases', to_field='doi')
DOIDataSets, related_name='doi_entries', to_field='doi')
release = ForeignKeyField(TransactionRelease, related_name='doi_releases')

# pylint: disable=too-few-public-methods
Expand Down
2 changes: 1 addition & 1 deletion metadata/orm/doidatasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DOIDataSets(CherryPyAPI):
+-------------------+-------------------------------------+
"""

doi = CharField(unique=True)
doi = CharField(primary_key=True)
name = CharField(default='')
encoding = CharField(default='UTF8')
creator = ForeignKeyField(Users, related_name='dois_created')
Expand Down
4 changes: 4 additions & 0 deletions metadata/orm/test/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ def base_test_hash(self, obj_hash):
check all keys in the new hash from the obj_hash passed
"""
obj = self.base_create_obj(self.obj_cls, obj_hash)
# pylint: disable=no-member
new_obj = self.obj_cls.get(
self.obj_id == getattr(obj, self.obj_id.column_name))
# pylint: enable=no-member
chk_obj_hash = new_obj.to_hash()
self.assertTrue('_id' in chk_obj_hash)
for key in obj_hash.keys():
Expand All @@ -91,8 +93,10 @@ def base_test_json(self, json_str):
obj = self.obj_cls()
obj.from_hash(loads(json_str))
obj.save(force_insert=True)
# pylint: disable=no-member
new_obj = self.obj_cls.get(
self.obj_id == getattr(obj, self.obj_id.column_name))
# pylint: enable=no-member
chk_obj_json = dumps(new_obj.to_hash())
self.assertEqual(type(chk_obj_json), str)

Expand Down
4 changes: 1 addition & 3 deletions metadata/orm/test/test_doidatasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from metadata.orm.users import Users

SAMPLE_DOIDATASET_HASH = {
'_id': 142,
'doi': 'halitosis',
'name': 'halitosis',
'encoding': 'UTF8',
Expand All @@ -19,7 +18,6 @@
# yes a DOI can be unicode....
# https://www.doi.org/doi_handbook/2_Numbering.html#2.2.1
SAMPLE_UNICODE_DOIDATASET_HASH = {
'_id': 143,
'doi': u'blargééééé',
'name': u'blargééééé',
'encoding': 'UTF8',
Expand All @@ -31,7 +29,7 @@ class TestDOIDataSets(TestBase):
"""Test the Keywords ORM object."""

obj_cls = DOIDataSets
obj_id = DOIDataSets.id
obj_id = DOIDataSets.doi

@classmethod
def base_create_dep_objs(cls):
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mock
nose
peewee>2
pep257
psycopg2
psycopg2-binary
pylint
pytest
python-dateutil
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cherrypy
elasticsearch
peewee>2
psycopg2
psycopg2-binary
python-dateutil
requests
six