@@ -831,6 +831,9 @@ def test_insert_manipulate_false(self):
831
831
# 1. The return value is None or [None] as appropriate.
832
832
# 2. _id is not set on the passed-in document object.
833
833
# 3. _id is not sent to server.
834
+ if not version .at_least (self .db .connection , (2 , 0 )):
835
+ raise SkipTest ('Need at least MongoDB 2.0' )
836
+
834
837
collection_name = 'test_insert_manipulate_false'
835
838
try :
836
839
self .db .drop_collection (collection_name )
@@ -1922,11 +1925,14 @@ def test_find_and_modify(self):
1922
1925
c .insert ({'_id' : 1 , 'i' : 1 })
1923
1926
1924
1927
# Test that we raise DuplicateKeyError when appropriate.
1925
- c .ensure_index ('i' , unique = True )
1926
- self .assertRaises (DuplicateKeyError ,
1927
- c .find_and_modify , query = {'i' : 1 , 'j' : 1 },
1928
- update = {'$set' : {'k' : 1 }}, upsert = True )
1929
- c .drop_indexes ()
1928
+ # MongoDB doesn't have a code field for DuplicateKeyError
1929
+ # from commands before 2.2.
1930
+ if version .at_least (self .db .connection , (2 , 2 )):
1931
+ c .ensure_index ('i' , unique = True )
1932
+ self .assertRaises (DuplicateKeyError ,
1933
+ c .find_and_modify , query = {'i' : 1 , 'j' : 1 },
1934
+ update = {'$set' : {'k' : 1 }}, upsert = True )
1935
+ c .drop_indexes ()
1930
1936
1931
1937
# Test correct findAndModify
1932
1938
self .assertEqual ({'_id' : 1 , 'i' : 1 },
@@ -1962,20 +1968,23 @@ def test_find_and_modify(self):
1962
1968
c .find_and_modify ({'_id' : 1 }, {'$inc' : {'i' : 1 }},
1963
1969
new = True , fields = {'i' : 1 }))
1964
1970
1965
- # Test with full_response=True (version > 2.4.2)
1966
- result = c .find_and_modify ({'_id' : 1 }, {'$inc' : {'i' : 1 }},
1967
- new = True , upsert = True ,
1968
- full_response = True ,
1969
- fields = {'i' : 1 })
1970
- self .assertEqual ({'_id' : 1 , 'i' : 5 }, result ["value" ])
1971
- self .assertEqual (True , result ["lastErrorObject" ]["updatedExisting" ])
1972
-
1973
- result = c .find_and_modify ({'_id' : 2 }, {'$inc' : {'i' : 1 }},
1974
- new = True , upsert = True ,
1975
- full_response = True ,
1976
- fields = {'i' : 1 })
1977
- self .assertEqual ({'_id' : 2 , 'i' : 1 }, result ["value" ])
1978
- self .assertEqual (False , result ["lastErrorObject" ]["updatedExisting" ])
1971
+ # Test with full_response=True
1972
+ # No lastErrorObject from mongos until 2.0
1973
+ if (not is_mongos (self .db .connection ) or
1974
+ version .at_least (self .db .connection , (2 , 0 ))):
1975
+ result = c .find_and_modify ({'_id' : 1 }, {'$inc' : {'i' : 1 }},
1976
+ new = True , upsert = True ,
1977
+ full_response = True ,
1978
+ fields = {'i' : 1 })
1979
+ self .assertEqual ({'_id' : 1 , 'i' : 5 }, result ["value" ])
1980
+ self .assertEqual (True , result ["lastErrorObject" ]["updatedExisting" ])
1981
+
1982
+ result = c .find_and_modify ({'_id' : 2 }, {'$inc' : {'i' : 1 }},
1983
+ new = True , upsert = True ,
1984
+ full_response = True ,
1985
+ fields = {'i' : 1 })
1986
+ self .assertEqual ({'_id' : 2 , 'i' : 1 }, result ["value" ])
1987
+ self .assertEqual (False , result ["lastErrorObject" ]["updatedExisting" ])
1979
1988
1980
1989
class ExtendedDict (dict ):
1981
1990
pass
0 commit comments