def test_does_not_exist(self): self.create_cities() query = Query('City') query = query.does_not_exist('country') cities = query.fetch() self.assertTrue(len(cities) > 0) for city in cities: self.assertFalse(hasattr(city, 'country'))
def test_simple_fetch(self): class City(ParseObject): pass ny = City(name='New York') ny.save() query = Query('City') cities = query.fetch() for city in cities: self.assertTrue(isinstance(city, City)) self.assertTrue(city._is_loaded) self.assertTrue(hasattr(city, 'objectId')) for k, v in city.__dict__.items(): self.assertFalse(isinstance(v, dict))
def test_where(self): class City(ParseObject): pass name = 'New York' ny = City(name=name) sf = City(name='San Francisco') ny.save() sf.save() query = Query('City').equal_to('name', name) cities = query.fetch() self.assertTrue(len(cities) > 0) for city in cities: self.assertEqual(city.name, name)
def test_keys(self): class City(ParseObject): pass name = 'New York' ny = City(name=name) sf = City(name='San Francisco', country='United States') ny.save() sf.save() query = Query('City').keys(['country']) cities = query.fetch() self.assertTrue(len(cities) > 0) for city in cities: self.assertRaises(AttributeError, getattr, city, 'name') self.assertFalse(city._is_loaded)
def test_limit(self): class City(ParseObject): pass name = 'New York' ny = City(name=name) sf = City(name='San Francisco', country='United States') ny.save() sf.save() query = Query('City') cities = query.limit(1).fetch() self.assertTrue(len(cities) == 1) query = Query('City') cities = query.limit(1).fetch() self.assertTrue(len(cities) == 1)
def test_query_set_slicing(self): self.create_cities() query = Query('City') query = query.does_not_exist('country') cities = query.fetch()[2:4] self.assertEqual(2, len(cities))