Exemplo n.º 1
0
 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)
     self.assertCountEqual([
         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)
Exemplo n.º 2
0
 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.assertCountEqual([
         call.insert_structure(self.structure, self.course_key),
         call.insert_structure(other_structure, self.course_key)
     ], 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.insert_structure(self.structure, self.course_key))
     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.insert_structure(self.structure, self.course_key))
 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']}})  # lint-amnesty, pylint: disable=no-member
     self.assertConnCalls()
     self.bulk._end_bulk_operation(self.course_key)
     self.assertConnCalls(
         call.insert_structure(self.structure, self.course_key),
         call.update_course_index(
             {'versions': {self.course_key.branch: self.structure['_id']}},  # lint-amnesty, pylint: disable=no-member
             from_index=original_index,
             course_context=self.course_key,
         )
     )