Exemplo n.º 1
0
 def test_reload_specific(self, Sample):
     doc = Sample.find_one(integer=42)
     assert doc.string == 'baz'
     Sample.get_collection().update_one(
         Sample.id == doc, U(Sample, integer=1337, string="hoi"))
     assert doc.string == 'baz'
     doc.reload('string')
     assert doc.string == 'hoi'
     assert doc.integer == 42
Exemplo n.º 2
0
 def test_timestamp(self, D):
     q = U(D, now__field='ts')
     assert isinstance(q, Update)
     assert q.operations == {
         '$currentDate': {
             'field': {
                 '$type': 'timestamp'
             }
         }
     }
Exemplo n.º 3
0
    def test_complex_push(self, D):
        q = U(
            D,
            push_each__array=[1, 2, 3],
            push_sort__array=-1,
            push_slice__array=2,
            push_position__array=1,
        )

        assert q.operations == {
            '$push': {
                'array': {
                    '$each': ["1", "2", "3"],
                    '$sort': -1,
                    '$slice': 2,
                    '$position': 1
                }
            }
        }
Exemplo n.º 4
0
    def test_push_each(self, D):
        q = U(D, push_each__array=[1, 2, 3])

        assert q.operations == {'$push': {'array': {'$each': ["1", "2", "3"]}}}
Exemplo n.º 5
0
 def test_date(self, D):
     q = U(D, now__field=True)
     assert isinstance(q, Update)
     assert q.operations == {'$currentDate': {'field': True}}
Exemplo n.º 6
0
 def test_bit(self, D):
     q = U(D, bit_xor__number=27)
     assert isinstance(q, Update)
     assert q.operations == {'$bit': {'other': {'xor': 27}}}
Exemplo n.º 7
0
 def test_alias(self, D):
     q = U(D, rename__field="name")
     assert isinstance(q, Update)
     assert q.operations == {'$rename': {'field': 'name'}}
Exemplo n.º 8
0
 def test_dec(self, D):
     q = U(D, dec__number=42)
     assert isinstance(q, Update)
     assert q.operations == {'$inc': {'other': -42}}
Exemplo n.º 9
0
 def test_set_default(self, D):
     q = U(D, field=27, number=42)
     assert isinstance(q, Update)
     assert q.operations == {'$set': {'field': '27', 'other': 42}}