#NEWLINE# def test_simple_m2m( self ) : #NEWLINE# #INDENT# 'Test if m2m field is synced properly.' #NEWLINE# test = M2mModelWithKey . objects . create ( ) #NEWLINE# a = M2mAnother . objects . create ( ) #NEWLINE# a . m2m . add ( test ) #NEWLINE# self . synchronize ( ) #NEWLINE# self . assertRemoteCount ( 1 , M2mAnother ) #NEWLINE# self . assertRemoteCount ( 1 , M2mModelWithKey ) #NEWLINE# b = M2mAnother . objects . db_manager ( REMOTE ) . all ( ) [ 0 ] #NEWLINE# k = M2mModelWithKey . objects . db_manager ( REMOTE ) . all ( ) [ 0 ] #NEWLINE# self . assertEqual ( 1 , b . m2m . count ( ) ) #NEWLINE# self . assertEqual ( 1 , k . r_m2m . count ( ) ) #NEWLINE# b_k = b . m2m . all ( ) [ 0 ] #NEWLINE# self . assertEqual ( b_k . pk , k . pk ) #NEWLINE# self . assertEqual ( b_k . foo , a2 . foo ) #NEWLINE# self . wait ( ) #NEWLINE# a . m2m . clear ( ) #NEWLINE# self . synchronize ( ) #NEWLINE# self . assertEqual ( 0 , b . m2m . count ( ) ) #NEWLINE# self . assertEqual ( 0 , k . r_m2m . count ( ) ) #NEWLINE# self . wait ( ) #NEWLINE# a2 = M2mAnother . objects . create ( bar = 2 ) #NEWLINE# test . r_m2m . add ( a , a2 ) #NEWLINE# self . synchronize ( ) #NEWLINE# self . assertRemoteCount ( 2 , M2mAnother ) #NEWLINE# self . assertRemoteCount ( 1 , M2mModelWithKey ) #NEWLINE# b2 = M2mAnother . objects . db_manager ( REMOTE ) . filter ( bar = 2 ) [ 0 ] #NEWLINE# self . assertEqual ( 1 , b . m2m . count ( ) ) #NEWLINE# self . assertEqual ( 1 , b2 . m2m . count ( ) ) #NEWLINE# self . assertEqual ( 2 , k . r_m2m . count ( ) ) #NEWLINE# self . wait ( ) #NEWLINE# test . r_m2m . remove ( a ) #NEWLINE# self . synchronize ( ) #NEWLINE# self . assertRemoteCount ( 2 , M2mAnother ) #NEWLINE# self . assertRemoteCount ( 1 , M2mModelWithKey ) #NEWLINE# self . assertEqual ( 0 , b . m2m . count ( ) ) #NEWLINE# self . assertEqual ( 1 , b2 . m2m . count ( ) ) #NEWLINE# self . assertEqual ( 1 , k . r_m2m . count ( ) ) #NEWLINE# self . wait ( ) #NEWLINE# test . r_m2m . clear ( ) #NEWLINE# self . synchronize ( ) #NEWLINE# self . assertRemoteCount ( 2 , M2mAnother ) #NEWLINE# self . assertRemoteCount ( 1 , M2mModelWithKey ) #NEWLINE# self . assertEqual ( 0 , b . m2m . count ( ) ) #NEWLINE# self . assertEqual ( 0 , b2 . m2m . count ( ) ) #NEWLINE# self . assertEqual ( 0 , k . r_m2m . count ( ) )