'Test disjunction of query dicts'

def testOr(self):

    p = S3URLQueryParser()
    assertEqual = self.assertEqual
    assertTrue = self.assertTrue
    assertIn = self.assertIn
    q1 = (S3FieldSelector('~.test1') == 'A')
    q2 = (S3FieldSelector('x.test2') == 'B')
    q3 = (S3FieldSelector('x.test3') == 'C')
    q4 = (S3FieldSelector('y.test4') == 'D')
    qdict1 = {'x': q2}
    qdict2 = {'x': q3}
    result = p._or(qdict1, qdict2)
    assertTrue(isinstance(result, dict))
    assertEqual(len(result), 1)
    assertIn('x', result)
    query = result['x']
    assertEqual(query.op, query.OR)
    operands = (query.left, query.right)
    assertIn(q2, operands)
    assertIn(q3, operands)
    qdict1 = {'x': q2}
    qdict2 = {'y': q4}
    result = p._or(qdict1, qdict2)
    assertTrue(isinstance(result, dict))
    assertEqual(len(result), 1)
    assertIn(None, result)
    query = result[None]
    assertEqual(query.op, query.OR)
    operands = (query.left, query.right)
    assertIn(q2, operands)
    assertIn(q4, operands)
    qdict1 = {'x': q2}
    qdict2 = {'x': q3, 'y': q4}
    result = p._or(qdict1, qdict2)
    assertTrue(isinstance(result, dict))
    assertEqual(len(result), 1)
    assertIn(None, result)
    query = result[None]
    assertEqual(query.op, query.OR)
    assertIn(q2, (query.left, query.right))
    query = (query.right if (query.left == q2) else query.right)
    assertEqual(query.op, query.AND)
    operands = (query.left, query.right)
    assertIn(q3, operands)
    assertIn(q4, operands)
    qdict1 = {}
    qdict2 = {'x': q3}
    result = p._or(qdict1, qdict2)
    assertTrue(isinstance(result, dict))
    assertEqual(len(result), 1)
    assertIn('x', result)
    query = result['x']
    assertEqual(query, q3)
