def test_save_old(self, mock_db): update: MagicMock = mock_db.__getitem__.return_value.update_one doc = Document(_id='test') doc.save() update.assert_called_once_with({'_id': 'test'}, {'$set': {}}, session=None) assert doc._id == 'test'
def test_save_invalid(self): doc = Document(collection='test') doc.is_valid = lambda: False with pytest.raises(Document.DocumentInvalid): doc.save()
def test_save_new(self, mock_db): insert: MagicMock = mock_db.__getitem__.return_value.insert_one insert.return_value.inserted_id.return_value = 42 doc = Document() doc.save() insert.assert_called_once_with({}, session=None)