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']}}) # lint-amnesty, pylint: disable=line-too-long 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_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) self.assertItemsEqual([ call.insert_definition(self.definition), call.insert_definition(other_definition), call.update_course_index( { 'versions': { 'a': self.definition['_id'], 'b': other_definition['_id'] } }, from_index=original_index) ], self.conn.mock_calls)
def test_write_multiple_definitions_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_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.assertConnCalls() self.bulk._end_bulk_operation(self.course_key) self.assertItemsEqual( [call.insert_definition(self.definition), call.insert_definition(other_definition)], self.conn.mock_calls )
def test_write_definition_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_definition(self.course_key, self.definition) self.assertConnCalls() self.bulk._end_bulk_operation(self.course_key) self.assertConnCalls(call.insert_definition(self.definition, self.course_key))
def test_write_definition_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_definition(self.course_key, self.definition) self.assertConnCalls() self.bulk._end_bulk_operation(self.course_key) self.assertConnCalls(call.insert_definition(self.definition))
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) self.assertItemsEqual( [ call.insert_definition(self.definition), call.insert_definition(other_definition), call.update_course_index( {'versions': {'a': self.definition['_id'], 'b': other_definition['_id']}}, from_index=original_index ) ], 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) self.assertItemsEqual( [ 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_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), call.update_course_index( {'versions': {self.course_key.branch: self.definition['_id']}}, from_index=original_index ) )
def test_no_bulk_write_definition(self): # Writing a definition when no bulk operation is active should just # call through to the db_connection. self.bulk.update_definition(self.course_key, self.definition) self.assertConnCalls( call.insert_definition(self.definition, self.course_key))
def test_no_bulk_write_definition(self): # Writing a definition when no bulk operation is active should just # call through to the db_connection. self.bulk.update_definition(self.course_key, self.definition) self.assertConnCalls(call.insert_definition(self.definition, self.course_key))