Ejemplo n.º 1
0
    def test_q_inversion(self):
        version = Version(build=EXCHANGE_2007)
        account = mock_account(version=version,
                               protocol=mock_protocol(
                                   version=version,
                                   service_endpoint='example.com'))
        root = Root(account=account)
        self.assertEqual((~Q(foo=5)).op, Q.NE)
        self.assertEqual((~Q(foo__not=5)).op, Q.EQ)
        self.assertEqual((~Q(foo__lt=5)).op, Q.GTE)
        self.assertEqual((~Q(foo__lte=5)).op, Q.GT)
        self.assertEqual((~Q(foo__gt=5)).op, Q.LTE)
        self.assertEqual((~Q(foo__gte=5)).op, Q.LT)
        # Test not not Q on a non-leaf
        self.assertEqual(Q(foo__contains=('bar', 'baz')).conn_type, Q.AND)
        self.assertEqual((~Q(foo__contains=('bar', 'baz'))).conn_type, Q.NOT)
        self.assertEqual((~~Q(foo__contains=('bar', 'baz'))).conn_type, Q.AND)
        self.assertEqual(Q(foo__contains=('bar', 'baz')),
                         ~~Q(foo__contains=('bar', 'baz')))
        # Test generated XML of 'Not' statement when there is only one child. Skip 't:And' between 't:Not' and 't:Or'.
        result = '''\
<m:Restriction xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages">
    <t:Not xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
        <t:Or>
            <t:IsEqualTo>
                <t:FieldURI FieldURI="item:Subject"/>
                <t:FieldURIOrConstant>
                    <t:Constant Value="bar"/>
                </t:FieldURIOrConstant>
            </t:IsEqualTo>
            <t:IsEqualTo>
                <t:FieldURI FieldURI="item:Subject"/>
                <t:FieldURIOrConstant>
                    <t:Constant Value="baz"/>
                </t:FieldURIOrConstant>
            </t:IsEqualTo>
        </t:Or>
    </t:Not>
</m:Restriction>'''
        q = ~(Q(subject='bar') | Q(subject='baz'))
        self.assertEqual(
            xml_to_str(
                q.to_xml(folders=[Calendar(root=root)],
                         version=version,
                         applies_to=Restriction.ITEMS)),
            ''.join(s.lstrip() for s in result.split('\n')))
Ejemplo n.º 2
0
    def test_anonymizing_handler(self):
        h = AnonymizingXmlHandler(forbidden_strings=("XXX", "yyy"))
        self.assertEqual(
            xml_to_str(
                h.parse_bytes(b"""\
<Root>
  <t:ItemId Id="AQApA=" ChangeKey="AQAAAB"/>
  <Foo>XXX</Foo>
  <Foo><Bar>Hello yyy world</Bar></Foo>
</Root>""")),
            """\
<Root>
  <t:ItemId Id="DEADBEEF=" ChangeKey="DEADBEEF="/>
  <Foo>[REMOVED]</Foo>
  <Foo><Bar>Hello [REMOVED] world</Bar></Foo>
</Root>""",
        )
Ejemplo n.º 3
0
    def test_parse(self):
        xml = Restriction.parse_source(
            "calendar:Start > '2016-01-15T13:45:56Z' and (not calendar:Subject == 'EWS Test')"
        )
        result = '''\
<m:Restriction>
    <t:And>
        <t:IsGreaterThan>
            <t:FieldURI FieldURI="calendar:Start" />
            <t:FieldURIOrConstant>
                <t:Constant Value="2016-01-15T13:45:56Z" />
            </t:FieldURIOrConstant>
        </t:IsGreaterThan>
        <t:Not>
            <t:IsEqualTo>
                <t:FieldURI FieldURI="calendar:Subject" />
                <t:FieldURIOrConstant>
                    <t:Constant Value="EWS Test" />
                </t:FieldURIOrConstant>
            </t:IsEqualTo>
        </t:Not>
    </t:And>
</m:Restriction>'''
        self.assertEqual(xml_to_str(xml), ''.join(l.lstrip() for l in result.split('\n')))
Ejemplo n.º 4
0
 def test_xml_to_str(self):
     with self.assertRaises(AttributeError):
         xml_to_str("XXX", encoding=None, xml_declaration=True)