Skip to content

Commit d2eafef

Browse files
authored
Merge pull request #5 from IdanHaim/RavenDB-6332
RavenDB-6332
2 parents e8ce0e1 + 8adc213 commit d2eafef

File tree

10 files changed

+37
-18
lines changed

10 files changed

+37
-18
lines changed

pyravendb/d_commands/database_commands.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,14 @@ def create_database(self, database_document):
304304
path = "databases/{0}".format(Utils.quote_key(db_name))
305305
response = self.requests_handler.http_request_handler(path, "PUT", database_document.to_json(),
306306
admin=True)
307+
308+
if response.status_code == 502:
309+
raise exceptions.ErrorResponseException(
310+
"Connection failed please check your connection to {0}".format(self.requests_handler.url))
307311
if response.status_code != 200:
308312
raise exceptions.ErrorResponseException(
309313
"Database with the name '{0}' already exists".format(database_document.database_id))
314+
310315
return response
311316

312317
def delete_database(self, db_name, hard_delete=False):
@@ -315,7 +320,7 @@ def delete_database(self, db_name, hard_delete=False):
315320
if hard_delete:
316321
path += "?hard-delete=true"
317322
response = self.requests_handler.http_request_handler(path, "DELETE", admin=True)
318-
if response.status_code != 200:
323+
if response.content != '':
319324
raise response.raise_for_status()
320325
return response
321326

pyravendb/store/document_session.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@ def _multi_load(self, keys, object_type, includes, nested_object_types):
9191
if len(keys) == 0:
9292
return []
9393

94-
ids_of_not_existing_object = keys
94+
ids_of_not_existing_object = set(keys)
9595
if not includes:
96-
ids_in_includes = [key for key in keys if key in self._includes]
96+
ids_in_includes = [key for key in ids_of_not_existing_object if key in self._includes]
9797
if len(ids_in_includes) > 0:
9898
for include in ids_in_includes:
9999
self._convert_and_save_entity(include, self._includes[include], object_type, nested_object_types)
100100
self._includes.pop(include)
101101

102-
ids_of_not_existing_object = [key for key in keys if
102+
ids_of_not_existing_object = [key for key in ids_of_not_existing_object if
103103
key not in self._entities_by_key]
104104

105105
ids_of_not_existing_object = [key for key in ids_of_not_existing_object if key not in self._known_missing_ids]
@@ -114,7 +114,7 @@ def _multi_load(self, keys, object_type, includes, nested_object_types):
114114
if results[i] is None:
115115
self._known_missing_ids.add(ids_of_not_existing_object[i])
116116
continue
117-
self._convert_and_save_entity(keys[i], results[i], object_type, nested_object_types)
117+
self._convert_and_save_entity(ids_of_not_existing_object[i], results[i], object_type, nested_object_types)
118118
self.save_includes(response_includes)
119119
return [None if key in self._known_missing_ids else self._entities_by_key[
120120
key] if key in self._entities_by_key else None for key in keys]

pyravendb/store/session_query.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,10 @@ def boost(self, value):
287287
raise ArgumentOutOfRangeException("boost", "boost factor must be a positive number")
288288
if value != 1:
289289
# 1 is the default
290-
self.query_builder += "^{0}".format(value)
290+
if self.query_builder.endswith(')'):
291+
self.query_builder = "{0}^{1})".format(self.query_builder[:len(self.query_builder) - 1], value)
292+
else:
293+
self.query_builder += "^{0}".format(value)
291294
return self
292295

293296
def _execute_query(self):

pyravendb/tests/session_tests/full_text_search_tests.py renamed to pyravendb/tests/session_tests/test_full_text_search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_full_text_search_two(self):
6767
"query", search_terms="Bobo"))
6868
self.assertEqual(len(query), 3)
6969

