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

Recursive Mock #6

Open
bakera1 opened this issue Jul 11, 2018 · 3 comments
Open

Recursive Mock #6

bakera1 opened this issue Jul 11, 2018 · 3 comments

Comments

@bakera1
Copy link

bakera1 commented Jul 11, 2018

I would like to understand how these objects could be extended to allow recursive operations. Let me explain a little of what this might look like. For example, it is often the case where

def setUp():
session = UnifiedAlchemyMagicMock( ...)

def my_test(self):
first_item = session.query(Blah).filter(Blah.foo == 'bar').first()
all_items = first_item.my_relationship.filter(Foo.bar == 'blah blah').all()

I can successfully replicate using examples the first item; however I would like all objects that are subsequently passed back from the UnifiedAlchemyMagicMock() class instance to have have embedded the same mixin as the session that I originally setup. This would allow "first_item.my_relationship.filter(" type calls on those objects via the same single setup.

My ultimate goal is also to boostrap the UnifiedAlchemyMagicMock.data from a json file; that I have first streamed out of a real set of SQLAlchemy objects. This

SQL DB ---> json file --> UnifiedAlchemyMagicMock.data --> tests

This way I can decouple the SQL DB but re-use a complex objects graph that spans my data base directly in mocked tests. The code in this repo is very close to allowing the first step; but the subsequent calls to alternative relationships and association_proxy, hybrid_properties and methods needs to be ideally supported.

@miki725
Copy link
Owner

miki725 commented Jul 11, 2018

can you give an example of the model which allows first_item.my_relationship.filter(Foo.bar == 'blah blah').all(). my understanding that is not possible in SQLAlchemy. first_item.my_relationship should either resolve to an object instance of related model if relationship(uselist=False) or will resolve to a list of related models.

@shosca
Copy link
Collaborator

shosca commented Jul 11, 2018

@miki725 first_item.my_relationship can be a dynamic as in relationship(..., lazy='dynamic',.. ). In that case it'll be a query.

@miki725
Copy link
Owner

miki725 commented Jul 11, 2018

interesting. didnt know that. thanks @shosca

not sure how that can be handled since first_item is not a mocked instance. perhaps UnifiedAlchemyMagicMock can loop over all given data and mock all dynamic relationships. will have to give it some though.

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

No branches or pull requests

3 participants