Ejemplo n.º 1
0
 def test_crowdUpdateUserRejoin(self):
     # Create existing DB state.
     new_crowd = {'_id': 1, 'users': ['user1', 'user2'], 'type': 'ats'}
     self.crowdsDB.save(new_crowd) 
     
     # User leaves crowd
     user_leave_time = 1283400000
     user_leaves_crowd = {'_id': 1, 'users': ['user2'], 'type': 'ats'}
     self.crowdsDB = CrowdsDB(crowds_collection, user_leave_time)
     self.crowdsDB.save(user_leaves_crowd)
     
     # User rejoines crowd
     user_rejoin_time = 1283700000
     user_rejoins_crowd = {'_id': 1, 'users': ['user1', 'user2'], 'type': 'ats'}
     self.crowdsDB = CrowdsDB(crowds_collection, user_rejoin_time)
     self.crowdsDB.save(user_rejoins_crowd)
     
     expected_object_in_db = {'_id': 1, 'start': TEST_CURRENT_EPOCH, 'end': None,
                     'users': [
                              {'id':'user1','history': [[TEST_CURRENT_EPOCH, user_leave_time], [user_rejoin_time, None]]},
                              {'id':'user2','history': [[TEST_CURRENT_EPOCH,None]]}, 
                             ],
                    'type': 'ats',
                     'merge' : [],
                     'split' : []
                     }
     actual_object_in_db = crowds_collection.find_one({'_id': 1})
     actual_object_in_db['users'] = sorted([user.items() for user in actual_object_in_db['users']], key=itemgetter(0))
     expected_object_in_db['users'] = sorted([user.items() for user in expected_object_in_db['users']], key=itemgetter(0))
     self.assertEqual(expected_object_in_db, actual_object_in_db)
Ejemplo n.º 2
0
    def test_crowdUpdateUserRejoin(self):
        # Create existing DB state.
        new_crowd = {'_id': 1, 'users': ['user1', 'user2'], 'type': 'ats'}
        self.crowdsDB.save(new_crowd)

        # User leaves crowd
        user_leave_time = 1283400000
        user_leaves_crowd = {'_id': 1, 'users': ['user2'], 'type': 'ats'}
        self.crowdsDB = CrowdsDB(crowds_collection, user_leave_time)
        self.crowdsDB.save(user_leaves_crowd)

        # User rejoines crowd
        user_rejoin_time = 1283700000
        user_rejoins_crowd = {
            '_id': 1,
            'users': ['user1', 'user2'],
            'type': 'ats'
        }
        self.crowdsDB = CrowdsDB(crowds_collection, user_rejoin_time)
        self.crowdsDB.save(user_rejoins_crowd)

        expected_object_in_db = {
            '_id':
            1,
            'start':
            TEST_CURRENT_EPOCH,
            'end':
            None,
            'users': [
                {
                    'id':
                    'user1',
                    'history': [[TEST_CURRENT_EPOCH, user_leave_time],
                                [user_rejoin_time, None]]
                },
                {
                    'id': 'user2',
                    'history': [[TEST_CURRENT_EPOCH, None]]
                },
            ],
            'type':
            'ats',
            'merge': [],
            'split': []
        }
        actual_object_in_db = crowds_collection.find_one({'_id': 1})
        actual_object_in_db['users'] = sorted(
            [user.items() for user in actual_object_in_db['users']],
            key=itemgetter(0))
        expected_object_in_db['users'] = sorted(
            [user.items() for user in expected_object_in_db['users']],
            key=itemgetter(0))
        self.assertEqual(expected_object_in_db, actual_object_in_db)