70-
def test_full_text_search_witg_boost(self):
70+
def test_full_text_search_with_boost(self):
7171
with self.document_store.open_session() as session:
7272
query = list(session.query(object_type=LastFm, wait_for_non_stale_results=True,
7373
index_name=LastFmAnalyzed.__name__).search("query", search_terms="Me").boost(10).

pyravendb/tests/session_tests/load_test.py renamed to pyravendb/tests/session_tests/test_load.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class TestLoad(TestBase):
3030
@classmethod
3131
def setUpClass(cls):
3232
super(TestLoad, cls).setUpClass()
33-
cls.db.put("products/101", {"name": "test"}, {"Raven-Python-Type": "load_test.Product"})
33+
cls.db.put("products/101", {"name": "test"},
34+
{"Raven-Python-Type": Product.__module__+".Product"})
3435
cls.db.put("products/10", {"name": "test"}, {})
3536
cls.db.put("orders/105", {"name": "testing_order", "key": 92, "product": "products/101"},
3637
{"Raven-Entity-Name": "Orders"})
@@ -52,6 +53,13 @@ def test_multi_load(self):
5253
products = session.load(["products/101", "products/10"])
5354
self.assertEqual(len(products), 2)
5455

56+
def test_multi_load_with_duplicate_id(self):
57+
with self.document_store.open_session() as session:
58+
products = session.load(["products/101", "products/101", "products/10"])
59+
self.assertEqual(len(products), 3)
60+
for product in products:
61+
self.assertIsNotNone(product)
62+
5563
def test_load_track_entity(self):
5664
with self.document_store.open_session() as session:
5765
product = session.load("products/101")

pyravendb/tests/session_tests/query_test.py renamed to pyravendb/tests/session_tests/test_query.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from pyravendb.store.session_query import QueryOperator
44
from pyravendb.custom_exceptions import exceptions
55
from pyravendb.data.indexes import IndexDefinition, SortOptions
6+
import unittest
67

78

89
class Product(object):
@@ -31,15 +32,15 @@ def setUpClass(cls):
3132
stores={"doc_id": "Yes"})
3233
cls.db.put_index("Testing_Sort", index_def=cls.index_sort, overwrite=True)
3334
cls.db.put("products/101", {"name": "test101", "key": 2, "order": "a"},
34-
{"Raven-Entity-Name": "Products", "Raven-Python-Type": "query_test.Product"})
35+
{"Raven-Entity-Name": "Products", "Raven-Python-Type": Product.__module__ + ".Product"})
3536
cls.db.put("products/10", {"name": "test10", "key": 3, "order": "b"}, {})
3637
cls.db.put("products/106", {"name": "test106", "key": 4, "order": "c"}, {})
3738
cls.db.put("products/107", {"name": "test107", "key": 5, "order": None},
38-
{"Raven-Entity-Name": "Products", "Raven-Python-Type": "query_test.Product"})
39+
{"Raven-Entity-Name": "Products", "Raven-Python-Type": Product.__module__ + ".Product"})
3940
cls.db.put("products/103", {"name": "test107", "key": 6},
40-
{"Raven-Entity-Name": "Products", "Raven-Python-Type": "query_test.Product"})
41+
{"Raven-Entity-Name": "Products", "Raven-Python-Type": Product.__module__ + ".Product"})
4142
cls.db.put("products/108", {"name": "new_testing", "key": 90, "order": "d"},
42-
{"Raven-Entity-Name": "Products", "Raven-Python-Type": "query_test.Product"})
43+
{"Raven-Entity-Name": "Products", "Raven-Python-Type": Product.__module__ + ".Product"})
4344
cls.db.put("orders/105", {"name": "testing_order", "key": 92, "product": "products/108"},
4445
{"Raven-Entity-Name": "Orders"})
4546
cls.db.put("company/1",
@@ -152,8 +153,11 @@ def test_query_with_fetch_terms(self):
152153

153154
found_in_all = True
154155
for result in query_results:
155-
if not hasattr(result,"doc_id"):
156+
if not hasattr(result, "doc_id"):
156157
found_in_all = False
157158
break
158159

159160
self.assertTrue(found_in_all)
161+
162+
if __name__ == "__main__":
163+
unittest.main()

pyravendb/tools/utils.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,13 @@ def build_path(index_name, query, options):
7070
@staticmethod
7171
def import_class(name):
7272
components = name.split('.')
73+
module_name = '.'.join(name.split('.')[:-1])
74+
mod = None
7375
try:
74-
mod = __import__(components[0])
75-
for comp in components[1:]:
76-
mod = getattr(mod, comp)
77-
return mod
76+
mod = getattr(__import__(module_name, fromlist=[components[-1]]), components[-1])
7877
except (ImportError, ValueError, AttributeError):
7978
pass
80-
return None
79+
return mod
8180

8281
@staticmethod
8382
def is_inherit(parent, child):

0 commit comments

Comments
 (0)