Skip to content

Commit

Permalink
Merge pull request #66 from Princeton-CDH/extensible-mock-solr
Browse files Browse the repository at this point in the history
Make mock queryset plugin more extensible
  • Loading branch information
rlskoeser committed Nov 4, 2021
2 parents 8949fc6 + 63d2266 commit a18fbcf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
20 changes: 12 additions & 8 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
CHANGELOG
=========

0.8
---
* Pytest fixture ``mock_solr_queryset`` now takes optional argument for extra methods to include in fluent interface

0.7
---

Expand All @@ -11,10 +15,10 @@ CHANGELOG
* Continuous integration migrated from Travis-CI to GitHub Actions
* bugfix: in some cases, index script was wrongly detecting ModelIndexable
subclasses as abstract and excluding them; this has been corrected
* ModelIndexable now extends `django.db.models.Model`; existing code
* ModelIndexable now extends ``django.db.models.Model``; existing code
MUST be updated to avoid double-extending Model
* Default index data has been updated to use a dynamic field `item_type_s` instead of `item_type` so that basic setup does not require customizing the solr schema.
* `ModelIndexable.get_related_model` now supports ForeignKey relationships and django-taggit `TaggableManager` when identifying depencies for binding signal handlers
* Default index data has been updated to use a dynamic field ``item_type_s`` instead of ``item_type`` so that basic setup does not require customizing the solr schema.
* ``ModelIndexable.get_related_model`` now supports ForeignKey relationships and django-taggit ``TaggableManager`` when identifying depencies for binding signal handlers

0.6.1
-----
Expand All @@ -25,14 +29,14 @@ CHANGELOG
---

* Solr client now escalates 404 errors instead of logging with no exception
* Schema field declarations now support the `stored` option
* Schema field declarations now support the ``stored`` option
* Schema field type declarations now pass through arbitrary options
* New method `total_to_index` on `parasolr.indexing.Indexable` to better
* New method ``total_to_index`` on ``parasolr.indexing.Indexable`` to better
support indexing content that is returned as a generator
* Access to expanded results now available on QueryResponse and SolrQuerySet
* SolrQuerySet no longer wraps return results from `get_stats` and `get_facets` with QueryResponse
* New last-modified view mixin for use with Django views `parasolr.django.views.SolrLastModifiedMixin`
* New pytest fixture `mock_solr_queryset` to generate a Mock SolrQuerySet that simulates the SolrQuerySet fluent interface
* SolrQuerySet no longer wraps return results from ``get_stats`` and ``get_facets`` with QueryResponse
* New last-modified view mixin for use with Django views ``parasolr.django.views.SolrLastModifiedMixin``
* New pytest fixture ``mock_solr_queryset`` to generate a Mock SolrQuerySet that simulates the SolrQuerySet fluent interface


0.5.4
Expand Down
4 changes: 2 additions & 2 deletions parasolr/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ def empty_solr():
sleep(0.1)


def get_mock_solr_queryset(spec=SolrQuerySet):
def get_mock_solr_queryset(spec=SolrQuerySet, extra_methods=[]):
mock_qs = MagicMock(spec=spec)

# simulate fluent interface
for meth in ['filter', 'facet', 'stats', 'facet_field', 'facet_range',
'search', 'order_by', 'query', 'only', 'also',
'highlight', 'raw_query_parameters', 'all', 'none']:
'highlight', 'raw_query_parameters', 'all', 'none'] + extra_methods:
getattr(mock_qs, meth).return_value = mock_qs

return Mock(return_value=mock_qs)
Expand Down
7 changes: 6 additions & 1 deletion parasolr/tests/test_pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
except ImportError:
pass

from parasolr.pytest_plugin import get_mock_solr_queryset
from parasolr.pytest_plugin import get_mock_solr_queryset, mock_solr_queryset
from parasolr.query import SolrQuerySet
from parasolr.tests.utils import skipif_no_django

Expand Down Expand Up @@ -186,6 +186,11 @@ def custom_method(self):
# should pass isinstance check
assert isinstance(mock_qs, MyCustomQuerySet)

# specify extra methods to include in fluent interface
mock_qs_cls = get_mock_solr_queryset(MyCustomQuerySet, extra_methods=["custom_method"])
mock_qs = mock_qs_cls()
assert mock_qs.custom_method.return_value == mock_qs


def test_get_mock_solr_queryset_class_scope(testdir):
# test class scope logic when using mock solr queryset fixture
Expand Down

0 comments on commit a18fbcf

Please sign in to comment.