Beispiel #1
0
class SQLiteUtils(object):
    @override
    def __init__(self, kwargs=None):
        self._index = None

    def setUp(self):
        self._index = QueryTable("testing")

    def tearDown(self):
        pass

    def setUpClass(self):
        pass

    def tearDownClass(self):
        pass

    def not_real_service(self):
        return True

    def execute_es_tests(self, subtest, tjson=False):
        subtest = wrap(subtest)
        subtest.name = extract_stack()[1]['method']

        if subtest.disable:
            return

        if "sqlite" in subtest["not"]:
            return

        self.fill_container(subtest, tjson=tjson)
        self.send_queries(subtest)

    def fill_container(self, subtest, tjson=False):
        """
        RETURN SETTINGS THAT CAN BE USED TO POINT TO THE INDEX THAT'S FILLED
        """
        subtest = wrap(subtest)

        try:
            # INSERT DATA
            self._index.insert(subtest.data)
        except Exception, e:
            Log.error("can not load {{data}} into container",
                      {"data": subtest.data}, e)

        frum = subtest.query['from']
        if isinstance(frum, basestring):
            subtest.query["from"] = frum.replace(test_jx.TEST_TABLE,
                                                 self._index.name)
        else:
            Log.error("Do not know how to handle")

        return Data()
Beispiel #2
0
class SQLiteUtils(object):
    @override
    def __init__(self, kwargs=None):
        self._index = None

    def setUp(self):
        self._index = QueryTable(name="testing",
                                 kwargs=test_jx.global_settings)

    def tearDown(self):

        pass

    def setUpClass(self):
        pass

    def tearDownClass(self):
        pass

    def not_real_service(self):
        return True

    def execute_tests(self, subtest, tjson=False, places=6):
        subtest = wrap(subtest)
        subtest.name = get_stacktrace()[1]['method']

        if subtest.disable:
            return

        self.fill_container(subtest, tjson=tjson)
        self.send_queries(subtest)

    def fill_container(self, subtest, tjson=False):
        """
        RETURN SETTINGS THAT CAN BE USED TO POINT TO THE INDEX THAT'S FILLED
        """
        subtest = wrap(subtest)

        try:
            # INSERT DATA
            self._index.insert(subtest.data)
        except Exception as e:
            Log.error("can not load {{data}} into container",
                      {"data": subtest.data}, e)

        frum = subtest.query['from']
        if isinstance(frum, text):
            subtest.query["from"] = frum.replace(
                test_jx.TEST_TABLE, self._index.facts.snowflake.fact_name)
        else:
            Log.error("Do not know how to handle")

        return Data({"index": subtest.query["from"]})

    def send_queries(self, subtest):
        subtest = wrap(subtest)

        try:
            # EXECUTE QUERY
            num_expectations = 0
            for k, v in subtest.items():
                if k.startswith("expecting_"):  # WHAT FORMAT ARE WE REQUESTING
                    format = k[len("expecting_"):]
                elif k == "expecting":  # NO FORMAT REQUESTED (TO TEST DEFAULT FORMATS)
                    format = None
                else:
                    continue

                num_expectations += 1
                expected = v

                subtest.query.format = format
                subtest.query.meta.testing = True  # MARK ALL QUERIES FOR TESTING SO FULL METADATA IS AVAILABLE BEFORE QUERY EXECUTION
                result = self.execute_query(subtest.query)

                compare_to_expected(subtest.query, result, expected)
            if num_expectations == 0:
                Log.error(
                    "Expecting test {{name|quote}} to have property named 'expecting_*' for testing the various format clauses",
                    {"name": subtest.name})
        except Exception as e:
            Log.error("Failed test {{name|quote}}", name=subtest.name, cause=e)

    def execute_query(self, query):
        try:
            if startswith_field(query["from"],
                                self._index.facts.snowflake.fact_name):
                return self._index.query(deepcopy(query))
            elif query["from"] == "meta.columns":
                return self._index.query_metadata(deepcopy(query))
            else:
                Log.error("Do not know how to handle")
        except Exception as e:
            Log.error("Failed query", e)

    def try_till_response(self, *args, **kwargs):
        self.execute_query(
            convert.json2value(convert.utf82unicode(kwargs["data"])))