Example #1
0
 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)
Example #2
0
 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'
Example #3
0
 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
Example #4
0
 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
Example #5
0
 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)]
Example #6
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)]
Example #7
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"]]]''')
Example #8
0
 def test_query(self):
     grn = Groonga()
     grn.connect()
     result = grn.query('cache_limit')
     assert result == '100'
Example #9
0
 def test_query_with_invalid_command(self):
     grn = Groonga()
     grn.connect()
     with pytest.raises(GroongaError):
         grn.query('a')
Example #10
0
 def test_connect_with_incorrect_params(self, host, port):
     grn = Groonga()
     with pytest.raises(GroongaError):
         grn.connect(host=host, port=port)