Commit 4d66c30f by David Robinson

Set up the QueryManager in a metaclass instead of in the __new__ method, which…

Set up the QueryManager in a metaclass instead of in the __new__ method, which means one doesn't have to instantiate an instance of the class before querying it. Fixed the __iter__ method of Queryset, which yielded only the first object from the query. Put back test cases for CloudCode functions.
parent 250d3694
......@@ -282,8 +282,16 @@ class ParseResource(ParseBase):
updatedAt = property(_get_updated_datetime, _set_created_datetime)
class Object(ParseResource):
class ObjectMetaclass(type):
def __new__(cls, name, bases, dct):
cls = super(ObjectMetaclass, cls).__new__(cls, name, bases, dct)
cls.set_endpoint_root()
cls.Query = QueryManager(cls)
return cls
class Object(ParseResource):
__metaclass__ = ObjectMetaclass
ENDPOINT_ROOT = '/'.join([API_ROOT, 'classes'])
@classmethod
......
......@@ -47,11 +47,7 @@ class Queryset(object):
self._options = {}
def __iter__(self):
results = getattr(self, '_results', self._fetch())
self._results = results
if len(self._results) == 0:
raise StopIteration
yield self._results.pop(0)
return iter(self._fetch())
def where(self, **kw):
for key, value in kw.items():
......
......@@ -52,6 +52,10 @@ class City(Object):
pass
class Review(Object):
pass
class TestObject(unittest.TestCase):
def setUp(self):
self.score = GameScore(
......@@ -105,7 +109,6 @@ class TestObject(unittest.TestCase):
'Failed to increment score on backend')
@unittest.skip("Skipping")
class TestFunction(unittest.TestCase):
def setUp(self):
"""create and deploy cloud functions"""
......@@ -124,8 +127,8 @@ class TestFunction(unittest.TestCase):
"(see https://www.parse.com/docs/cloud_code_guide)")
os.chdir(original_dir)
# remove all existing Review objects
for review in parse_rest.ObjectQuery("Review").fetch():
def tearDown(self):
for review in Review.Query.all():
review.delete()
def test_simple_functions(self):
......@@ -136,17 +139,10 @@ class TestFunction(unittest.TestCase):
self.assertEqual(ret["result"], u"Hello world!")
# Test the averageStars function- takes simple argument
r1 = parse_rest.Object(
"Review", {
"movie": "The Matrix",
"stars": 5,
"comment": "Too bad they never made any sequels."})
r1 = Review(movie="The Matrix", stars=5,
comment="Too bad they never made any sequels.")
r1.save()
r2 = parse_rest.Object(
"Review", {
"movie": "The Matrix",
"stars": 4,
"comment": "It's OK."})
r2 = Review(movie="The Matrix", stars=4, comment="It's OK.")
r2.save()
star_func = parse_rest.Function("averageStars")
......@@ -179,6 +175,13 @@ class TestUser(unittest.TestCase):
self.username = TestUser.USERNAME
self.password = TestUser.PASSWORD
try:
u = User.login(self.USERNAME, self.PASSWORD)
except parse_rest.ResourceRequestNotFound as e:
# if the user doesn't exist, that's fine
return
u.delete()
def tearDown(self):
self._destroy_user()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment