Skip to content

Commit e9fde1e

Browse files
committed
Various tests
1 parent dc175e1 commit e9fde1e

File tree

20 files changed

+502
-8
lines changed

20 files changed

+502
-8
lines changed

ravendb/documents/commands/revisions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def get_request_query_string(self, path_builder: List[str]) -> None:
9292
path_builder.append(Utils.escape(change_vector))
9393

9494
if self._before is not None:
95-
path_builder.append("&before")
95+
path_builder.append("&before=")
9696
path_builder.append(Utils.datetime_to_string(self._before))
9797

9898
if self._start is not None:

ravendb/documents/indexes/abstract_index_creation_tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def __set_suggestions(options: IndexFieldOptions, value: bool):
268268
return index_definition
269269

270270
except Exception as e:
271-
raise RuntimeError(f"Failed to create index {self._index_name}", e) # todo: IndexCompilationException
271+
raise RuntimeError(f"Failed to create index {self._index_name}", e) # todo: IndexCompilationException
272272

273273

274274
class IndexDefinitionBuilder(AbstractIndexDefinitionBuilder[IndexDefinition]):

ravendb/documents/session/document_session_operations/in_memory_document_session_operations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1887,7 +1887,7 @@ def with_timeout(self, timeout: datetime.timedelta) -> InMemoryDocumentSessionOp
18871887
return self
18881888

18891889
def throw_on_timeout(self, should_throw: bool) -> InMemoryDocumentSessionOperations.IndexesWaitOptsBuilder:
1890-
self.get_options().index_options.throw_on_timeout_in_wait_for_replicas = should_throw
1890+
self.get_options().index_options.throw_on_timeout_in_wait_for_indexes = should_throw
18911891
return self
18921892

18931893
def wait_for_indexes(self, *indexes: str) -> InMemoryDocumentSessionOperations.IndexesWaitOptsBuilder:

