Skip to content
This repository has been archived by the owner on Feb 20, 2022. It is now read-only.

Commit

Permalink
fixed saving of Pointer to User
Browse files Browse the repository at this point in the history
  • Loading branch information
farin committed Jul 20, 2014
1 parent ffacfc4 commit efb00e4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
13 changes: 9 additions & 4 deletions parse_rest/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def convert_from_parse(parse_data):
if not is_parse_type:
return parse_data

native = ParseType.type_mapping.get(parse_data['__type'])
native = ParseType.type_mapping.get(parse_data.pop('__type'))
return native.from_native(**parse_data) if native else parse_data

@staticmethod
Expand Down Expand Up @@ -93,7 +93,7 @@ def __init__(self, obj):
def _to_native(self):
return {
'__type': 'Pointer',
'className': self._object.__class__.__name__,
'className': self._object.className,
'objectId': self._object.objectId
}

Expand All @@ -102,7 +102,7 @@ def _to_native(self):
class EmbeddedObject(ParseType):
@classmethod
def from_native(cls, **kw):
klass = Object.factory(kw.get('className'))
klass = Object.factory(kw.pop('className'))
return klass(**kw)


Expand Down Expand Up @@ -284,8 +284,13 @@ def delete(self, batch=False):
if batch:
return response, lambda response_dict: None

@property
def className(self):
return self.__class__.__name__

_absolute_url = property(lambda self: '/'.join([self.__class__.ENDPOINT_ROOT, self.objectId]))
@property
def _absolute_url(self):
return '%s/%s' % (self.__class__.ENDPOINT_ROOT, self.objectId)

createdAt = property(_get_created_datetime, _set_created_datetime)
updatedAt = property(_get_updated_datetime, _set_updated_datetime)
Expand Down
11 changes: 10 additions & 1 deletion parse_rest/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from parse_rest.core import ResourceRequestNotFound
from parse_rest.connection import register, ParseBatcher
from parse_rest.datatypes import GeoPoint, Object, Function
from parse_rest.datatypes import GeoPoint, Object, Function, Pointer
from parse_rest.user import User
from parse_rest import query
from parse_rest.installation import Push
Expand Down Expand Up @@ -170,6 +170,15 @@ def testBatch(self):
"batch_delete didn't delete objects")


class TestPointer(unittest.TestCase):

def testToNative(self):
ptr = Pointer(GameScore(objectId='xyz'))
self.assertEqual(ptr._to_native(), dict(__type='Pointer', className='GameScore', objectId='xyz'))
ptr = Pointer(User(objectId='dh56yz', username="dhelmet@spaceballs.com"))
self.assertEqual(ptr._to_native(), dict(__type='Pointer', className='_User', objectId='dh56yz'))


class TestTypes(unittest.TestCase):
def setUp(self):
self.now = datetime.datetime.now()
Expand Down
4 changes: 4 additions & 0 deletions parse_rest/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ def _to_native(self):
return dict([(k, ParseType.convert_to_parse(v, as_pointer=True))
for k, v in self._editable_attrs.items()])

@property
def className(self):
return '_User'

def __repr__(self):
return '<User:%s (Id %s)>' % (self.username, self.objectId)

Expand Down

0 comments on commit efb00e4

Please sign in to comment.