From 5445106ed3e890612a310aad4433b23087b284b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Re=C3=A9?= Date: Wed, 31 Jan 2024 17:00:54 +0100 Subject: [PATCH] add tests --- .../solr/tests/data/add_request_with_none.txt | 7 +++ .../add_request_with_none_and_boost_value.txt | 7 +++ src/collective/solr/tests/test_solr.py | 53 ++++++++++++++++++- 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 src/collective/solr/tests/data/add_request_with_none.txt create mode 100644 src/collective/solr/tests/data/add_request_with_none_and_boost_value.txt diff --git a/src/collective/solr/tests/data/add_request_with_none.txt b/src/collective/solr/tests/data/add_request_with_none.txt new file mode 100644 index 00000000..0e1380d1 --- /dev/null +++ b/src/collective/solr/tests/data/add_request_with_none.txt @@ -0,0 +1,7 @@ +POST /solr/plone/update HTTP/1.1 +Host: localhost +Accept-Encoding: identity +Content-Length: 95 +Content-Type: text/xml; charset=utf-8 + +500 diff --git a/src/collective/solr/tests/data/add_request_with_none_and_boost_value.txt b/src/collective/solr/tests/data/add_request_with_none_and_boost_value.txt new file mode 100644 index 00000000..6ed17d9e --- /dev/null +++ b/src/collective/solr/tests/data/add_request_with_none_and_boost_value.txt @@ -0,0 +1,7 @@ +POST /solr/plone/update HTTP/1.1 +Host: localhost +Accept-Encoding: identity +Content-Length: 115 +Content-Type: text/xml; charset=utf-8 + +500 diff --git a/src/collective/solr/tests/test_solr.py b/src/collective/solr/tests/test_solr.py index 5f866acf..a42273e4 100644 --- a/src/collective/solr/tests/test_solr.py +++ b/src/collective/solr/tests/test_solr.py @@ -8,7 +8,6 @@ class TestSolr(TestCase): - layer = COLLECTIVE_SOLR_MOCK_REGISTRY_FIXTURE def test_add(self): @@ -63,6 +62,58 @@ def test_add_with_boost_values(self): self.assertEqual(len(res), 1) # one request was sent self.failUnlessEqual(str(output), add_request.decode("utf-8")) + def test_add_none(self): + config = getConfig() + config.atomic_updates = True + add_request = getData("add_request_with_none.txt").rstrip(b"\n") + add_response = getData("add_response.txt") + + c = SolrConnection(host="localhost:8983", persistent=True) + + # fake schema response - caches the schema + fakehttp(c, getData("schema.xml")) + c.get_schema() + + output = fakehttp(c, add_response) + c.add(id=500, name=None) + res = c.flush() + self.assertEqual(len(res), 1) # one request was sent + res = res[0] + self.failUnlessEqual(str(output), add_request.decode("utf-8")) + # Status + node = res.findall(".//int")[0] + self.failUnlessEqual(node.attrib["name"], "status") + self.failUnlessEqual(node.text, "0") + # QTime + node = res.findall(".//int")[1] + self.failUnlessEqual(node.attrib["name"], "QTime") + self.failUnlessEqual(node.text, "4") + res.find("QTime") + + def test_add_none_with_boost_values(self): + config = getConfig() + config.atomic_updates = False + add_request = getData("add_request_with_none_and_boost_value.txt").rstrip(b"\n") + add_response = getData("add_response.txt") + c = SolrConnection(host="localhost:8983", persistent=True) + + # fake schema response - caches the schema + fakehttp(c, getData("schema.xml")) + c.get_schema() + + output = fakehttp(c, add_response) + boost = {"": 2, "id": 0.5, "name": 5} + c.add( + boost_values=boost, + atomic_updates=False, # Force disabling atomic updates + id="500", + name=None, + ) + + res = c.flush() + self.assertEqual(len(res), 1) # one request was sent + self.failUnlessEqual(str(output), add_request.decode("utf-8")) + def test_connection_str(self): c = SolrConnection(host="localhost:8983", persistent=True) self.assertEqual(