22import json
33import unittest
44
5+ import pytest
6+
57from pysolr import SolrCoreAdmin , SolrError
68
79
@@ -49,28 +51,28 @@ def test_status(self):
4951 raw_all = self .solr_admin .status ()
5052 all_data = json .loads (raw_all )
5153
52- self . assertIn ( "core0" , all_data ["status" ])
54+ assert "core0" in all_data ["status" ]
5355
5456 # Status of a specific core
5557 raw_single = self .solr_admin .status (core = "core0" )
5658 single_data = json .loads (raw_single )
5759
58- self . assertEqual ( single_data ["status" ]["core0" ]["name" ], "core0" )
60+ assert single_data ["status" ]["core0" ]["name" ] == "core0"
5961
6062 def test_create (self ):
6163 """Test creating a core returns a successful response."""
6264 raw_response = self .solr_admin .create ("demo_core1" )
6365 data = json .loads (raw_response )
6466
65- self . assertEqual ( data ["responseHeader" ]["status" ], 0 )
66- self . assertEqual ( data ["core" ], "demo_core1" )
67+ assert data ["responseHeader" ]["status" ] == 0
68+ assert data ["core" ] == "demo_core1"
6769
6870 def test_reload (self ):
6971 """Test reloading a core returns a successful response."""
7072 raw_response = self .solr_admin .reload ("core0" )
7173 data = json .loads (raw_response )
7274
73- self . assertEqual ( data ["responseHeader" ]["status" ], 0 )
75+ assert data ["responseHeader" ]["status" ] == 0
7476
7577 def test_rename (self ):
7678 """Test renaming a core succeeds and the new name appears in the status."""
@@ -82,13 +84,13 @@ def test_rename(self):
8284 raw_response = self .solr_admin .rename ("demo_core1" , "demo_core2" )
8385 data = json .loads (raw_response )
8486
85- self . assertEqual ( data ["responseHeader" ]["status" ], 0 )
87+ assert data ["responseHeader" ]["status" ] == 0
8688
8789 # Verify that the renamed core appears in the status response
8890 raw_response2 = self .solr_admin .status (core = "demo_core2" )
8991 data2 = json .loads (raw_response2 )
9092
91- self . assertEqual ( data2 ["status" ]["demo_core2" ]["name" ], "demo_core2" )
93+ assert data2 ["status" ]["demo_core2" ]["name" ] == "demo_core2"
9294
9395 def test_swap (self ):
9496 """
@@ -110,7 +112,7 @@ def test_swap(self):
110112 raw_swap = self .solr_admin .swap ("demo_core1" , "demo_core2" )
111113 swap_data = json .loads (raw_swap )
112114
113- self . assertEqual ( swap_data ["responseHeader" ]["status" ], 0 )
115+ assert swap_data ["responseHeader" ]["status" ] == 0
114116
115117 def test_unload (self ):
116118 """
@@ -124,18 +126,19 @@ def test_unload(self):
124126 raw_response = self .solr_admin .unload ("demo_core1" )
125127 data = json .loads (raw_response )
126128
127- self . assertEqual ( data ["responseHeader" ]["status" ], 0 )
129+ assert data ["responseHeader" ]["status" ] == 0
128130
129131 def test_load (self ):
130- self .assertRaises (NotImplementedError , self .solr_admin .load , "wheatley" )
132+ with pytest .raises (NotImplementedError ):
133+ self .solr_admin .load ("wheatley" )
131134
132135 def test_status__nonexistent_core_returns_empty_response (self ):
133136 """Test that requesting status for a missing core returns an empty response."""
134137 raw_response = self .solr_admin .status (core = "not_exists" )
135138 data = json .loads (raw_response )
136139
137- self . assertNotIn ( "name" , data ["status" ]["not_exists" ])
138- self . assertNotIn ( "instanceDir" , data ["status" ]["not_exists" ])
140+ assert "name" not in data ["status" ]["not_exists" ]
141+ assert "instanceDir" not in data ["status" ]["not_exists" ]
139142
140143 def test_create__existing_core_raises_error (self ):
141144 """Test creating a core that already exists returns a 500 error."""
@@ -147,20 +150,18 @@ def test_create__existing_core_raises_error(self):
147150 raw_response = self .solr_admin .create ("demo_core1" )
148151 data = json .loads (raw_response )
149152
150- self .assertEqual (data ["responseHeader" ]["status" ], 500 )
151- self .assertEqual (
152- data ["error" ]["msg" ], "Core with name 'demo_core1' already exists."
153- )
153+ assert data ["responseHeader" ]["status" ] == 500
154+ assert data ["error" ]["msg" ] == "Core with name 'demo_core1' already exists."
154155
155156 def test_reload__nonexistent_core_raises_error (self ):
156157 """Test that reloading a non-existent core returns a 400 error."""
157158 raw_response = self .solr_admin .reload ("not_exists" )
158159 data = json .loads (raw_response )
159160
160161 # Solr returns a 400 error for missing cores
161- self . assertEqual ( data ["responseHeader" ]["status" ], 400 )
162- self . assertIn ( "No such core" , data ["error" ]["msg" ])
163- self . assertIn ( "not_exists" , data ["error" ]["msg" ])
162+ assert data ["responseHeader" ]["status" ] == 400
163+ assert "No such core" in data ["error" ]["msg" ]
164+ assert "not_exists" in data ["error" ]["msg" ]
164165
165166 def test_rename__nonexistent_core_no_effect (self ):
166167 """
@@ -179,8 +180,8 @@ def test_rename__nonexistent_core_no_effect(self):
179180 data = json .loads (raw_response )
180181
181182 # The target core should not exist because the rename operation was ignored
182- self . assertNotIn ( "name" , data ["status" ]["demo_core99" ])
183- self . assertNotIn ( "instanceDir" , data ["status" ]["demo_core99" ])
183+ assert "name" not in data ["status" ]["demo_core99" ]
184+ assert "instanceDir" not in data ["status" ]["demo_core99" ]
184185
185186 def test_swap__missing_source_core_returns_error (self ):
186187 """Test swapping when the source core is missing returns a 400 error."""
@@ -193,9 +194,9 @@ def test_swap__missing_source_core_returns_error(self):
193194 data = json .loads (raw_response )
194195
195196 # Solr returns a 400 error when the source core does not exist
196- self . assertEqual ( data ["responseHeader" ]["status" ], 400 )
197- self . assertIn ( "No such core" , data ["error" ]["msg" ])
198- self . assertIn ( "not_exists" , data ["error" ]["msg" ])
197+ assert data ["responseHeader" ]["status" ] == 400
198+ assert "No such core" in data ["error" ]["msg" ]
199+ assert "not_exists" in data ["error" ]["msg" ]
199200
200201 def test_swap__missing_target_core_returns_error (self ):
201202 """Test swapping when the target core is missing returns a 400 error."""
@@ -208,9 +209,9 @@ def test_swap__missing_target_core_returns_error(self):
208209 data = json .loads (raw_response )
209210
210211 # Solr returns a 400 error when the target core does not exist
211- self . assertEqual ( data ["responseHeader" ]["status" ], 400 )
212- self . assertIn ( "No such core" , data ["error" ]["msg" ])
213- self . assertIn ( "not_exists" , data ["error" ]["msg" ])
212+ assert data ["responseHeader" ]["status" ] == 400
213+ assert "No such core" in data ["error" ]["msg" ]
214+ assert "not_exists" in data ["error" ]["msg" ]
214215
215216 def test_unload__nonexistent_core_returns_error (self ):
216217 """Test unloading a non-existent core returns a 400 error response."""
@@ -220,6 +221,6 @@ def test_unload__nonexistent_core_returns_error(self):
220221 data = json .loads (raw_response )
221222
222223 # Solr returns a 400 error for unloading a missing core
223- self . assertEqual ( data ["responseHeader" ]["status" ], 400 )
224- self . assertIn ( "Cannot unload non-existent core" , data ["error" ]["msg" ])
225- self . assertIn ( "not_exists" , data ["error" ]["msg" ])
224+ assert data ["responseHeader" ]["status" ] == 400
225+ assert "Cannot unload non-existent core" in data ["error" ]["msg" ]
226+ assert "not_exists" in data ["error" ]["msg" ]
0 commit comments