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
a48cadb1
Commit
a48cadb1
authored
Oct 06, 2014
by
David Robinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #59 from dgadling/master
Fix the relatedTo Query operator
parents
9b67ee0c
b7fb7947
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
1 deletions
+40
-1
parse_rest/datatypes.py
+5
-0
parse_rest/query.py
+1
-1
parse_rest/tests.py
+34
-0
No files found.
parse_rest/datatypes.py
View file @
a48cadb1
...
@@ -60,6 +60,11 @@ class ParseType(object):
...
@@ -60,6 +60,11 @@ class ParseType(object):
ParseResource
:
Pointer
ParseResource
:
Pointer
}
}
if
hasattr
(
python_object
,
'__iter__'
):
# It's an iterable? Repeat this whole process on each object
return
[
ParseType
.
convert_to_parse
(
o
,
as_pointer
=
as_pointer
)
for
o
in
python_object
]
if
python_type
in
transformation_map
:
if
python_type
in
transformation_map
:
klass
=
transformation_map
.
get
(
python_type
)
klass
=
transformation_map
.
get
(
python_type
)
return
klass
(
python_object
)
.
_to_native
()
return
klass
(
python_object
)
.
_to_native
()
...
...
parse_rest/query.py
View file @
a48cadb1
...
@@ -126,7 +126,7 @@ class Queryset(object):
...
@@ -126,7 +126,7 @@ class Queryset(object):
if
operator
is
None
:
if
operator
is
None
:
q
.
_where
[
attr
]
=
parse_value
q
.
_where
[
attr
]
=
parse_value
elif
operator
==
'relatedTo'
:
elif
operator
==
'relatedTo'
:
q
.
_where
[
'$'
+
operator
]
=
parse_value
q
.
_where
[
'$'
+
operator
]
=
{
'object'
:
parse_value
,
'key'
:
attr
}
else
:
else
:
if
not
isinstance
(
q
.
_where
[
attr
],
dict
):
if
not
isinstance
(
q
.
_where
[
attr
],
dict
):
q
.
_where
[
attr
]
=
{}
q
.
_where
[
attr
]
=
{}
...
...
parse_rest/tests.py
View file @
a48cadb1
...
@@ -59,6 +59,14 @@ class GameScore(Object):
...
@@ -59,6 +59,14 @@ class GameScore(Object):
pass
pass
class
GameMap
(
Object
):
pass
class
GameMode
(
Object
):
pass
class
City
(
Object
):
class
City
(
Object
):
pass
pass
...
@@ -348,6 +356,32 @@ class TestQuery(unittest.TestCase):
...
@@ -348,6 +356,32 @@ class TestQuery(unittest.TestCase):
self
.
assertEqual
(
GameScore
.
Query
.
filter
(
createdAt__lte
=
tomorrow
)
.
count
(),
5
,
self
.
assertEqual
(
GameScore
.
Query
.
filter
(
createdAt__lte
=
tomorrow
)
.
count
(),
5
,
'Could not make inequality comparison with dates'
)
'Could not make inequality comparison with dates'
)
def
testRelations
(
self
):
"""Make some maps, make a Game Mode that has many maps, find all maps
given a Game Mode"""
maps
=
[
GameMap
(
name
=
"map "
+
i
)
for
i
in
[
'a'
,
'b'
,
'c'
,
'd'
]]
ParseBatcher
()
.
batch_save
(
maps
)
gm
=
GameMode
(
name
=
'test mode'
)
gm
.
save
()
gm
.
addRelation
(
"maps"
,
GameMap
.
__name__
,
[
m
.
objectId
for
m
in
maps
])
modes
=
GameMode
.
Query
.
all
()
self
.
assertEqual
(
len
(
modes
),
1
)
mode
=
modes
[
0
]
maps_for_mode
=
GameMap
.
Query
.
filter
(
maps__relatedTo
=
mode
)
self
.
assertEqual
(
len
(
maps_for_mode
),
4
)
gm
.
delete
()
ParseBatcher
()
.
batch_delete
(
maps
)
def
testQueryByRelated
(
self
):
game_scores_direct
=
GameScore
.
Query
.
filter
(
game
=
self
.
game
)
self
.
assertTrue
(
len
(
game_scores_direct
)
>
0
)
game_scores_in
=
GameScore
.
Query
.
filter
(
game__in
=
[
self
.
game
])
self
.
assertEqual
(
len
(
game_scores_in
),
len
(
game_scores_direct
))
class
TestFunction
(
unittest
.
TestCase
):
class
TestFunction
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
...
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