예제 #1
0
    def test_rel_keys_matcher(self):
        u1 = Baz(username='******')
        u1.save()
        u2 = Baz(username='******')
        u2.save()

        qk = QueryKey(Baz)
        q = Qux()
        q.save()
        q.rel.add(u1)

        queries = (
            (q.rel.filter(username='******'), True),
            (q.rel.filter(username='******'), False)
        )

        tests = {}

        for qs, expected in queries:
            len(qs) # force eval
            tests[qs.query.res.key] = expected

        good = qk.match_and_parse_keys(tests.keys(), u1.as_dict(to_db=True))

        for key, expected in tests.items():
            self.assertEqual((key in good) is expected, True)
예제 #2
0
    def test_rel_key_matcher(self):
        u1 = Baz(username='******')
        u1.save()
        u2 = Baz(username='******')
        u2.save()

        qk = QueryKey(Baz)
        q = Qux()
        q.save()
        q.rel.add(u1)

        qs = q.rel
        self.assertEqual(len(qs), 1)
        key = qs.query.res.key

        p = r.pipeline()
        ok, parts, async_eval = qk.match_and_parse_key(key, u1.as_dict(to_db=True), pipe=p)
        self.assertEqual(ok, True)
        self.assertEqual(async_eval, True)
        self.assertEqual(True in p.execute(), True)

        ok, parts, async_eval = qk.match_and_parse_key(key, u1.as_dict(to_db=True))
        self.assertEqual(ok, True)
        self.assertEqual(async_eval, False)
        u = Baz(username='******')
        u.save()

        p = r.pipeline()
        ok, parts, async_eval = qk.match_and_parse_key(key, u2.as_dict(to_db=True), pipe=p)
        self.assertEqual(ok, True)
        self.assertEqual(async_eval, True)
        # notice that this last question evaluates as False.
        self.assertEqual(True in p.execute(), False)
예제 #3
0
 def test_key_builder(self):
     qk = QueryKey(Foo)
     self.runtests([
         (qk.build_key({}, {}, ''), '~Foo_all',  'all'),
         (qk.build_key({'username': '******'}, {}, ''), '~Foo_all+Foo_index:username:foo',  'all+inter'),
         (qk.build_key({}, {'username': '******'}, ''), '~Foo_all-Foo_index:username:foo',  'all+diff'),
         (qk.build_key({}, {}, 'Foo:username'), '~Foo_all^Foo:username',  'all+sort'),
     ])
예제 #4
0
    def test_key_matcher(self):
        qk = QueryKey(Bar)

        tests = [
            ('~Bar_all', self.b1, True),
            ('~Foo_all', self.b1, False),
            ('~Bar_all^Bar:username', self.b1, True),
            ('~Bar_all+Bar_index:username:foo', self.b1, True),
            ('~Bar_all+Bar_index:username:foo+Bar:pk:1', self.b1, True),
            ('~Bar_all+Bar_index:username:foo-Bar:pk:2', self.b1, True),
            ('~Bar_all+Bar_index:username:foo+Bar:pk:2', self.b1, False),
            ('~Bar_all+Bar_index:username:foo+Bar:pk:1^Bar:created_at', self.b1, True),
        ]

        for key, obj, expected in tests:
            ok, parts, async_eval = qk.match_and_parse_key(key, obj.as_dict(to_db=True))
            self.assertEqual(ok and async_eval == False, expected)
예제 #5
0
 def test_key_parser(self):
     qk = QueryKey(Foo)
     self.runtests([
         (qk.parse_key('~S'),       [['S'], [],        [],        []],          'all'),
         (qk.parse_key('~S^S:a'),   [['S'], [],        [],        ['S:a']],     'all+sort'),
         (qk.parse_key('~S-S:d:0'), [['S'], [],        ['S:d:0'], []],          'all+diff'),
         (qk.parse_key('~S+S:a:1'), [['S'], ['S:a:1'], [],        []],          'all+inter'),
         (qk.parse_key('~S+S:a:1+S:b:2-S:d:0^S:a'), [['S'], ['S:a:1', 'S:b:2'], ['S:d:0'], ['S:a']], 'all+inter+inter+diff+sort')
     ])