Пример #1
0
 def setUp(self):
     from Bee.Request import SimpleRequest
     #r = SimpleRequest()
     #content = r.get('http://s.taobao.com/search?q=t&debug=true&test=1')
     content = open("./tests/sample.json").read()
     self._json = content
     self._data = loads(content)
     self.e = Eval(self._data, debug=0)
Пример #2
0
    def testGetId(self):
        case = self.db.getById(2)

        from Bee.Request import SimpleRequest
        from Bee.Expr import Eval
        import json
        r = SimpleRequest()
        test_data = r.get(case["input"])
        script = Eval(debug=0)
        r = script.runStringOnce(case["expect"], test_data, prefix="entry.%s" % case['refmodules'])

        self.assertTrue(r)
Пример #3
0
    def testAll(self):
        cases = self.db.getAll()

        from Bee.Request import SimpleRequest
        from Bee.Expr import Eval
        import json
        r = SimpleRequest()
        script = Eval(debug=0)

        for case in cases:
            if input not in case:
                print(case)
                return
            test_data = r.get(case["input"])
            r = script.runStringOnce(case["expect"], test_data, prefix="entry.%s" % case['refmodules'])
            self.assertTrue(r)
Пример #4
0
 def setUp(self):
     from Bee.Request import SimpleRequest
     #r = SimpleRequest()
     #content = r.get('http://s.taobao.com/search?q=t&debug=true&test=1')
     content = open("./tests/sample.json").read()
     self._json = content
     self._data = loads(content)
     self.e = Eval(self._data, debug=0)
Пример #5
0
    def run(self):

        url = self._s[0].strip()
        rules = self._s[1:]

        data = urllib.urlopen(url)
        if (data):
            data = json.loads(data)
            return Eval.runs(rules, data)
        return False
Пример #6
0
    def run(self):

        url = self._s[0].strip()
        rules = self._s[1:]

        data = urllib.urlopen(url)
        if (data):
            data = json.loads(data)
            return Eval.runs(rules, data)
        return False
Пример #7
0
    def POST(self):
        """
        get parameters from post body

        :return:
        """
        storage = input()
        rules = storage.get('rules')
        url = storage.get('url')
        data = req.get(url)
        result = Eval(data).runStringOnce(rules)
        return dumps({"result": result})
Пример #8
0
 def handle_request(self, response):
     """
     request handler
     """
     rules = self.get_argument("rules")
     if response.error:
         self.write("Error:", response.error)
     else:
         data = req.parse(response.body, 'gb18030')
         result = Eval(data).runStringOnce(rules)
         self.write( result )
         #self.write(response.body)
     self.finish()
Пример #9
0
    def post(self, url=None, rules=None):
        url = "{}&test=true&debug=true".format(self.get_argument("url"))
        rules = self.get_argument("rules")
        node_prefix = self.get_argument("node_prefix")
        http_client.fetch(url,
                          callback=(yield gen.Callback("key")))
        response = yield gen.Wait("key")
        if response.error:
            self.write("Error:", response.error)
        else:
            if None != response.body:
                data = req.parse(response.body, 'gb18030')
                result = Eval(data, node_prefix=node_prefix, debug=0).runStringOnce(rules)
                self.write( dumps(result) )
            else:
                self.write( "ok" )

        self.finish()
Пример #10
0
    def testAll(self):
        cases = self.db.getAll()

        from Bee.Request import SimpleRequest
        from Bee.Expr import Eval
        import json
        r = SimpleRequest()
        script = Eval(debug=0)

        for case in cases:
            if input not in case:
                print(case)
                return
            test_data = r.get(case["input"])
            r = script.runStringOnce(case["expect"],
                                     test_data,
                                     prefix="entry.%s" % case['refmodules'])
            self.assertTrue(r)
Пример #11
0
class BasicScriptTestCase(unittest.TestCase):
    def setUp(self):
        from Bee.Request import SimpleRequest
        #r = SimpleRequest()
        #content = r.get('http://s.taobao.com/search?q=t&debug=true&test=1')
        content = open("./tests/sample.json").read()
        self._json = content
        self._data = loads(content)
        self.e = Eval(self._data, debug=0)

    def getData(self):
        pass

    def test_json_global(self):
        self.assertTrue(
            self.e.runStringOnce(
                    "data.view.navigation.type = 3",
                    self._data
            )
        )

    def test_node_value2(self):
        self.assertFalse(self.e.runStringOnce(
                "data.view.navigation.type = 0",
                self._data
            ))

    def test_complex_path(self):
        self.assertTrue(
            self.e.runStringOnce(
                'entry.recommendbottom.DATA.*widgetName = "recommendBottom"',
                self._data
            ),
        )


    def test_regex_match(self):
        self.assertEquals(True, self.e.runStringOnce('"helloword" ~ r"hell[o]word"', self._data))

    def test_double_eval(self):
        self.assertTrue(
            self.e.runStringOnce(
                    "data.view.navigation.type = 3 ; #data.view.navigation.prop.20000 = 2"
            )
        )
        self.assertTrue(self.e.runStringOnce('data.view.navigation.type = 3'))
Пример #12
0
class BasicScriptTestCase(unittest.TestCase):
    def setUp(self):
        from Bee.Request import SimpleRequest
        #r = SimpleRequest()
        #content = r.get('http://s.taobao.com/search?q=t&debug=true&test=1')
        content = open("./tests/sample.json").read()
        self._json = content
        self._data = loads(content)
        self.e = Eval(self._data, debug=0)

    def getData(self):
        pass

    def test_json_global(self):
        self.assertTrue(
            self.e.runStringOnce("data.view.navigation.type = 3", self._data))

    def test_node_value2(self):
        self.assertFalse(
            self.e.runStringOnce("data.view.navigation.type = 0", self._data))

    def test_complex_path(self):
        self.assertTrue(
            self.e.runStringOnce(
                'entry.recommendbottom.DATA.*widgetName = "recommendBottom"',
                self._data), )

    def test_regex_match(self):
        self.assertEquals(
            True,
            self.e.runStringOnce('"helloword" ~ r"hell[o]word"', self._data))

    def test_double_eval(self):
        self.assertTrue(
            self.e.runStringOnce(
                "data.view.navigation.type = 3 ; #data.view.navigation.prop.20000 = 2"
            ))
        self.assertTrue(self.e.runStringOnce('data.view.navigation.type = 3'))
Пример #13
0
        self.db = SingleDb
        self.db.connectDb({})

    def testCon(self):
        case = self.db.querySql("SELECT * FROM bee_case")
        self.assertTrue(len(case) > 0)

    def testGetId(self):
        case = self.db.getById(2)

        from Bee.Request import SimpleRequest
        from Bee.Expr import Eval
        import json
        r = SimpleRequest()
        test_data = r.get(case["input"])
        script = Eval(debug=0)
        r = script.runStringOnce(case["expect"],
                                 test_data,
                                 prefix="entry.%s" % case['refmodules'])

        self.assertTrue(r)

    def testAll(self):
        cases = self.db.getAll()

        from Bee.Request import SimpleRequest
        from Bee.Expr import Eval
        import json
        r = SimpleRequest()
        script = Eval(debug=0)