Ejemplo n.º 3
0
 def test_crowdUpdateUserJoin(self):
     # Create existing DB state.
     existing_data = {'_id': 1, 'users': ['user1', 'user2'], 'type': 'ats'}
     self.crowdsDB.save(existing_data)
     
     # Performing test
     user_join_time = 1283400000
     user_added_data = {'_id': 1, 'users': ['user1', 'user2', 'user3'], 'type': 'ats'}
     self.crowdsDB = CrowdsDB(crowds_collection, user_join_time)
     self.crowdsDB.save(user_added_data)
     
     expected_object_in_db = {'_id': 1, 'start': TEST_CURRENT_EPOCH, 'end': None,
                    'users': [
                              {'id':'user1','history': [[TEST_CURRENT_EPOCH,None]]},
                              {'id':'user2','history': [[TEST_CURRENT_EPOCH,None]]}, 
                              {'id':'user3','history': [[user_join_time,None]]}
                             ], 
                    'type': 'ats',
                     'merge' : [],
                     'split' : []
                     }
     actual_object_in_db =crowds_collection.find_one({'_id': 1})
     actual_object_in_db['users'] = sorted([user.items() for user in actual_object_in_db['users']], key=itemgetter(0))
     expected_object_in_db['users'] = sorted([user.items() for user in expected_object_in_db['users']], key=itemgetter(0))
     self.assertEqual(expected_object_in_db, actual_object_in_db)
Ejemplo n.º 4
0
    def test_crowdUpdateUserJoin(self):
        # Create existing DB state.
        existing_data = {'_id': 1, 'users': ['user1', 'user2'], 'type': 'ats'}
        self.crowdsDB.save(existing_data)

        # Performing test
        user_join_time = 1283400000
        user_added_data = {
            '_id': 1,
            'users': ['user1', 'user2', 'user3'],
            'type': 'ats'
        }
        self.crowdsDB = CrowdsDB(crowds_collection, user_join_time)
        self.crowdsDB.save(user_added_data)

        expected_object_in_db = {
            '_id':
            1,
            'start':
            TEST_CURRENT_EPOCH,
            'end':
            None,
            'users': [{
                'id': 'user1',
                'history': [[TEST_CURRENT_EPOCH, None]]
            }, {
                'id': 'user2',
                'history': [[TEST_CURRENT_EPOCH, None]]
            }, {
                'id': 'user3',
                'history': [[user_join_time, None]]
            }],
            'type':
            'ats',
            'merge': [],
            'split': []
        }
        actual_object_in_db = crowds_collection.find_one({'_id': 1})
        actual_object_in_db['users'] = sorted(
            [user.items() for user in actual_object_in_db['users']],
            key=itemgetter(0))
        expected_object_in_db['users'] = sorted(
            [user.items() for user in expected_object_in_db['users']],
            key=itemgetter(0))
        self.assertEqual(expected_object_in_db, actual_object_in_db)
Ejemplo n.º 5
0
    def test_crowdUpdateEndTime(self):
        crowd_id = 1
        end_time = 1283700000
        new_crowd_data = {
            '_id': crowd_id,
            'users': ['user1', 'user2'],
            'type': 'ats'
        }
        self.crowdsDB.save(new_crowd_data)

        expected_object_in_db = {
            '_id':
            1,
            'start':
            TEST_CURRENT_EPOCH,
            'end':
            end_time,
            'users': [
                {
                    'id': 'user1',
                    'history': [[TEST_CURRENT_EPOCH, None]]
                },
                {
                    'id': 'user2',
                    'history': [[TEST_CURRENT_EPOCH, None]]
                },
            ],
            'type':
            'ats',
            'merge': [],
            'split': []
        }

        self.crowdsDB = CrowdsDB(crowds_collection, end_time)
        self.crowdsDB.updateEndTime(crowd_id)
        actual_object_in_db = crowds_collection.find_one({'_id': 1})
        actual_object_in_db['users'] = sorted(
            [user.items() for user in actual_object_in_db['users']],
            key=itemgetter(0))
        expected_object_in_db['users'] = sorted(
            [user.items() for user in expected_object_in_db['users']],
            key=itemgetter(0))
        self.assertEqual(expected_object_in_db, actual_object_in_db)
