示例#1
0
    def testTypeOfLookupTableNone(self):
        """
            Test resolution of __typeof queries, for field in lookup table,
            with None value
        """

        db = current.db

        uids = self.uids
        resource = current.s3db.resource("test_hierarchy_reference")

        # Test with None
        expr = FS("test_hierarchy_id$name").typeof(None)
        query = expr.query(resource)
        table = db.test_hierarchy
        expected_query = table.id.belongs(set())
        self.assertEquivalent(query, expected_query)

        # Test with list
        expr = FS("test_hierarchy_id$name").typeof([None])
        query = expr.query(resource)
        #table = db.test_hierarchy
        expected_query = table.id.belongs(set())
        self.assertEquivalent(query, expected_query)

        # Test with multiple values
        expr = FS("test_hierarchy_id$name").typeof([None, "Type 1-1-2"])
        query = expr.query(resource)
        #table = db.test_hierarchy
        expected_query = (table.id == uids["HIERARCHY1-1-2"])
        self.assertEquivalent(query, expected_query)
示例#2
0
    def testTypeOfReferenceNoHierarchy(self):
        """
            Test resolution of __typeof queries, for field in referencing
            table, with no hierarchy configured
        """

        db = current.db
        uids = self.uids

        # Remove hierarchy setting
        current.s3db.clear_config("test_hierarchy", "hierarchy")

        resource = current.s3db.resource("test_hierarchy_reference")

        # Test with field in referencing table, single value
        expr = FS("test_hierarchy_id").typeof(uids["HIERARCHY1-2"])
        query = expr.query(resource)

        expected = uids["HIERARCHY1-2"]
        expected_query = resource.table.test_hierarchy_id == expected

        self.assertEquivalent(query, expected_query)

        # Test with field in referencing table, multiple values
        expr = FS("test_hierarchy_id").typeof((uids["HIERARCHY1-2"],
                                               uids["HIERARCHY2-1"]
                                               ))
        query = expr.query(resource)

        expected = set(uids[uid] for uid in ("HIERARCHY1-2",
                                             "HIERARCHY2-1",
                                             ))
        expected_query = resource.table.test_hierarchy_id.belongs(expected)

        self.assertEquivalent(query, expected_query)
示例#3
0
    def testTypeOfListReferenceMultiple(self):
        """
            Test resolution of __typeof queries, for list:reference,
            with multiple values
        """

        db = current.db

        uids = self.uids
        resource = current.s3db.resource("test_hierarchy_reference")

        # Test with multiple values
        expr = FS("test_hierarchy_multi_id").typeof((uids["HIERARCHY1-2"],
                                                     uids["HIERARCHY2-1"]))
        query = expr.query(resource)

        table = resource.table
        expected = set(uids[uid] for uid in ("HIERARCHY1-2",
                                             "HIERARCHY1-2-1",
                                             "HIERARCHY1-2-2",
                                             "HIERARCHY2-1",
                                             "HIERARCHY2-1-1",
                                             "HIERARCHY2-1-2",
                                             ))
        found = self.inspect_multi_query(query,
                                         field = table.test_hierarchy_multi_id,
                                         conjunction = db._adapter.OR,
                                         op = db._adapter.CONTAINS)

        self.assertEqual(found, expected)
示例#4
0
    def testTypeOfLookupTableMultipleWildcard(self):
        """
            Test resolution of __typeof queries, for field in lookup table,
            with multiple values with wildcards
        """

        db = current.db

        uids = self.uids
        resource = current.s3db.resource("test_hierarchy_reference")

        # Test with field in hierarchy table, with wildcard
        expr = FS("test_hierarchy_id$name").typeof(("Type 1-1-*", "Type 2-1*"))
        query = expr.query(resource)
        
        table = db.test_hierarchy
        expected = set(uids[uid] for uid in ("HIERARCHY1-1-1",
                                             "HIERARCHY1-1-2",
                                             "HIERARCHY2-1",
                                             "HIERARCHY2-1-1",
                                             "HIERARCHY2-1-2",
                                             ))
        expected_query = table.id.belongs(expected)
        
        self.assertEquivalent(query, expected_query)
示例#5
0
    def testTypeOfReferenceMultiple(self):
        """
            Test resolution of __typeof queries, for field in referencing
            table, with multiple values
        """

        db = current.db

        uids = self.uids
        resource = current.s3db.resource("test_hierarchy_reference")

        # Test with field in referencing table
        expr = FS("test_hierarchy_id").typeof((uids["HIERARCHY1-2"],
                                               uids["HIERARCHY2-1"],
                                               ))
        query = expr.query(resource)

        table = resource.table
        expected = set(uids[uid] for uid in ("HIERARCHY1-2",
                                             "HIERARCHY1-2-1",
                                             "HIERARCHY1-2-2",
                                             "HIERARCHY2-1",
                                             "HIERARCHY2-1-1",
                                             "HIERARCHY2-1-2",
                                             ))
        expected_query = table.test_hierarchy_id.belongs(expected)
        
        self.assertEquivalent(query, expected_query)
示例#6
0
    def testTypeOfLookupTableNoHierarchy(self):
        """
            Test resolution of __typeof queries, for field in lookup
            table, with no hierarchy configured
        """

        db = current.db

        uids = self.uids
        
        # Remove hierarchy setting
        current.s3db.clear_config("test_hierarchy", "hierarchy")

        resource = current.s3db.resource("test_hierarchy_reference")

        # Test with field in lookup table, single value
        expr = FS("test_hierarchy_id$name").typeof("Type 1-2")
        query = expr.query(resource)

        table = db.test_hierarchy
        expected_query = (table.name == "Type 1-2")

        self.assertEquivalent(query, expected_query)

        # Test with field in lookup table
        expr = FS("test_hierarchy_id$name").typeof(("Type 1-2", "Type 2-1"))
        query = expr.query(resource)

        table = db.test_hierarchy
        expected_query = table.name.belongs(("Type 1-2", "Type 2-1"))

        self.assertEquivalent(query, expected_query)

        # Test with field in lookup table, multiple values + wildcards
        expr = FS("test_hierarchy_id$name").typeof(("Type 1-*", "Type 2-1"))
        query = expr.query(resource)

        table = db.test_hierarchy
        expected_query = (table.name.like("Type 1-%")) | \
                         (table.name == "Type 2-1")

        self.assertEquivalent(query, expected_query)
示例#7
0
    def testTypeOfLookupTableSingleUnresolvable(self):
        """
            Test resolution of __typeof queries, for field in lookup table,
            with unresolvable value
        """

        db = current.db

        uids = self.uids
        resource = current.s3db.resource("test_hierarchy_reference")

        # Test with field in hierarchy table, with wildcard, no match
        expr = FS("test_hierarchy_id$name").typeof("Type 1-3*")
        query = expr.query(resource)
        
        table = db.test_hierarchy
        expected_query = table.id.belongs(set())
        
        self.assertEquivalent(query, expected_query)