Skip to content

Commit 51deffd

Browse files
committed
Fix exception-dispatcher tests; expect RavenException / message-contains
The client ExceptionDispatcher only ever yields RavenException (or a mapped subclass) and appends a status-code suffix to the message, so tests asserting bare exceptions.* types or exact messages could never pass. Per the csharp-sync testing rule, server-side errors use assertRaisesWithMessageContaining. - test_cannot_create_database_with_the_same_name: unskip; assertRaises(RavenException) on duplicate create. - test_update_by_index_fail / test_delete_by_index_fail: unskip; expect RavenException. - test_put_fail: unskip; expect RavenException for an invalid (non-object) document body. - test_can_replace_certificate: unskip; assertRaisesWithMessage -> assertRaisesWithMessageContaining. - test_ravenDB_13456 (identity-parts-separator): skip -> skipIf(RAVENDB_LICENSE); message asserts -> contains. - test_time_series_configuration: drop "Disable on pull request" skips on the 3 configure tests; _3 message asserts -> contains. Also fix TimeSeriesCollectionConfiguration.to_json to guard None policies/raw_policy (Python defaults them to None, unlike C#), which crashed test_can_configure_time_series.
1 parent cefe05f commit 51deffd

7 files changed

Lines changed: 21 additions & 24 deletions

File tree

ravendb/documents/operations/time_series.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ def from_json(cls, json_dict: Dict[str, Any]) -> TimeSeriesCollectionConfigurati
101101
def to_json(self) -> Dict[str, Any]:
102102
return {
103103
"Disabled": self.disabled,
104-
"Policies": [policy.to_json() for policy in self.policies],
105-
"RawPolicy": self.raw_policy.to_json(),
104+
"Policies": [policy.to_json() for policy in (self.policies or [])],
105+
"RawPolicy": self.raw_policy.to_json() if self.raw_policy is not None else None,
106106
}
107107

108108

ravendb/tests/jvm_migrated_tests/client_tests/time_series_tests/test_time_series_configuration.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ def test_deserialization(self):
3838
self.assertEqual(TimeValueUnit.NONE, time_value.unit)
3939
self.assertEqual(0, time_value.value)
4040

41-
@unittest.skip("Disable on pull request")
4241
def test_can_configure_time_series(self):
4342
config = TimeSeriesConfiguration()
4443
self.store.maintenance.send(ConfigureTimeSeriesOperation(config))
@@ -90,7 +89,6 @@ def test_can_configure_time_series(self):
9089
self.assertEqual(TimeValue.of_years(3), policies[5].retention_time)
9190
self.assertEqual(TimeValue.of_years(1), policies[5].aggregation_time)
9291

93-
@unittest.skip("Disable on pull request")
9492
def test_can_configure_time_series_2(self):
9593
collection_name = "Users"
9694

@@ -206,7 +204,6 @@ def test_not_valid_configure_should_throw(self):
206204
ConfigureTimeSeriesOperation(config3),
207205
)
208206

