Skip to content

Conversation

@MartinGotelli
Copy link
Contributor

This solves #192

@stefan6419846
Copy link
Collaborator

Thanks for the PR. With .order_by('foo'), shouldn't the result list be [1, 2, 3] instead of [2, 3, 1]?

@MartinGotelli
Copy link
Contributor Author

Thanks for the PR. With .order_by('foo'), shouldn't the result list be [1, 2, 3] instead of [2, 3, 1]?

Great catch, let me check on that. In Django works, so the mock should work the same way

@MartinGotelli
Copy link
Contributor Author

Tinkering here:
The problem we have with the sorting for the mock is that we don't have the context of the field that we already queried. Different from Django which builds a query and executes it just when necessary.

self.mock_set.values_list('foo').order_by('foo') # The mock_set after the values_list does not know which field you asked for
self.mock_set.order_by('foo') # Good, using the model attribute to sort

I don't really have a suggestion on how to solve this. My only thought was having something like QueryMockContext in the MockSet object.

django_mock_queries/query.py

    def values_list(self, *fields, **kwargs):
        result = []
        item_values_dicts = list(self.values(*fields))

        for values_dict in item_values_dicts:
            result.append(self._values_row(values_dict, fields, **kwargs))

        return self._mockset_class()(*result, clone=self, context=QueryMockContext(fields=fields))

What do you think?

@stefan6419846
Copy link
Collaborator

I have no direct clean solution for this either, but feel free to implement your proposal. If it works and does not introduce too much maintenance burdens, I am open to merging it.

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

Successfully merging this pull request may close these issues.

2 participants