def test_connect(self): # test the connect grn = Groonga() grn.connect(host='localhost', port=10041) self.assertTrue(grn.connected) self.assertEqual(grn.host, 'localhost') self.assertEqual(grn.port, 10041)
def test_query_with_after_invalid_command(self): grn = Groonga() grn.connect() with pytest.raises(GroongaError): grn.query('unknown command') result = grn.query('cache_limit') assert result == '100'
def test_connect_with_params(self): grn = Groonga() assert grn.connected is False assert grn.host == '0.0.0.0' assert grn.port == 10041 grn.connect(host='localhost', port=10041) assert grn.connected is True assert grn.host == '0.0.0.0' assert grn.port == 10041
def test_connect_with_default(self): grn = Groonga() assert grn.connected is False assert grn.host == '0.0.0.0' assert grn.port == 10041 grn.connect() assert grn.connected is True assert grn.host == '0.0.0.0' assert grn.port == 10041
def test_connect_with_default(self): grn = Groonga() grn._ctx = mock.MagicMock() grn._ctx.connect.return_value = 0 assert grn.connected is False assert grn.host == '0.0.0.0' assert grn.port == 10041 grn.connect() assert grn.connected is True assert grn.host == '0.0.0.0' assert grn.port == 10041 assert grn._ctx.connect.mock_calls == [mock.call('0.0.0.0', 10041, flags=0)]
def test_connect_with_params(self): host = utils.random_string() port = random.randint(1025, 65535) grn = Groonga() grn._ctx = mock.MagicMock() grn._ctx.connect.return_value = 0 assert grn.connected is False assert grn.host == '0.0.0.0' assert grn.port == 10041 grn.connect(host=host, port=port) assert grn.connected is True assert grn.host == '0.0.0.0' assert grn.port == 10041 assert grn._ctx.connect.mock_calls == [mock.call(host, port, flags=0)]
def test_query(self): # test with not connected grn = Groonga() self.assertRaises(GroongaError, grn.query, 'a') # test with invalid command grn = Groonga() grn.connect('localhost', 10041) self.assertRaises(GroongaError, grn.query, 'a') # test the query grn = Groonga() grn.connect('localhost', 10041) result = grn.query('table_list') self.assertEqual(result, '''[[["id","UInt32"],["name","ShortText"],\ ["path","ShortText"],["flags","ShortText"],["domain","ShortText"],\ ["range","ShortText"]]]''') # test the query with after the query of invalid command grn = Groonga() grn.connect('localhost', 10041) self.assertRaises(GroongaError, grn.query, 'unknown command') result = grn.query('table_list') self.assertEqual(result, '''[[["id","UInt32"],["name","ShortText"],\ ["path","ShortText"],["flags","ShortText"],["domain","ShortText"],\ ["range","ShortText"]]]''')
def test_query(self): grn = Groonga() grn.connect() result = grn.query('cache_limit') assert result == '100'
def test_query_with_invalid_command(self): grn = Groonga() grn.connect() with pytest.raises(GroongaError): grn.query('a')
def test_connect_with_incorrect_params(self, host, port): grn = Groonga() with pytest.raises(GroongaError): grn.connect(host=host, port=port)