|
4 | 4 |
|
5 | 5 | import pytest
|
6 | 6 | from bson import ObjectId
|
| 7 | +from pymongo.cursor import CursorType |
7 | 8 | from pymongo.errors import WriteError
|
8 | 9 |
|
9 |
| -from marrow.mongo import Field, Index, U |
| 10 | +from marrow.mongo import Index, U |
10 | 11 | from marrow.mongo.field import Integer, String
|
11 | 12 | from marrow.mongo.trait import Queryable
|
12 | 13 |
|
@@ -39,6 +40,47 @@ class Sample(Queryable):
|
39 | 40 | return Sample
|
40 | 41 |
|
41 | 42 |
|
| 43 | + |
| 44 | +class TestQueryableCore(object): |
| 45 | + def test_prepare_find_cursor_type_explicit(self, Sample): |
| 46 | + cls, collection, query, options = Sample._prepare_find(cursor_type=CursorType.TAILABLE) |
| 47 | + assert options['cursor_type'] == CursorType.TAILABLE |
| 48 | + |
| 49 | + def test_prepare_find_cursor_conflict(self, Sample): |
| 50 | + with pytest.raises(TypeError): |
| 51 | + Sample._prepare_find(cursor_type=CursorType.TAILABLE, tail=True) |
| 52 | + |
| 53 | + with pytest.raises(TypeError): |
| 54 | + Sample._prepare_find(cursor_type=CursorType.TAILABLE, await=True) |
| 55 | + |
| 56 | + with pytest.raises(TypeError): |
| 57 | + Sample._prepare_find(cursor_type=CursorType.TAILABLE, tail=True, await=True) |
| 58 | + |
| 59 | + def test_prepare_find_cursor_type_tail(self, Sample): |
| 60 | + cls, collection, query, options = Sample._prepare_find(tail=True) |
| 61 | + assert options['cursor_type'] == CursorType.TAILABLE_AWAIT |
| 62 | + |
| 63 | + def test_prepare_find_cursor_type_tail_not_await(self, Sample): |
| 64 | + cls, collection, query, options = Sample._prepare_find(tail=True, await=False) |
| 65 | + assert options['cursor_type'] == CursorType.TAILABLE |
| 66 | + |
| 67 | + def test_prepare_find_cursor_type_await_conflict(self, Sample): |
| 68 | + with pytest.raises(TypeError): |
| 69 | + Sample._prepare_find(await=False) |
| 70 | + |
| 71 | + def test_prepare_find_max_time_modifier(self, Sample): |
| 72 | + cls, collection, query, options = Sample._prepare_find(max_time_ms=1000) |
| 73 | + assert options['modifiers'] == {'$maxTimeMS': 1000} |
| 74 | + |
| 75 | + def test_prepare_aggregate_skip_limit(self, Sample): |
| 76 | + cls, collection, stages, options = Sample._prepare_aggregate(skip=10, limit=10) |
| 77 | + |
| 78 | + assert stages == [ |
| 79 | + {'$skip': 10}, |
| 80 | + {'$limit': 10}, |
| 81 | + ] |
| 82 | + |
| 83 | + |
42 | 84 | class TestQueryableTrait(object):
|
43 | 85 | def test_find(self, Sample):
|
44 | 86 | rs = Sample.find()
|
|
0 commit comments