Exemplo n.º 1
0
    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'))
Exemplo n.º 2
0
    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))
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
 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))