Ejemplo n.º 6
0
 def test_crowdUpdateEndTime(self):
     crowd_id = 1
     end_time = 1283700000
     new_crowd_data = {'_id': crowd_id, 'users': ['user1', 'user2'], 'type': 'ats'}
     self.crowdsDB.save(new_crowd_data)
     
     expected_object_in_db = {'_id': 1, 'start': TEST_CURRENT_EPOCH, 'end': end_time,
                    'users': [
                              {'id':'user1','history': [[TEST_CURRENT_EPOCH,None]]}, 
                              {'id':'user2','history': [[TEST_CURRENT_EPOCH,None]]}, 
                             ], 
                    'type': 'ats',
                     'merge' : [],
                     'split' : []
                     }
     
     self.crowdsDB = CrowdsDB(crowds_collection, end_time)
     self.crowdsDB.updateEndTime(crowd_id) 
     actual_object_in_db=crowds_collection.find_one({'_id': 1})
     actual_object_in_db['users'] = sorted([user.items() for user in actual_object_in_db['users']], key=itemgetter(0))
     expected_object_in_db['users'] = sorted([user.items() for user in expected_object_in_db['users']], key=itemgetter(0))
     self.assertEqual(expected_object_in_db, actual_object_in_db)
Ejemplo n.º 7
0
 def setUp(self):
     crowds_db.drop_collection(crowds_collection)
     self.crowdsDB = CrowdsDB(crowds_collection, TEST_CURRENT_EPOCH)
