|
3 | 3 |
|
4 | 4 | from ravendb import AbstractIndexCreationTask, SetIndexesPriorityOperation |
5 | 5 | from ravendb.changes.observers import ActionObserver |
6 | | -from ravendb.changes.types import DocumentChange, IndexChange |
| 6 | +from ravendb.changes.types import DocumentChange, IndexChange, DocumentChangeType |
7 | 7 | from ravendb.documents.indexes.definitions import IndexPriority |
8 | 8 | from ravendb.infrastructure.entities import User |
9 | 9 | from ravendb.infrastructure.orders import Order |
@@ -235,3 +235,62 @@ def __ev(value: DocumentChange): |
235 | 235 | self.assertEqual("users/2", document_changes[1].key) |
236 | 236 |
|
237 | 237 | close_action() |
| 238 | + |
| 239 | + def test_changes_with_https(self): |
| 240 | + event = Event() |
| 241 | + changes_list = [] |
| 242 | + exception = None |
| 243 | + |
| 244 | + def _on_error(e): |
| 245 | + nonlocal exception |
| 246 | + exception = e |
| 247 | + |
| 248 | + changes = self.secured_document_store.changes(on_error=_on_error) |
| 249 | + observable = changes.for_document("users/1") |
| 250 | + |
| 251 | + def __ev(value: DocumentChange): |
| 252 | + changes_list.append(value) |
| 253 | + event.set() |
| 254 | + |
| 255 | + observer = ActionObserver(__ev) |
| 256 | + close_action = observable.subscribe_with_observer(observer) |
| 257 | + try: |
| 258 | + observable.ensure_subscribe_now() |
| 259 | + except Exception: |
| 260 | + raise exception |
| 261 | + |
| 262 | + with self.secured_document_store.open_session() as session: |
| 263 | + user = User() |
| 264 | + session.store(user, "users/1") |
| 265 | + session.save_changes() |
| 266 | + |
| 267 | + event.wait(2) |
| 268 | + document_change = changes_list[0] |
| 269 | + self.assertIsNotNone(document_change) |
| 270 | + self.assertEqual("users/1", document_change.key) |
| 271 | + self.assertEqual(DocumentChangeType.PUT, document_change.type_of_change) |
| 272 | + |
| 273 | + changes_list.clear() |
| 274 | + |
| 275 | + try: |
| 276 | + event.wait(1) |
| 277 | + except Exception: |
| 278 | + pass |
| 279 | + |
| 280 | + self.assertEqual(0, len(changes_list)) |
| 281 | + close_action() |
| 282 | + # at this point we should be unsubscribed from changes on 'users/1' |
| 283 | + |
| 284 | + with self.secured_document_store.open_session() as session: |
| 285 | + user = User() |
| 286 | + user.name = "another name" |
| 287 | + session.store(user, "users/1") |
| 288 | + session.save_changes() |
| 289 | + |
| 290 | + # it should be empty |
| 291 | + try: |
| 292 | + event.wait(1) |
| 293 | + except Exception: |
| 294 | + pass |
| 295 | + |
| 296 | + self.assertEqual(0, len(changes_list)) |
0 commit comments