209-
@unittest.skip("Disable on pull request")
210207
def test_configure_time_series_3(self):
211208
self.store.time_series.set_policy(
212209
User, "By15SecondsFor1Minute", TimeValue.of_seconds(15), TimeValue.of_seconds(60)
@@ -245,7 +242,7 @@ def test_configure_time_series_3(self):
245242
self.assertEqual(TimeValue.of_years(3), policies[5].retention_time)
246243
self.assertEqual(TimeValue.of_years(1), policies[5].aggregation_time)
247244

248-
self.assertRaisesWithMessage(
245+
self.assertRaisesWithMessageContaining(
249246
self.store.time_series.remove_policy,
250247
Exception,
251248
"The policy 'By15SecondsFor1Minute' has a retention time of '60 seconds' "
@@ -254,7 +251,7 @@ def test_configure_time_series_3(self):
254251
"ByMinuteFor3Hours",
255252
)
256253

257-
self.assertRaisesWithMessage(
254+
self.assertRaisesWithMessageContaining(
258255
self.store.time_series.set_raw_policy,
259256
Exception,
260257
"The policy 'rawpolicy' has a retention time of '10 seconds' but should be aggregated by policy "

ravendb/tests/jvm_migrated_tests/https_tests/test_https.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ def test_can_connect_with_certificate(self):
3535
session.store(user, "users/1")
3636
session.save_changes()
3737

38-
@unittest.skip("Exception dispatcher")
3938
def test_can_replace_certificate(self):
4039
with self.secured_document_store as sec_store:
41-
self.assertRaisesWithMessage(
40+
self.assertRaisesWithMessageContaining(
4241
sec_store.maintenance.server.send,
4342
Exception,
4443
"Unable to load the provided certificate",

ravendb/tests/jvm_migrated_tests/issues_tests/test_ravenDB_13456.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import unittest
23

34
from ravendb.documents.operations.configuration.definitions import ClientConfiguration
@@ -12,7 +13,7 @@ class TestRavenDB13456(TestBase):
1213
def setUp(self):
1314
super().setUp()
1415

15-
@unittest.skip("Fails on cicd due to free license - adding the client configuration is disallowed")
16+
@unittest.skipIf(os.environ.get("RAVENDB_LICENSE") is None, "Insufficient license permissions. Skipping on CI/CD.")
1617
def test_can_change_identity_parts_separator(self):
1718
with self.store.open_session() as session:
1819
company1 = Company()
@@ -44,15 +45,15 @@ def test_can_change_identity_parts_separator(self):
4445

4546
with self.store.open_session(session_options=session_options) as session:
4647
session.advanced.cluster_transaction.create_compare_exchange_value("company|", Company())
47-
self.assertRaisesWithMessage(
48+
self.assertRaisesWithMessageContaining(
4849
session.save_changes,
4950
RuntimeError, # todo: change to RavenException when the Exception Dispatcher will be ready
5051
"Document id company| cannot end with '|' or '/' as part of cluster transaction",
5152
)
5253

5354
with self.store.open_session(session_options=session_options) as session:
5455
session.advanced.cluster_transaction.create_compare_exchange_value("company/", Company())
55-
self.assertRaisesWithMessage(
56+
self.assertRaisesWithMessageContaining(
5657
session.save_changes,
5758
RuntimeError, # todo: change to RavenException when the Exception Dispatcher will be ready
5859
"Document id company/ cannot end with '|' or '/' as part of cluster transaction",
@@ -90,7 +91,7 @@ def test_can_change_identity_parts_separator(self):
9091
with self.store.open_session(session_options=session_options) as session:
9192
session.advanced.cluster_transaction.create_compare_exchange_value("company:", Company())
9293

93-
self.assertRaisesWithMessage(
94+
self.assertRaisesWithMessageContaining(
9495
session.save_changes,
9596
RuntimeError, # todo: change to RavenException when the Exception Dispatcher will be ready
9697
"Document id company: cannot end with '|' or ':' as part of cluster transaction",
@@ -99,7 +100,7 @@ def test_can_change_identity_parts_separator(self):
99100
with self.store.open_session(session_options=session_options) as session:
100101
session.advanced.cluster_transaction.create_compare_exchange_value("company|", Company())
101102

102-
self.assertRaisesWithMessage(
103+
self.assertRaisesWithMessageContaining(
103104
session.save_changes,
104105
RuntimeError, # todo: change to RavenException when the Exception Dispatcher will be ready
105106
"Document id company| cannot end with '|' or ':' as part of cluster transaction",
@@ -148,15 +149,15 @@ def test_can_change_identity_parts_separator(self):
148149
with self.store.open_session(session_options=session_options) as session:
149150
session.advanced.cluster_transaction.create_compare_exchange_value("company|", Company())
150151

151-
self.assertRaisesWithMessage(
152+
self.assertRaisesWithMessageContaining(
152153
session.save_changes,
153154
RuntimeError, # todo: change to RavenException when the Exception Dispatcher will be ready
154155
"Document id company| cannot end with '|' or '/' as part of cluster transaction",
155156
)
156157

157158
with self.store.open_session(session_options=session_options) as session:
158159
session.advanced.cluster_transaction.create_compare_exchange_value("company/", Company())
159-
self.assertRaisesWithMessage(
160+
self.assertRaisesWithMessageContaining(
160161
session.save_changes,
161162
RuntimeError, # todo: change to RavenException when the Exception Dispatcher will be ready
162163
"Document id company/ cannot end with '|' or '/' as part of cluster transaction",

ravendb/tests/operations_tests/test_server_operations.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from ravendb.serverwide.operations.common import GetDatabaseNamesOperation
2+
from ravendb.exceptions.raven_exceptions import RavenException
23
from ravendb.tests.test_base import *
34
import unittest
45

@@ -21,13 +22,13 @@ def test_create_database_name_longer_than_260_chars(self):
2122
except Exception as exception:
2223
raise exception
2324

24-
@unittest.skip("Exception dispatcher")
2525
def test_cannot_create_database_with_the_same_name(self):
2626
name = "Duplicate"
2727
try:
2828
self.store.maintenance.server.send(CreateDatabaseOperation(DatabaseRecord(name)))
2929
TestBase.wait_for_database_topology(self.store, name)
30-
self.assertIsNone(self.store.maintenance.server.send(CreateDatabaseOperation(DatabaseRecord(name))))
30+
with self.assertRaises(RavenException):
31+
self.store.maintenance.server.send(CreateDatabaseOperation(DatabaseRecord(name)))
3132

3233
finally:
3334
try:

ravendb/tests/raven_commands_tests/test_by_index_actions.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from ravendb.documents.commands.query import QueryCommand
44
from ravendb.exceptions import exceptions
5+
from ravendb.exceptions.raven_exceptions import RavenException
56
from ravendb.documents.commands.crud import PutDocumentCommand
67
from ravendb.documents.indexes.definitions import IndexDefinition
78
from ravendb.documents.operations.indexes import PutIndexesOperation
@@ -61,14 +62,13 @@ def test_update_by_index_success(self):
6162
patch_command.result.operation_node_tag,
6263
).wait_for_completion()
6364

64-
@unittest.skip("Exception dispatcher")
6565
def test_update_by_index_fail(self):
6666
index_query = IndexQuery("from index 'TeSort' update {{{0}}}".format(self.patch))
6767
patch_command = PatchByQueryOperation(
6868
index_query,
6969
options=QueryOperationOptions(allow_stale=False),
7070
).get_command(self.store, self.store.conventions)
71-
with self.assertRaises(exceptions.InvalidOperationException):
71+
with self.assertRaises(RavenException):
7272
self.requests_executor.execute_command(patch_command)
7373
Operation(
7474
self.requests_executor,
@@ -78,12 +78,11 @@ def test_update_by_index_fail(self):
7878
patch_command.result.operation_node_tag,
7979
).wait_for_completion()
8080

81-
@unittest.skip("Exception dispatcher")
8281
def test_delete_by_index_fail(self):
8382
delete_by_index_command = DeleteByQueryOperation("From Index 'region_2' WHERE Name = 'Western'").get_command(
8483
self.store, self.store.conventions
8584
)
86-
with self.assertRaises(exceptions.InvalidOperationException):
85+
with self.assertRaises(RavenException):
8786
self.requests_executor.execute_command(delete_by_index_command)
8887
self.assertIsNotNone(delete_by_index_command.result)
8988
Operation(

ravendb/tests/raven_commands_tests/test_put.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from ravendb.documents.commands.crud import PutDocumentCommand, GetDocumentsCommand
2+
from ravendb.exceptions.raven_exceptions import RavenException
23
from ravendb.tests.test_base import *
34

45

@@ -17,10 +18,9 @@ def test_put_success(self):
1718
self.assertEqual(response.results[0]["@metadata"]["@id"], "testing/1")
1819
request_executor.close()
1920

20-
@unittest.skip("Exception Dispatcher")
2121
def test_put_fail(self):
2222
request_executor = self.store.get_request_executor()
23-
with self.assertRaises(ValueError):
23+
with self.assertRaises(RavenException):
2424
command = PutDocumentCommand("testing/2", None, "document")
2525
request_executor.execute_command(command)
2626

0 commit comments

Comments
 (0)