def test_write_index_and_multiple_structures_on_close(self): original_index = {'versions': {'a': ObjectId(), 'b': ObjectId()}} self.conn.get_course_index.return_value = copy.deepcopy(original_index) self.bulk._begin_bulk_operation(self.course_key) self.conn.reset_mock() self.bulk.update_structure(self.course_key.replace(branch='a'), self.structure) other_structure = {'another': 'structure', '_id': ObjectId()} self.bulk.update_structure(self.course_key.replace(branch='b'), other_structure) self.bulk.insert_course_index(self.course_key, { 'versions': { 'a': self.structure['_id'], 'b': other_structure['_id'] } }) self.bulk._end_bulk_operation(self.course_key) self.assertItemsEqual([ call.upsert_structure(self.structure), call.upsert_structure(other_structure), call.update_course_index( { 'versions': { 'a': self.structure['_id'], 'b': other_structure['_id'] } }, from_index=original_index) ], self.conn.mock_calls)
def test_write_multiple_structures_on_close(self): self.conn.get_course_index.return_value = None self.bulk._begin_bulk_operation(self.course_key) self.conn.reset_mock() self.bulk.update_structure(self.course_key.replace(branch='a'), self.structure) other_structure = {'another': 'structure', '_id': ObjectId()} self.bulk.update_structure(self.course_key.replace(branch='b'), other_structure) self.assertConnCalls() self.bulk._end_bulk_operation(self.course_key) self.assertItemsEqual( [call.upsert_structure(self.structure), call.upsert_structure(other_structure)], self.conn.mock_calls )
def test_write_multiple_structures_on_close(self): self.conn.get_course_index.return_value = None self.bulk._begin_bulk_operation(self.course_key) self.conn.reset_mock() self.bulk.update_structure(self.course_key.replace(branch='a'), self.structure) other_structure = {'another': 'structure', '_id': ObjectId()} self.bulk.update_structure(self.course_key.replace(branch='b'), other_structure) self.assertConnCalls() self.bulk._end_bulk_operation(self.course_key) self.assertItemsEqual([ call.upsert_structure(self.structure), call.upsert_structure(other_structure) ], self.conn.mock_calls)
def test_no_bulk_write_structure(self): # Writing a structure when no bulk operation is active should just # call through to the db_connection. It should also clear the # system cache self.bulk.update_structure(self.course_key, self.structure) self.assertConnCalls(call.upsert_structure(self.structure)) self.clear_cache.assert_called_once_with(self.structure['_id'])
def test_write_structure_on_close(self): self.conn.get_course_index.return_value = None self.bulk._begin_bulk_operation(self.course_key) self.conn.reset_mock() self.bulk.update_structure(self.course_key, self.structure) self.assertConnCalls() self.bulk._end_bulk_operation(self.course_key) self.assertConnCalls(call.upsert_structure(self.structure))
def test_write_index_and_multiple_structures_on_close(self): original_index = {'versions': {'a': ObjectId(), 'b': ObjectId()}} self.conn.get_course_index.return_value = copy.deepcopy(original_index) self.bulk._begin_bulk_operation(self.course_key) self.conn.reset_mock() self.bulk.update_structure(self.course_key.replace(branch='a'), self.structure) other_structure = {'another': 'structure', '_id': ObjectId()} self.bulk.update_structure(self.course_key.replace(branch='b'), other_structure) self.bulk.insert_course_index(self.course_key, {'versions': {'a': self.structure['_id'], 'b': other_structure['_id']}}) self.bulk._end_bulk_operation(self.course_key) self.assertItemsEqual( [ call.upsert_structure(self.structure), call.upsert_structure(other_structure), call.update_course_index( {'versions': {'a': self.structure['_id'], 'b': other_structure['_id']}}, from_index=original_index ) ], self.conn.mock_calls )
def test_write_index_and_structure_on_close(self): original_index = {'versions': {}} self.conn.get_course_index.return_value = copy.deepcopy(original_index) self.bulk._begin_bulk_operation(self.course_key) self.conn.reset_mock() self.bulk.update_structure(self.course_key, self.structure) self.bulk.insert_course_index(self.course_key, {'versions': {self.course_key.branch: self.structure['_id']}}) self.assertConnCalls() self.bulk._end_bulk_operation(self.course_key) self.assertConnCalls( call.upsert_structure(self.structure), call.update_course_index( {'versions': {self.course_key.branch: self.structure['_id']}}, from_index=original_index ) )
def test_write_index_and_structure_on_close(self): original_index = {'versions': {}} self.conn.get_course_index.return_value = copy.deepcopy(original_index) self.bulk._begin_bulk_operation(self.course_key) self.conn.reset_mock() self.bulk.update_structure(self.course_key, self.structure) self.bulk.insert_course_index( self.course_key, {'versions': { self.course_key.branch: self.structure['_id'] }}) self.assertConnCalls() self.bulk._end_bulk_operation(self.course_key) self.assertConnCalls( call.upsert_structure(self.structure), call.update_course_index( {'versions': { self.course_key.branch: self.structure['_id'] }}, from_index=original_index))