try:
    import unittest2 as unittest
except ImportError:
    import unittest

import collections

try:
    from unittest import mock
except ImportError:
    import mock

from pymongo.cursor import Cursor

from simon import connection, query
from simon._compat import range

from .utils import AN_OBJECT_ID, ModelFactory

DefaultModel = ModelFactory('DefaultModel')
MappedModel = ModelFactory('MappedModel', field_map={'fake': 'real'})


class TestQ(unittest.TestCase):
    """Test the `Q` class."""

    def test___init__(self):
        """Test the `__init__()` method."""

        q = query.Q(a=1)
        self.assertEqual(q._filter, {'a': 1})

        q = query.Q(a=1, b=2)
        self.assertEqual(q._filter, {'a': 1, 'b': 2})

    def test___and__(self):
        """Test the `__and__()` method."""

        q1 = query.Q(a=1)
        q1._add_filter = mock.Mock()

        q2 = query.Q(b=2)

        q1.__and__(q2)

        q1._add_filter.assert_called_with(q2, '$and')