Ejemplo n.º 8
0
class CrowdsDBTests(unittest.TestCase):
    def setUp(self):
        crowds_db.drop_collection(crowds_collection)
        self.crowdsDB = CrowdsDB(crowds_collection, TEST_CURRENT_EPOCH)

    def test_newCrowdAdd(self):
        data_to_save = {'_id': 1, 'users': ['user1', 'user2'], 'type': 'ats'}
        expected_object_in_db = {
            '_id':
            1,
            'start':
            TEST_CURRENT_EPOCH,
            'end':
            None,
            'users': [
                {
                    'id': 'user1',
                    'history': [[TEST_CURRENT_EPOCH, None]]
                },
                {
                    'id': 'user2',
                    'history': [[TEST_CURRENT_EPOCH, None]]
                },
            ],
            'type':
            'ats',
            'merge': [],
            'split': []
        }
        self.crowdsDB.save(data_to_save)
        actual_object_in_db = crowds_collection.find_one({'_id': 1})
        actual_object_in_db['users'] = sorted(
            [user.items() for user in actual_object_in_db['users']],
            key=itemgetter(0))
        expected_object_in_db['users'] = sorted(
            [user.items() for user in expected_object_in_db['users']],
            key=itemgetter(0))
        self.assertEqual(expected_object_in_db, actual_object_in_db)

    def test_crowdUpdateUserJoin(self):
        # Create existing DB state.
        existing_data = {'_id': 1, 'users': ['user1', 'user2'], 'type': 'ats'}
        self.crowdsDB.save(existing_data)

        # Performing test
        user_join_time = 1283400000
        user_added_data = {
            '_id': 1,
            'users': ['user1', 'user2', 'user3'],
            'type': 'ats'
        }
        self.crowdsDB = CrowdsDB(crowds_collection, user_join_time)
        self.crowdsDB.save(user_added_data)

        expected_object_in_db = {
            '_id':
            1,
            'start':
            TEST_CURRENT_EPOCH,
            'end':
            None,
            'users': [{
                'id': 'user1',
                'history': [[TEST_CURRENT_EPOCH, None]]
            }, {
                'id': 'user2',
                'history': [[TEST_CURRENT_EPOCH, None]]
            }, {
                'id': 'user3',
                'history': [[user_join_time, None]]
            }],
            'type':
            'ats',
            'merge': [],
            'split': []
        }
        actual_object_in_db = crowds_collection.find_one({'_id': 1})
        actual_object_in_db['users'] = sorted(
            [user.items() for user in actual_object_in_db['users']],
            key=itemgetter(0))
        expected_object_in_db['users'] = sorted(
            [user.items() for user in expected_object_in_db['users']],
            key=itemgetter(0))
        self.assertEqual(expected_object_in_db, actual_object_in_db)

    def test_crowdUpdateUserDrop(self):
        # Create existing DB state.
        new_crowd = {'_id': 1, 'users': ['user1', 'user2'], 'type': 'ats'}
        self.crowdsDB.save(new_crowd)

        # User leaves crowd
        user_leave_time = 1283400000
        user_leaves_crowd = {'_id': 1, 'users': ['user2'], 'type': 'ats'}
        self.crowdsDB = CrowdsDB(crowds_collection, user_leave_time)
        self.crowdsDB.save(user_leaves_crowd)

        expected_object_in_db = {
            '_id':
            1,
            'start':
            TEST_CURRENT_EPOCH,
            'end':
            None,
            'users': [
                {
                    'id': 'user1',
                    'history': [[TEST_CURRENT_EPOCH, user_leave_time]]
                },
                {
                    'id': 'user2',
                    'history': [[TEST_CURRENT_EPOCH, None]]
                },
            ],
            'type':
            'ats',
            'merge': [],
            'split': []
        }
        actual_object_in_db = crowds_collection.find_one({'_id': 1})
        actual_object_in_db['users'] = sorted(
            [user.items() for user in actual_object_in_db['users']],
            key=itemgetter(0))
        expected_object_in_db['users'] = sorted(
            [user.items() for user in expected_object_in_db['users']],
            key=itemgetter(0))
        self.assertEqual(expected_object_in_db, actual_object_in_db)

    def test_crowdUpdateUserRejoin(self):
        # Create existing DB state.
        new_crowd = {'_id': 1, 'users': ['user1', 'user2'], 'type': 'ats'}
        self.crowdsDB.save(new_crowd)

        # User leaves crowd
        user_leave_time = 1283400000
        user_leaves_crowd = {'_id': 1, 'users': ['user2'], 'type': 'ats'}
        self.crowdsDB = CrowdsDB(crowds_collection, user_leave_time)
        self.crowdsDB.save(user_leaves_crowd)

        # User rejoines crowd
        user_rejoin_time = 1283700000
        user_rejoins_crowd = {
            '_id': 1,
            'users': ['user1', 'user2'],
            'type': 'ats'
        }
        self.crowdsDB = CrowdsDB(crowds_collection, user_rejoin_time)
        self.crowdsDB.save(user_rejoins_crowd)

        expected_object_in_db = {
            '_id':
            1,
            'start':
            TEST_CURRENT_EPOCH,
            'end':
            None,
            'users': [
                {
                    'id':
                    'user1',
                    'history': [[TEST_CURRENT_EPOCH, user_leave_time],
                                [user_rejoin_time, None]]
                },
                {
                    'id': 'user2',
                    'history': [[TEST_CURRENT_EPOCH, None]]
                },
            ],
            'type':
            'ats',
            'merge': [],
            'split': []
        }
        actual_object_in_db = crowds_collection.find_one({'_id': 1})
        actual_object_in_db['users'] = sorted(
            [user.items() for user in actual_object_in_db['users']],
            key=itemgetter(0))
        expected_object_in_db['users'] = sorted(
            [user.items() for user in expected_object_in_db['users']],
            key=itemgetter(0))
        self.assertEqual(expected_object_in_db, actual_object_in_db)

    def test_crowdMerge(self):
        crowd_id, merged_crowd_id = 1, 2
        merge_time = 1283700000
        new_crowd_data = {
            '_id': crowd_id,
            'users': ['user1', 'user2'],
            'type': 'ats'
        }
        self.crowdsDB.save(new_crowd_data)

        expected_object_in_db = {
            '_id':
            1,
            'start':
            TEST_CURRENT_EPOCH,
            'end':
            None,
            'users': [
                {
                    'id': 'user1',
                    'history': [[TEST_CURRENT_EPOCH, None]]
                },
                {
                    'id': 'user2',
                    'history': [[TEST_CURRENT_EPOCH, None]]
                },
            ],
            'type':
            'ats',
            'merge': [[merged_crowd_id, merge_time]],
            'split': []
        }

        self.crowdsDB = CrowdsDB(crowds_collection, merge_time)
        self.crowdsDB.updateCrowdMerge(crowd_id, merged_crowd_id)
        actual_object_in_db = crowds_collection.find_one({'_id': 1})
        actual_object_in_db['users'] = sorted(
            [user.items() for user in actual_object_in_db['users']],
            key=itemgetter(0))
        expected_object_in_db['users'] = sorted(
            [user.items() for user in expected_object_in_db['users']],
            key=itemgetter(0))
        self.assertEqual(expected_object_in_db, actual_object_in_db)

    def test_crowdSplit(self):
        crowd_id, split_crowd_id = 1, 2
        split_time = 1283700000
        new_crowd_data = {
            '_id': crowd_id,
            'users': ['user1', 'user2'],
            'type': 'ats'
        }
        self.crowdsDB.save(new_crowd_data)

        expected_object_in_db = {
            '_id':
            1,
            'start':
            TEST_CURRENT_EPOCH,
            'end':
            None,
            'users': [
                {
                    'id': 'user1',
                    'history': [[TEST_CURRENT_EPOCH, None]]
                },
                {
                    'id': 'user2',
                    'history': [[TEST_CURRENT_EPOCH, None]]
                },
            ],
            'type':
            'ats',
            'merge': [],
            'split': [[split_crowd_id, split_time]]
        }

        self.crowdsDB = CrowdsDB(crowds_collection, split_time)
        self.crowdsDB.updateCrowdSplit(crowd_id, split_crowd_id)
        actual_object_in_db = crowds_collection.find_one({'_id': 1})
        actual_object_in_db['users'] = sorted(
            [user.items() for user in actual_object_in_db['users']],
            key=itemgetter(0))
        expected_object_in_db['users'] = sorted(
            [user.items() for user in expected_object_in_db['users']],
            key=itemgetter(0))
        self.assertEqual(expected_object_in_db, actual_object_in_db)

    def test_crowdUpdateEndTime(self):
        crowd_id = 1
        end_time = 1283700000
        new_crowd_data = {
            '_id': crowd_id,
            'users': ['user1', 'user2'],
            'type': 'ats'
        }
        self.crowdsDB.save(new_crowd_data)

        expected_object_in_db = {
            '_id':
            1,
            'start':
            TEST_CURRENT_EPOCH,
            'end':
            end_time,
            'users': [
                {
                    'id': 'user1',
                    'history': [[TEST_CURRENT_EPOCH, None]]
                },
                {
                    'id': 'user2',
                    'history': [[TEST_CURRENT_EPOCH, None]]
                },
            ],
            'type':
            'ats',
            'merge': [],
            'split': []
        }

        self.crowdsDB = CrowdsDB(crowds_collection, end_time)
        self.crowdsDB.updateEndTime(crowd_id)
        actual_object_in_db = crowds_collection.find_one({'_id': 1})
        actual_object_in_db['users'] = sorted(
            [user.items() for user in actual_object_in_db['users']],
            key=itemgetter(0))
        expected_object_in_db['users'] = sorted(
            [user.items() for user in expected_object_in_db['users']],
            key=itemgetter(0))
        self.assertEqual(expected_object_in_db, actual_object_in_db)
