|
6 | 6 | AbstractTimeSeriesIndexCreationTask, |
7 | 7 | AbstractMultiMapTimeSeriesIndexCreationTask, |
8 | 8 | ) |
| 9 | +from ravendb.infrastructure.entities import User |
9 | 10 | from ravendb.infrastructure.orders import Company |
10 | 11 | from ravendb.tests.test_base import TestBase |
11 | 12 | from ravendb.tools.raven_test_helper import RavenTestHelper |
@@ -44,6 +45,36 @@ def test_basic_map_index(self): |
44 | 45 | self.assertIsNotNone(result.user) |
45 | 46 | self.assertGreater(result.heart_beat, 0) |
46 | 47 |
|
| 48 | + def test_basic_multi_map_index(self): |
| 49 | + now = RavenTestHelper.utc_today() |
| 50 | + time_series_index = MyMultiMapTsIndex() |
| 51 | + time_series_index.execute(self.store) |
| 52 | + |
| 53 | + with self.store.open_session() as session: |
| 54 | + company = Company() |
| 55 | + session.store(company) |
| 56 | + |
| 57 | + session.time_series_for_entity(company, "HeartRate").append_single(now, 2.5, "tag1") |
| 58 | + session.time_series_for_entity(company, "HeartRate2").append_single(now, 3.5, "tag2") |
| 59 | + |
| 60 | + user = User() |
| 61 | + session.store(user) |
| 62 | + session.time_series_for_entity(user, "HeartRate").append_single(now, 4.5, "tag3") |
| 63 | + |
| 64 | + session.save_changes() |
| 65 | + |
| 66 | + self.wait_for_indexing(self.store) |
| 67 | + |
| 68 | + with self.store.open_session() as session: |
| 69 | + results = list(session.query_index_type(MyMultiMapTsIndex, MyMultiMapTsIndex.Result)) |
| 70 | + self.assertEqual(3, len(results)) |
| 71 | + |
| 72 | + result = results[0] |
| 73 | + |
| 74 | + self.assertEqual(now, result.date) |
| 75 | + self.assertIsNotNone(result.user) |
| 76 | + self.assertGreater(result.heart_beat, 0) |
| 77 | + |
47 | 78 |
|
48 | 79 | class MyTsIndex(AbstractTimeSeriesIndexCreationTask): |
49 | 80 | def __init__(self): |
@@ -72,13 +103,8 @@ def __init__( |
72 | 103 | self.user = user |
73 | 104 |
|
74 | 105 | @classmethod |
75 | | - def from_json(cls, json_dict:Dict[str, Any]) -> MyMultiMapTsIndex.Result: |
76 | | - return cls( |
77 | | - json_dict["heartBeat"], |
78 | | - Utils.string_to_datetime(json_dict["date"]), |
79 | | - json_dict["user"] |
80 | | - ) |
81 | | - |
| 106 | + def from_json(cls, json_dict: Dict[str, Any]) -> MyMultiMapTsIndex.Result: |
| 107 | + return cls(json_dict["heartBeat"], Utils.string_to_datetime(json_dict["date"]), json_dict["user"]) |
82 | 108 |
|
83 | 109 | def __init__(self): |
84 | 110 | super(MyMultiMapTsIndex, self).__init__() |
|
0 commit comments