|
11 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
14 |
| -from unittest import TestCase |
| 14 | +import unittest |
| 15 | +from test import client_context |
15 | 16 |
|
| 17 | +from pymongoarrow.api import find_arrow_all |
| 18 | +from pymongoarrow.schema import Schema |
16 | 19 | from pymongoarrow.version import __version__
|
17 | 20 |
|
18 | 21 |
|
19 |
| -class TestPyMongoArrow(TestCase): |
| 22 | +class TestPyMongoArrow(unittest.TestCase): |
| 23 | + @classmethod |
| 24 | + def setUpClass(cls): |
| 25 | + if not client_context.connected: |
| 26 | + raise unittest.SkipTest("cannot connect to MongoDB") |
| 27 | + cls.client = client_context.get_client() |
| 28 | + |
20 | 29 | def test_version(self):
|
21 | 30 | self.assertIsNotNone(__version__)
|
22 | 31 | self.assertIsInstance(__version__, str)
|
| 32 | + |
| 33 | + def test_capped_collection(self): |
| 34 | + self.client.test.drop_collection("test") |
| 35 | + self.client.test.create_collection("test", capped=True, size=5000) |
| 36 | + schema = Schema({"data": bool}) |
| 37 | + data = [{"data": False} for _ in range(1000)] |
| 38 | + self.client.test.test.insert_many(data) |
| 39 | + |
| 40 | + # Data should have been capped. |
| 41 | + cursor = self.client.test.test.find({}) |
| 42 | + total = len(list(cursor)) |
| 43 | + self.assertLess(total, 1000) |
| 44 | + table = find_arrow_all(self.client.test.test, {}, schema=schema) |
| 45 | + self.assertEqual(table.shape, (total, 1)) |
0 commit comments