Ejemplo n.º 9
0
 def setUp(self):
     crowds_db.drop_collection(crowds_collection)
     self.crowdsDB = CrowdsDB(crowds_collection, TEST_CURRENT_EPOCH)
Ejemplo n.º 10
0
class CrowdsDBTests(unittest.TestCase):
    def setUp(self):
        crowds_db.drop_collection(crowds_collection)
        self.crowdsDB = CrowdsDB(crowds_collection, TEST_CURRENT_EPOCH)
    
    def test_newCrowdAdd(self):
        data_to_save = {'_id': 1, 'users': ['user1', 'user2'], 'type': 'ats'}
        expected_object_in_db = {'_id': 1, 'start': TEST_CURRENT_EPOCH, 'end': None,
                       'users': [
                                 {'id':'user1','history': [[TEST_CURRENT_EPOCH,None]]}, 
                                 {'id':'user2','history': [[TEST_CURRENT_EPOCH,None]]}, 
                                ], 
                       'type': 'ats',
                        'merge' : [],
                        'split' : []
                        }
        self.crowdsDB.save(data_to_save)
        actual_object_in_db = crowds_collection.find_one({'_id': 1})
        actual_object_in_db['users'] = sorted([user.items() for user in actual_object_in_db['users']], key=itemgetter(0))
        expected_object_in_db['users'] = sorted([user.items() for user in expected_object_in_db['users']], key=itemgetter(0))
        self.assertEqual(expected_object_in_db, actual_object_in_db)
    
    def test_crowdUpdateUserJoin(self):
        # Create existing DB state.
        existing_data = {'_id': 1, 'users': ['user1', 'user2'], 'type': 'ats'}
        self.crowdsDB.save(existing_data)
        
        # Performing test
        user_join_time = 1283400000
        user_added_data = {'_id': 1, 'users': ['user1', 'user2', 'user3'], 'type': 'ats'}
        self.crowdsDB = CrowdsDB(crowds_collection, user_join_time)
        self.crowdsDB.save(user_added_data)
        
        expected_object_in_db = {'_id': 1, 'start': TEST_CURRENT_EPOCH, 'end': None,
                       'users': [
                                 {'id':'user1','history': [[TEST_CURRENT_EPOCH,None]]},
                                 {'id':'user2','history': [[TEST_CURRENT_EPOCH,None]]}, 
                                 {'id':'user3','history': [[user_join_time,None]]}
                                ], 
                       'type': 'ats',
                        'merge' : [],
                        'split' : []
                        }
        actual_object_in_db =crowds_collection.find_one({'_id': 1})
        actual_object_in_db['users'] = sorted([user.items() for user in actual_object_in_db['users']], key=itemgetter(0))
        expected_object_in_db['users'] = sorted([user.items() for user in expected_object_in_db['users']], key=itemgetter(0))
        self.assertEqual(expected_object_in_db, actual_object_in_db)


    def test_crowdUpdateUserDrop(self):
        # Create existing DB state.
        new_crowd = {'_id': 1, 'users': ['user1', 'user2'], 'type': 'ats'}
        self.crowdsDB.save(new_crowd) 
        
        # User leaves crowd
        user_leave_time = 1283400000
        user_leaves_crowd = {'_id': 1, 'users': ['user2'], 'type': 'ats'}
        self.crowdsDB = CrowdsDB(crowds_collection, user_leave_time)
        self.crowdsDB.save(user_leaves_crowd)
        
        expected_object_in_db = {'_id': 1, 'start': TEST_CURRENT_EPOCH, 'end': None,
                        'users': [
                                 {'id':'user1','history': [[TEST_CURRENT_EPOCH,user_leave_time]]},
                                 {'id':'user2','history': [[TEST_CURRENT_EPOCH,None]]}, 
                                ], 
                        'type': 'ats',
                        'merge' : [],
                        'split' : []
                        }
        actual_object_in_db = crowds_collection.find_one({'_id': 1})
        actual_object_in_db['users'] = sorted([user.items() for user in actual_object_in_db['users']], key=itemgetter(0))
        expected_object_in_db['users'] = sorted([user.items() for user in expected_object_in_db['users']], key=itemgetter(0))
        self.assertEqual(expected_object_in_db, actual_object_in_db)

    def test_crowdUpdateUserRejoin(self):
        # Create existing DB state.
        new_crowd = {'_id': 1, 'users': ['user1', 'user2'], 'type': 'ats'}
        self.crowdsDB.save(new_crowd) 
        
        # User leaves crowd
        user_leave_time = 1283400000
        user_leaves_crowd = {'_id': 1, 'users': ['user2'], 'type': 'ats'}
        self.crowdsDB = CrowdsDB(crowds_collection, user_leave_time)
        self.crowdsDB.save(user_leaves_crowd)
        
        # User rejoines crowd
        user_rejoin_time = 1283700000
        user_rejoins_crowd = {'_id': 1, 'users': ['user1', 'user2'], 'type': 'ats'}
        self.crowdsDB = CrowdsDB(crowds_collection, user_rejoin_time)
        self.crowdsDB.save(user_rejoins_crowd)
        
        expected_object_in_db = {'_id': 1, 'start': TEST_CURRENT_EPOCH, 'end': None,
                        'users': [
                                 {'id':'user1','history': [[TEST_CURRENT_EPOCH, user_leave_time], [user_rejoin_time, None]]},
                                 {'id':'user2','history': [[TEST_CURRENT_EPOCH,None]]}, 
                                ],
                       'type': 'ats',
                        'merge' : [],
                        'split' : []
                        }
        actual_object_in_db = crowds_collection.find_one({'_id': 1})
        actual_object_in_db['users'] = sorted([user.items() for user in actual_object_in_db['users']], key=itemgetter(0))
        expected_object_in_db['users'] = sorted([user.items() for user in expected_object_in_db['users']], key=itemgetter(0))
        self.assertEqual(expected_object_in_db, actual_object_in_db)

    def test_crowdMerge(self):
        crowd_id, merged_crowd_id = 1, 2
        merge_time = 1283700000
        new_crowd_data = {'_id': crowd_id, 'users': ['user1', 'user2'], 'type': 'ats'}
        self.crowdsDB.save(new_crowd_data)
        
        expected_object_in_db = {'_id': 1, 'start': TEST_CURRENT_EPOCH, 'end': None,
                       'users': [
                                 {'id':'user1','history': [[TEST_CURRENT_EPOCH,None]]}, 
                                 {'id':'user2','history': [[TEST_CURRENT_EPOCH,None]]}, 
                                ], 
                       'type': 'ats',
                        'merge' : [[merged_crowd_id, merge_time]],
                        'split' : []
                        }
        
        self.crowdsDB = CrowdsDB(crowds_collection, merge_time)
        self.crowdsDB.updateCrowdMerge(crowd_id, merged_crowd_id) 
        actual_object_in_db=crowds_collection.find_one({'_id': 1})
        actual_object_in_db['users'] = sorted([user.items() for user in actual_object_in_db['users']], key=itemgetter(0))
        expected_object_in_db['users'] = sorted([user.items() for user in expected_object_in_db['users']], key=itemgetter(0))
        self.assertEqual(expected_object_in_db, actual_object_in_db)

    def test_crowdSplit(self):
        crowd_id, split_crowd_id = 1, 2
        split_time = 1283700000
        new_crowd_data = {'_id': crowd_id, 'users': ['user1', 'user2'], 'type': 'ats'}
        self.crowdsDB.save(new_crowd_data)
        
        expected_object_in_db = {'_id': 1, 'start': TEST_CURRENT_EPOCH, 'end': None,
                       'users': [
                                 {'id':'user1','history': [[TEST_CURRENT_EPOCH,None]]}, 
                                 {'id':'user2','history': [[TEST_CURRENT_EPOCH,None]]}, 
                                ], 
                       'type': 'ats',
                        'merge' : [],
                        'split' : [[split_crowd_id, split_time]]
                        }
        
        self.crowdsDB = CrowdsDB(crowds_collection, split_time)
        self.crowdsDB.updateCrowdSplit(crowd_id, split_crowd_id) 
        actual_object_in_db=crowds_collection.find_one({'_id': 1})
        actual_object_in_db['users'] = sorted([user.items() for user in actual_object_in_db['users']], key=itemgetter(0))
        expected_object_in_db['users'] = sorted([user.items() for user in expected_object_in_db['users']], key=itemgetter(0))
        self.assertEqual(expected_object_in_db, actual_object_in_db)
        
    def test_crowdUpdateEndTime(self):
        crowd_id = 1
        end_time = 1283700000
        new_crowd_data = {'_id': crowd_id, 'users': ['user1', 'user2'], 'type': 'ats'}
        self.crowdsDB.save(new_crowd_data)
        
        expected_object_in_db = {'_id': 1, 'start': TEST_CURRENT_EPOCH, 'end': end_time,
                       'users': [
                                 {'id':'user1','history': [[TEST_CURRENT_EPOCH,None]]}, 
                                 {'id':'user2','history': [[TEST_CURRENT_EPOCH,None]]}, 
                                ], 
                       'type': 'ats',
                        'merge' : [],
                        'split' : []
                        }
        
        self.crowdsDB = CrowdsDB(crowds_collection, end_time)
        self.crowdsDB.updateEndTime(crowd_id) 
        actual_object_in_db=crowds_collection.find_one({'_id': 1})
        actual_object_in_db['users'] = sorted([user.items() for user in actual_object_in_db['users']], key=itemgetter(0))
        expected_object_in_db['users'] = sorted([user.items() for user in expected_object_in_db['users']], key=itemgetter(0))
        self.assertEqual(expected_object_in_db, actual_object_in_db)