Beispiel #1
0
    def testParse(self):
        filt = filters.ItemFilter()

        one = rdf_protodict.AttributedDict(test1="1", test2=[2, 3])
        foo = rdf_protodict.AttributedDict(test1="foo", test2=["bar", "baz"])
        fs = rdf_client.Filesystem(device="/dev/sda1", mount_point="/root")
        objs = [one, foo, fs]

        results = filt.Parse(objs, "test1 is '1'")
        self.assertEqual(1, len(results))
        self.assertEqual("test1", results[0].key)
        self.assertEqual("1", results[0].value)

        results = filt.Parse(objs, "test1 is '2'")
        self.assertFalse(results)

        results = filt.Parse(objs, "test2 contains 3")
        self.assertEqual(1, len(results))
        self.assertEqual("test2", results[0].key)
        self.assertEqual([2, 3], results[0].value)

        results = filt.Parse(objs, "test1 is '1' or test1 contains 'foo'")
        self.assertEqual(2, len(results))
        self.assertEqual("test1", results[0].key)
        self.assertEqual("1", results[0].value)
        self.assertEqual("test1", results[1].key)
        self.assertEqual("foo", results[1].value)

        results = filt.Parse(objs, "mount_point is '/root'")
        self.assertEqual(1, len(results))
        self.assertEqual("mount_point", results[0].key)
        self.assertEqual("/root", results[0].value)
Beispiel #2
0
    def testParse(self):
        filt = filters.ItemFilter()

        cfg = rdfvalue.Config(test1="1", test2=[2, 3])

        result = list(filt.Parse(cfg, "test1 is '1'"))
        self.assertEqual(1, len(result))
        self.assertEqual("test1", result[0].k)
        self.assertEqual("1", result[0].v)

        result = list(filt.Parse(cfg, "test1 is '2'"))
        self.assertFalse(result)

        result = list(filt.Parse(cfg, "test2 contains 3"))
        self.assertEqual(1, len(result))
        self.assertEqual("test2", result[0].k)
        self.assertEqual([2, 3], result[0].v)

        # Ensure this works on other RDF types, not just Configs.
        cfg = rdfvalue.Filesystem(device="/dev/sda1", mount_point="/root")
        result = list(filt.Parse(cfg, "mount_point is '/root'"))
        self.assertEqual(1, len(result))
        self.assertEqual("mount_point", result[0].k)
        self.assertEqual("/root", result[0].v)