ravendb/documents/session/misc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
if TYPE_CHECKING:
1212
from ravendb.http.request_executor import RequestExecutor
13-
from ravendb.documents.queries.misc import Query
13+
from ravendb.documents.session.query import DocumentQuery
1414
from ravendb.documents.session.operations.query import QueryOperation
1515
from ravendb.documents.session.document_session_operations.in_memory_document_session_operations import (
1616
InMemoryDocumentSessionOperations,
@@ -153,7 +153,7 @@ def __init__(
153153

154154

155155
class DocumentQueryCustomization:
156-
def __init__(self, query: Query):
156+
def __init__(self, query: DocumentQuery):
157157
self.query = query
158158
self.query_operation: QueryOperation = None
159159

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from pathlib import Path
2+
3+
from ravendb.documents.smuggler.periodic_backup_file_extension_comparator import PeriodicBackupFileExtensionComparator
4+
5+
6+
class BackupUtils:
7+
8+
@staticmethod
9+
def file_comparator(file1: Path, file2: Path) -> int:
10+
base_name1 = file1.stem
11+
base_name2 = file2.stem
12+
13+
if base_name1 != base_name2:
14+
return (base_name1 > base_name2) - (base_name1 < base_name2)
15+
16+
ext1 = file1.suffix[1:] if file1.suffix.startswith('.') else file1.suffix
17+
ext2 = file2.suffix[1:] if file2.suffix.startswith('.') else file2.suffix
18+
19+
if ext1 != ext2:
20+
return PeriodicBackupFileExtensionComparator.compare(file1, file2)
21+
22+
last_modified1 = file1.stat().st_mtime
23+
last_modified2 = file2.stat().st_mtime
24+
25+
return (last_modified1 > last_modified2) - (last_modified1 < last_modified2)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from pathlib import Path
2+
3+
from ravendb.primitives.constants import PeriodicBackup
4+
5+
class PeriodicBackupFileExtensionComparator:
6+
7+
@staticmethod
8+
def compare(file1: Path, file2: Path) -> int:
9+
if file1.resolve() == file2.resolve():
10+
return 0
11+
12+
ext1 = file1.suffix[1:].lower() if file1.suffix.startswith('.') else file1.suffix.lower()
13+
14+
if ext1 == PeriodicBackup.SNAPSHOT_EXTENSION:
15+
return -1
16+
17+
if ext1 == PeriodicBackup.FULL_BACKUP_EXTENSION:
18+
return -1
19+
20+
return 1

ravendb/documents/subscriptions/document_subscriptions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ def create_for_class(
7373
options = options or SubscriptionCreationOptions()
7474
return self.create_for_options(self.ensure_criteria(options, object_type, False), database)
7575

76+
def create_for_revisions(
77+
self,
78+
object_type: Type[_T],
79+
options: Optional[SubscriptionCreationOptions] = None,
80+
database: Optional[str] = None,
81+
) -> str:
82+
options = options or SubscriptionCreationOptions()
83+
return self.create_for_options(self.ensure_criteria(options, object_type, True), database)
84+
7685
def ensure_criteria(self, criteria: SubscriptionCreationOptions, object_type: Type[_T], revisions: bool):
7786
if criteria is None:
7887
criteria = SubscriptionCreationOptions()

ravendb/primitives/constants.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,16 @@ def configuration_to_method_name(source: VectorEmbeddingType, dest: VectorEmbedd
114114

115115
DEFAULT_EMBEDDING_TYPE = VectorEmbeddingType.SINGLE
116116
DEFAULT_IS_EXACT = False
117+
118+
class PeriodicBackup:
119+
FULL_BACKUP_EXTENSION = "ravendb-full-backup"
120+
SNAPSHOT_EXTENSION = "ravendb-snapshot"
121+
ENCRYPTED_FULL_BACKUP_EXTENSION = ".ravendb-encrypted-full-backup"
122+
ENCRYPTED_SNAPSHOT_EXTENSION = ".ravendb-encrypted-snapshot"
123+
INCREMENTAL_BACKUP_EXTENSION = "ravendb-incremental-backup"
124+
ENCRYPTED_INCREMENTAL_BACKUP_EXTENSION = ".ravendb-encrypted-incremental-backup"
125+
126+
class Folders:
127+
INDEXES = "Indexes"
128+
DOCUMENTS = "Documents"
129+
CONFIGURATION = "Configuration"

ravendb/tests/jvm_migrated_tests/bugs_tests/caching_tests/test_caching_of_document_include.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,24 @@ class CachingOfDocumentsIncludeTest(TestBase):
2828
def setUp(self):
2929
super().setUp()
3030

31+
def test_can_cache_document_with_includes(self):
32+
with self.store.open_session() as session:
33+
user = User(name="Ayende")
34+
session.store(user)
35+
36+
partner = User(partner_id="users/1-A")
37+
session.store(partner)
38+
39+
session.save_changes()
40+
41+
with self.store.open_session() as session:
42+
session.include("partnerId").load("users/2-A", User)
43+
session.save_changes()
44+
45+
with self.store.open_session() as session:
46+
session.include("partnerId").load("users/2-A", User)
47+
self.assertEqual(len(session.advanced.request_executor.cache), 1)
48+
3149
def test_can_avoid_using_server_for_load_with_include_if_everything_is_in_session_cacheLazy(self):
3250
with self.store.open_session() as session:
3351
user = User(name="Ayende")

ravendb/tests/jvm_migrated_tests/client_tests/test_patch.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ravendb import PatchByQueryOperation, PatchOperation, PatchRequest, PatchStatus
1+
from ravendb import PatchByQueryOperation, PatchOperation, PatchRequest, PatchStatus, InMemoryDocumentSessionOperations
22
from ravendb.infrastructure.entities import User
33
from ravendb.tests.test_base import TestBase
44

@@ -37,3 +37,19 @@ def test_can_patch_single_document(self):
3737
with self.store.open_session() as session:
3838
loaded_user = session.load("users/1", User)
3939
self.assertEqual("Patched", loaded_user.name)
40+
41+
def test_can_wait_for_index_after_patch(self):
42+
with self.store.open_session() as session:
43+
user = User(name="RavenDB")
44+
session.store(user, "users/1")
45+
session.save_changes()
46+
47+
def wait_for_indexes_options(options: InMemoryDocumentSessionOperations.IndexesWaitOptsBuilder):
48+
options.wait_for_indexes("Users/ByName")
49+
50+
with self.store.open_session() as session:
51+
session.advanced.wait_for_indexes_after_save_changes(wait_for_indexes_options)
52+
53+
user = session.load("users/1", User)
54+
session.advanced.patch(user, "name", "New Name")
55+
session.save_changes()

0 commit comments

Comments
 (0)