Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to mock with_for_update #67

Open
hmajid2301 opened this issue Apr 10, 2021 · 3 comments
Open

How to mock with_for_update #67

hmajid2301 opened this issue Apr 10, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@hmajid2301
Copy link

Hi,

Im struggling to mock out

session.query(Model).filter(Model.a != False).with_for_update()

Using the following (return_object just being a list of Model to return).

  session = UnifiedAlchemyMagicMock(
      data=[
          (
              [
                  mock.call.query(Model),
                  mock.call.filter(Model.a != False),
                  mock.call.with_for_update(),
              ],
              return_object,
          ),
      ]
  )

If I remove the mock.call.with_for_update(), the example below works.

session.query(Model).filter(Model.a != False).first()
@rajivsarvepalli
Copy link
Owner

rajivsarvepalli commented Apr 15, 2021

mock.call.with_for_update() is not a supported command as of now. I believe this call returns a query which can be used later on. I will look into adding these types of commands. If I am not mistaken,

session.query(Model).filter(Model.a != False).with_for_update()

should return a query object, and not a list of objects according sqlalchemy documentation? Let me know what you think the expected behavior of the line

session.query(Model).filter(Model.a != False).with_for_update()

should be for the testing library. Would you expect a query object with some of the functionality of the query object in SQLAlchemy? I could look into adding that but that would be a considerable addition and therefore take some time.

@hmajid2301
Copy link
Author

Yeh it's a good point, with_for_update() I believe is usually used to lock row it "touches" in the db. So I suppose for now if it just returns a query object back that is fine. The testing of the actual mechanism of locking could (and perhaps should be) done outside of unit tests.

@rajivsarvepalli rajivsarvepalli added the enhancement New feature or request label May 6, 2021
@zeason
Copy link

zeason commented Apr 30, 2024

@rajivsarvepalli Hi, just want to check if there is any progress on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants