示例#1
0
    def test_basic(self):

        now = time.time_ns()

        q1 = Query(Key('/'), limit=100)
        q2 = Query(Key('/'), offset=200)
        q3 = Query(Key('/'), object_getattr=getattr)

        q1.offset = 300
        q3.limit = 1

        q1.filter('key', '>', '/ABC')
        q1.filter('created', '>', now)

        q2.order('key')
        q2.order('-created')

        q1d = {
            'key': '/',
            'limit': 100,
            'offset': 300,
            'filter': [['key', '>', '/ABC'], ['created', '>', now]]
        }

        q2d = {'key': '/', 'offset': 200, 'order': ['+key', '-created']}

        q3d = {'key': '/', 'limit': 1}

        assert q1.dict() == q1d
        assert q2.dict() == q2d
        assert q3.dict() == q3d

        assert q1 == Query.from_dict(q1d)
        assert q2 == Query.from_dict(q2d)
        assert q3 == Query.from_dict(q3d)

        assert q1 == eval(repr(q1))
        assert q2 == eval(repr(q2))
        assert q3 == eval(repr(q3))

        assert q1 == q1.copy()
        assert q2 == q2.copy()
        assert q3 == q3.copy()
示例#2
0
    def test_basic(self):

        now = nanotime.now().nanoseconds()

        q1 = Query(Key('/'), limit=100)
        q2 = Query(Key('/'), offset=200)
        q3 = Query(Key('/'), object_getattr=getattr)

        q1.offset = 300
        q3.limit = 1

        q1.filter('key', '>', '/ABC')
        q1.filter('created', '>', now)

        q2.order('key')
        q2.order('-created')

        q1d = {'key': '/', 'limit': 100, 'offset': 300, \
               'filter': [['key', '>', '/ABC'], ['created', '>', now]]}

        q2d = {'key': '/', 'offset': 200, 'order': ['+key', '-created']}

        q3d = {'key': '/', 'limit': 1}

        self.assertEqual(q1.dict(), q1d)
        self.assertEqual(q2.dict(), q2d)
        self.assertEqual(q3.dict(), q3d)

        self.assertEqual(q1, Query.from_dict(q1d))
        self.assertEqual(q2, Query.from_dict(q2d))
        self.assertEqual(q3, Query.from_dict(q3d))

        self.assertEqual(q1, eval(repr(q1)))
        self.assertEqual(q2, eval(repr(q2)))
        self.assertEqual(q3, eval(repr(q3)))

        self.assertEqual(q1, q1.copy())
        self.assertEqual(q2, q2.copy())
        self.assertEqual(q3, q3.copy())