Пример #1
0
 def test_placeholderAttributeValueComparison(self):
     """
     Test that getting an attribute from a Placeholder which exists on the
     underlying Item class and comparing it to a value returns an
     L{IComparison} provider.
     """
     value = 0
     p = Placeholder(PlaceholderTestItem)
     for op in COMPARISON_OPS:
         self.failUnless(IComparison.providedBy(op(p.attr, value)))
         self.failUnless(IComparison.providedBy(op(value, p.attr)))
Пример #2
0
 def test_placeholderStoreID(self):
     """
     Test that the C{storeID} attribute of a Placeholder can be retrieved
     just like any other attribute.
     """
     value = 0
     p = Placeholder(PlaceholderTestItem)
     self.failUnless(IComparison.providedBy(p.storeID > value))
Пример #3
0
 def test_oneOfValueQueryGeneration(self):
     """
     Test that comparing an attribute for containment against a value set
     generates the appropriate SQL.
     """
     values = [u'a', u'b', u'c']
     comparison = C.name.oneOf(values)
     self.failUnless(IComparison.providedBy(comparison))
     self.assertEquals(
         comparison.getQuery(self.store),
         '%s IN (?, ?, ?)' % (C.name.getColumnName(self.store), ))
     self.assertEquals(comparison.getArgs(self.store), values)
Пример #4
0
 def test_oneOfColumnQueryQueryGeneration(self):
     """
     Test that comparing an attribute for containment against another query
     generates a sub-select.
     """
     subselect = self.store.query(A).getColumn('type')
     comparison = C.name.oneOf(subselect)
     self.failUnless(IComparison.providedBy(comparison))
     self.assertEquals(
         comparison.getQuery(self.store), '%s IN (SELECT %s FROM %s)' %
         (C.name.getColumnName(self.store), A.type.getColumnName(
             self.store), A.getTableName(self.store)))
     self.assertEquals(comparison.getArgs(self.store), [])
Пример #5
0
 def test_oneOfColumnQueryGeneration(self):
     """
     Test that comparing an attribute for containment against an L{IColumn}
     generates the appropriate SQL.
     """
     values = A.type
     comparison = C.name.oneOf(values)
     self.failUnless(IComparison.providedBy(comparison))
     self.assertEquals(
         comparison.getQuery(self.store),
         '%s IN (%s)' % (C.name.getColumnName(
             self.store), A.type.getColumnName(self.store)))
     self.assertEquals(comparison.getArgs(self.store), [])
Пример #6
0
    def _placeholderAttributeSimilarity(self, kind, sql, args):
        s = Store()
        value = u'text'

        p = Placeholder(PlaceholderTestItem)

        # Explicitly call this, since we aren't going through ItemQuery.
        p.getTableAlias(s, ())

        comparison = getattr(p.characters, kind)(value)
        self.failUnless(IComparison.providedBy(comparison))
        self.assertEquals(comparison.getQuery(s),
                          sql % (p.characters.getColumnName(s), ))
        self.assertEquals(comparison.getArgs(s), [args % (value, )])
Пример #7
0
    def test_placeholderAntiContainment(self):
        """
        Test that placeholder attributes can be used with the SQL NOT IN
        operator.
        """
        s = Store()
        value = [1, 2, 3]
        p = Placeholder(PlaceholderTestItem)

        # Call this since we're not using ItemQuery
        p.getTableAlias(s, ())

        comparison = p.attr.notOneOf(value)
        self.failUnless(IComparison.providedBy(comparison))
        self.assertEquals(comparison.getQuery(s),
                          '%s NOT IN (?, ?, ?)' % (p.attr.getColumnName(s), ))
        self.assertEquals(comparison.getArgs(s), value)
Пример #8
0
    def test_placeholderLikeTarget(self):
        """
        Test that a placeholder can be used as the right-hand argument to a SQL
        LIKE expression.
        """
        s = Store()
        p = Placeholder(PlaceholderTestItem)

        # Call this since we're not using ItemQuery
        p.getTableAlias(s, ())

        comparison = PlaceholderTestItem.attr.like(p.attr)
        self.failUnless(IComparison.providedBy(comparison))
        self.assertEquals(
            comparison.getQuery(s), '(%s LIKE (placeholder_0.[attr]))' %
            (PlaceholderTestItem.attr.getColumnName(s), ))
        self.assertEquals(comparison.getArgs(s), [])
Пример #9
0
    def test_placeholderAntiContainmentTarget(self):
        """
        Test that a placeholder attribute can be used as the right-hand
        argument to the SQL NOT IN operator.
        """
        s = Store()
        p = Placeholder(PlaceholderTestItem)

        # Call this since we're not using ItemQuery
        p.getTableAlias(s, ())

        comparison = PlaceholderTestItem.attr.notOneOf(p.attr)
        self.failUnless(IComparison.providedBy(comparison))
        self.assertEquals(
            comparison.getQuery(s),
            '%s NOT IN (%s)' % (PlaceholderTestItem.attr.getColumnName(s),
                                p.attr.getColumnName(s)))
        self.assertEquals(comparison.getArgs(s), [])
Пример #10
0
    def test_oneOfColumnQueryQueryGenerationWithArguments(self):
        """
        Like test_oneOfColumnQueryQueryGeneration, but pass some values to the
        subselect and make sure they come out of the C{getArgs} method
        properly.
        """
        value = '10'
        subselect = self.store.query(D, AND(D.id == value,
                                            D.four == C.name)).getColumn('one')

        comparison = C.name.oneOf(subselect)
        self.failUnless(IComparison.providedBy(comparison))
        self.assertEquals(
            comparison.getQuery(self.store),
            '%s IN (SELECT %s FROM %s, %s WHERE ((%s = ?) AND (%s = %s)))' %
            (C.name.getColumnName(self.store), D.one.getColumnName(self.store),
             C.getTableName(self.store), D.getTableName(self.store),
             D.id.getColumnName(self.store), D.four.getColumnName(
                 self.store), C.name.getColumnName(self.store)))
        self.assertEquals(map(str, comparison.getArgs(self.store)), [value])