Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-957

Lacking rich comparison method(s) for write operations

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Trivial - P5 Trivial - P5
    • 3.1
    • Affects Version/s: None
    • Component/s: None
    • None

      I'd like to mock the driver in unit tests and assert that e.g. the bulk_write method was called with some object instances, as in:

      @patch('pymongo.MongoClient')
      def test_update(self, mock_mongo):
          test_items = pd.DataFrame({'id_field': [1, 2], 'foo': [42, 23]})
          save_items(mock_mongo, test_items)  # method under test
      
          mock_mongo.db.items.bulk_write.assert_called_with([
              UpdateOne({'id_field': 1}, {'$set': {'foo': 42}}),
              UpdateOne({'id_field': 2}, {'$set': {'foo': 23}})
          ])
      

      However, this assertion fails because the UpdateOne class (or its superclass) doesn't have a rich comparison method such as __eq__.

      Was there a specific reason for not implementing this? If not, is it ok if I implement it in e.g. the _WriteOp class and create a pull request?

            Assignee:
            bernie@mongodb.com Bernie Hackett
            Reporter:
            jsamoocha Jonatan Samoocha
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: