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']}}) # lint-amnesty, pylint: disable=line-too-long self.bulk._end_bulk_operation(self.course_key) six.assertCountEqual(self, [ call.insert_structure(self.structure, self.course_key), call.insert_structure(other_structure, self.course_key), call.update_course_index( { 'versions': { 'a': self.structure['_id'], 'b': other_structure['_id'] } }, from_index=original_index, course_context=self.course_key, ) ], self.conn.mock_calls)
def test_write_index_and_multiple_definitions_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_definition(self.course_key.replace(branch='a'), self.definition) other_definition = {'another': 'definition', '_id': ObjectId()} self.bulk.update_definition(self.course_key.replace(branch='b'), other_definition) self.bulk.insert_course_index( self.course_key, { 'versions': { 'a': self.definition['_id'], 'b': other_definition['_id'] } }) self.bulk._end_bulk_operation(self.course_key) six.assertCountEqual(self, [ call.insert_definition(self.definition, self.course_key), call.insert_definition(other_definition, self.course_key), call.update_course_index( { 'versions': { 'a': self.definition['_id'], 'b': other_definition['_id'] } }, from_index=original_index, course_context=self.course_key, ) ], self.conn.mock_calls)
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.insert_structure(self.structure), call.insert_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.insert_structure(self.structure), call.update_course_index( {'versions': {self.course_key.branch: self.structure['_id']}}, from_index=original_index ) )
def test_write_index_and_definition_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_definition(self.course_key, self.definition) self.bulk.insert_course_index(self.course_key, {"versions": {self.course_key.branch: self.definition["_id"]}}) self.assertConnCalls() self.bulk._end_bulk_operation(self.course_key) self.assertConnCalls( call.insert_definition(self.definition, self.course_key), call.update_course_index( {"versions": {self.course_key.branch: self.definition["_id"]}}, from_index=original_index, course_context=self.course_key, ), )
def test_write_index_and_definition_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_definition(self.course_key, self.definition) self.bulk.insert_course_index( self.course_key, {'versions': { self.course_key.branch: self.definition['_id'] }}) # lint-amnesty, pylint: disable=no-member self.assertConnCalls() self.bulk._end_bulk_operation(self.course_key) self.assertConnCalls( call.insert_definition(self.definition, self.course_key), call.update_course_index( {'versions': { self.course_key.branch: self.definition['_id'] }}, # lint-amnesty, pylint: disable=no-member from_index=original_index, course_context=self.course_key))
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.insert_structure(self.structure), call.insert_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_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.insert_structure(self.structure, self.course_key), call.insert_structure(other_structure, self.course_key), call.update_course_index( {"versions": {"a": self.structure["_id"], "b": other_structure["_id"]}}, from_index=original_index, course_context=self.course_key, ), ], self.conn.mock_calls, )