Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
ParsePy
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ParsePy
Commits
e5b911a4
Commit
e5b911a4
authored
Jan 14, 2013
by
David Robinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modifications to make fully pep8 compliant
parent
bc7aa3cd
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
24 deletions
+42
-24
parse_rest/__init__.py
+38
-20
parse_rest/tests.py
+4
-4
No files found.
parse_rest/__init__.py
View file @
e5b911a4
...
@@ -25,6 +25,7 @@ API_ROOT = 'https://api.parse.com/1'
...
@@ -25,6 +25,7 @@ API_ROOT = 'https://api.parse.com/1'
APPLICATION_ID
=
''
APPLICATION_ID
=
''
REST_API_KEY
=
''
REST_API_KEY
=
''
class
ParseBinaryDataWrapper
(
str
):
class
ParseBinaryDataWrapper
(
str
):
pass
pass
...
@@ -73,7 +74,7 @@ class ParseBase(object):
...
@@ -73,7 +74,7 @@ class ParseBase(object):
@property
@property
def
_attributes
(
self
):
def
_attributes
(
self
):
# return "public" attributes converted to the base parse representation
.
# return "public" attributes converted to the base parse representation
return
dict
([
return
dict
([
self
.
_convertToParseType
(
p
)
for
p
in
self
.
__dict__
.
items
()
self
.
_convertToParseType
(
p
)
for
p
in
self
.
__dict__
.
items
()
if
p
[
0
][
0
]
!=
'_'
if
p
[
0
][
0
]
!=
'_'
...
@@ -87,7 +88,8 @@ class ParseBase(object):
...
@@ -87,7 +88,8 @@ class ParseBase(object):
def
_ISO8601ToDatetime
(
self
,
date_string
):
def
_ISO8601ToDatetime
(
self
,
date_string
):
# TODO: verify correct handling of timezone
# TODO: verify correct handling of timezone
date_string
=
date_string
[:
-
1
]
+
'UTC'
date_string
=
date_string
[:
-
1
]
+
'UTC'
return
datetime
.
datetime
.
strptime
(
date_string
,
'
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S.
%
f
%
Z'
)
return
datetime
.
datetime
.
strptime
(
date_string
,
'
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S.
%
f
%
Z'
)
def
_convertToParseType
(
self
,
prop
):
def
_convertToParseType
(
self
,
prop
):
key
,
value
=
prop
key
,
value
=
prop
...
@@ -124,16 +126,19 @@ class ParseResource(ParseBase):
...
@@ -124,16 +126,19 @@ class ParseResource(ParseBase):
def
retrieve
(
cls
,
resource_id
):
def
retrieve
(
cls
,
resource_id
):
return
cls
(
**
cls
.
GET
(
'/'
+
resource_id
))
return
cls
(
**
cls
.
GET
(
'/'
+
resource_id
))
_absolute_url
=
property
(
lambda
self
:
'/'
.
join
([
self
.
__class__
.
ENDPOINT_ROOT
+
self
.
_object_id
]))
_absolute_url
=
property
(
lambda
self
:
'/'
.
join
(
[
self
.
__class__
.
ENDPOINT_ROOT
+
self
.
_object_id
]))
def
objectId
(
self
):
def
objectId
(
self
):
return
self
.
_object_id
return
self
.
_object_id
def
updatedAt
(
self
):
def
updatedAt
(
self
):
return
(
self
.
_updated_at
and
self
.
_ISO8601ToDatetime
(
self
.
_updated_at
)
or
None
)
return
(
self
.
_updated_at
and
self
.
_ISO8601ToDatetime
(
self
.
_updated_at
)
or
None
)
def
createdAt
(
self
):
def
createdAt
(
self
):
return
(
self
.
_created_at
and
self
.
_ISO8601ToDatetime
(
self
.
_created_at
)
or
None
)
return
(
self
.
_created_at
and
self
.
_ISO8601ToDatetime
(
self
.
_created_at
)
or
None
)
class
User
(
ParseResource
):
class
User
(
ParseResource
):
...
@@ -145,18 +150,21 @@ class User(ParseResource):
...
@@ -145,18 +150,21 @@ class User(ParseResource):
@classmethod
@classmethod
def
login
(
cls
,
username
,
password
):
def
login
(
cls
,
username
,
password
):
return
cls
.
GET
(
'/'
.
join
([
API_ROOT
,
'login'
]),
username
=
username
,
password
=
password
)
return
cls
.
GET
(
'/'
.
join
([
API_ROOT
,
'login'
]),
username
=
username
,
password
=
password
)
@classmethod
@classmethod
def
request_password_reset
(
cls
,
email
):
def
request_password_reset
(
cls
,
email
):
return
cls
.
POST
(
'/'
.
join
([
API_ROOT
,
'requestPasswordReset'
]),
email
=
email
)
return
cls
.
POST
(
'/'
.
join
([
API_ROOT
,
'requestPasswordReset'
]),
email
=
email
)
def
save
(
self
,
session
=
None
):
def
save
(
self
,
session
=
None
):
session_header
=
{
'X-Parse-Session-Token'
:
session
and
session
.
get
(
'sessionToken'
)
}
session_header
=
{
'X-Parse-Session-Token'
:
session
and
session
.
get
(
'sessionToken'
)}
return
self
.
__class__
.
PUT
(
return
self
.
__class__
.
PUT
(
self
.
_absolute_url
,
extra_headers
=
session_header
,
**
self
.
_attributes
self
.
_absolute_url
,
extra_headers
=
session_header
,
)
**
self
.
_attributes
)
class
Installation
(
ParseResource
):
class
Installation
(
ParseResource
):
...
@@ -237,7 +245,8 @@ class Object(ParseResource):
...
@@ -237,7 +245,8 @@ class Object(ParseResource):
elif
value
[
'__type'
]
==
'Date'
:
elif
value
[
'__type'
]
==
'Date'
:
value
=
self
.
_ISO8601ToDatetime
(
value
[
'iso'
])
value
=
self
.
_ISO8601ToDatetime
(
value
[
'iso'
])
elif
value
[
'__type'
]
==
'Bytes'
:
elif
value
[
'__type'
]
==
'Bytes'
:
value
=
ParseBinaryDataWrapper
(
base64
.
b64decode
(
value
[
'base64'
]))
value
=
ParseBinaryDataWrapper
(
base64
.
b64decode
(
value
[
'base64'
]))
elif
value
[
'__type'
]
==
'GeoPoint'
:
elif
value
[
'__type'
]
==
'GeoPoint'
:
value
=
'POINT(
%
s
%
s)'
%
(
value
[
'longitude'
],
value
=
'POINT(
%
s
%
s)'
%
(
value
[
'longitude'
],
value
[
'latitude'
])
value
[
'latitude'
])
...
@@ -266,17 +275,21 @@ class Object(ParseResource):
...
@@ -266,17 +275,21 @@ class Object(ParseResource):
response_dict
=
self
.
__class__
.
PUT
(
uri
,
**
self
.
_attributes
)
response_dict
=
self
.
__class__
.
PUT
(
uri
,
**
self
.
_attributes
)
self
.
_updated_at
=
response_dict
[
'updatedAt'
]
self
.
_updated_at
=
response_dict
[
'updatedAt'
]
class
Push
(
ParseResource
):
class
Push
(
ParseResource
):
ENDPOINT_ROOT
=
'/'
.
join
([
API_ROOT
,
'push'
])
ENDPOINT_ROOT
=
'/'
.
join
([
API_ROOT
,
'push'
])
@classmethod
@classmethod
def
send
(
cls
,
message
,
channels
=
None
,
**
kw
):
def
send
(
cls
,
message
,
channels
=
None
,
**
kw
):
alert_message
=
{
'alert'
:
message
}
alert_message
=
{
'alert'
:
message
}
targets
=
{}
targets
=
{}
if
channels
:
targets
[
'channels'
]
=
channels
if
channels
:
if
kw
:
targets
[
'where'
]
=
kw
targets
[
'channels'
]
=
channels
if
kw
:
targets
[
'where'
]
=
kw
return
cls
.
POST
(
''
,
data
=
alert_message
,
**
targets
)
return
cls
.
POST
(
''
,
data
=
alert_message
,
**
targets
)
class
Query
(
ParseBase
):
class
Query
(
ParseBase
):
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -338,7 +351,8 @@ class Query(ParseBase):
...
@@ -338,7 +351,8 @@ class Query(ParseBase):
options
.
update
({
'where'
:
where
})
options
.
update
({
'where'
:
where
})
response
=
self
.
__class__
.
GET
(
''
,
**
options
)
response
=
self
.
__class__
.
GET
(
''
,
**
options
)
return
[
self
.
__class__
.
QUERY_CLASS
(
**
result
)
for
result
in
response
[
'results'
]]
return
[
self
.
__class__
.
QUERY_CLASS
(
**
result
)
for
result
in
response
[
'results'
]]
class
ObjectQuery
(
Query
):
class
ObjectQuery
(
Query
):
...
@@ -359,7 +373,8 @@ class ObjectQuery(Query):
...
@@ -359,7 +373,8 @@ class ObjectQuery(Query):
# HTTP Verb: GET
# HTTP Verb: GET
if
self
.
_object_id
:
if
self
.
_object_id
:
response
=
self
.
__class__
.
GET
(
'/
%
s/
%
s'
%
(
self
.
_class_name
,
self
.
_object_id
))
response
=
self
.
__class__
.
GET
(
'/
%
s/
%
s'
%
(
self
.
_class_name
,
self
.
_object_id
))
else
:
else
:
options
=
dict
(
self
.
_options
)
# make a local copy
options
=
dict
(
self
.
_options
)
# make a local copy
if
self
.
_where
:
if
self
.
_where
:
...
@@ -372,7 +387,8 @@ class ObjectQuery(Query):
...
@@ -372,7 +387,8 @@ class ObjectQuery(Query):
if
single_result
:
if
single_result
:
return
Object
(
self
.
_class_name
,
response
)
return
Object
(
self
.
_class_name
,
response
)
else
:
else
:
return
[
Object
(
self
.
_class_name
,
result
)
for
result
in
response
[
'results'
]]
return
[
Object
(
self
.
_class_name
,
result
)
for
result
in
response
[
'results'
]]
class
UserQuery
(
Query
):
class
UserQuery
(
Query
):
...
@@ -391,6 +407,8 @@ class InstallationQuery(Query):
...
@@ -391,6 +407,8 @@ class InstallationQuery(Query):
where
=
json
.
dumps
(
self
.
_where
)
where
=
json
.
dumps
(
self
.
_where
)
options
.
update
({
'where'
:
where
})
options
.
update
({
'where'
:
where
})
extra_headers
=
{
'X-Parse-Master-Key'
:
MASTER_KEY
}
extra_headers
=
{
'X-Parse-Master-Key'
:
MASTER_KEY
}
response
=
self
.
__class__
.
GET
(
''
,
extra_headers
=
extra_headers
,
**
options
)
response
=
self
.
__class__
.
GET
(
''
,
extra_headers
=
extra_headers
,
return
[
self
.
__class__
.
QUERY_CLASS
(
**
result
)
for
result
in
response
[
'results'
]]
**
options
)
return
[
self
.
__class__
.
QUERY_CLASS
(
**
result
)
for
result
in
response
[
'results'
]]
parse_rest/tests.py
View file @
e5b911a4
...
@@ -11,9 +11,8 @@ import __init__ as parse_rest
...
@@ -11,9 +11,8 @@ import __init__ as parse_rest
try
:
try
:
import
settings_local
import
settings_local
except
ImportError
:
except
ImportError
:
raise
ImportError
(
raise
ImportError
(
'You must create a settings_local.py file with an '
+
'You must create a settings_local.py file with an example application to run tests'
'example application to run tests'
)
)
parse_rest
.
APPLICATION_ID
=
settings_local
.
APPLICATION_ID
parse_rest
.
APPLICATION_ID
=
settings_local
.
APPLICATION_ID
parse_rest
.
REST_API_KEY
=
settings_local
.
REST_API_KEY
parse_rest
.
REST_API_KEY
=
settings_local
.
REST_API_KEY
...
@@ -36,7 +35,8 @@ def test_obj(saved=False):
...
@@ -36,7 +35,8 @@ def test_obj(saved=False):
class
TestObjectAndQuery
(
unittest
.
TestCase
):
class
TestObjectAndQuery
(
unittest
.
TestCase
):
"""
"""
Tests for the parse_rest.Object interface for creating and updating Parse
Tests for the parse_rest.Object interface for creating and updating Parse
objects, as well as the parse_rest.ObjectQuery interface for retrieving them
objects, as well as the parse_rest.ObjectQuery interface for retrieving
them
"""
"""
def
check_test_obj
(
self
,
o
):
def
check_test_obj
(
self
,
o
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment