Ejemplo n.º 1
0
    def test_retrieve_rows(self, mock_uri, mock_get_from_uri,
                           mock_presto_config):
        client = PrestoClient('any_host', 'any_user')
        dir = os.path.abspath(os.path.dirname(__file__))

        with open(dir + '/resources/valid_rest_response_level1.txt') \
                as json_file:
            client.response_from_server = json.load(json_file)
        mock_get_from_uri.return_value = True
        mock_uri.side_effect = [
            "http://localhost:8080/v1/statement/2015_harih/2", ""
        ]

        self.assertEqual(client.get_rows(), [])
        self.assertEqual(client.next_uri,
                         "http://localhost:8080/v1/statement/2015_harih/2")

        with open(dir + '/resources/valid_rest_response_level2.txt') \
                as json_file:
            client.response_from_server = json.load(json_file)
        mock_uri.side_effect = [
            "http://localhost:8080/v1/statement/2015_harih/2", ""
        ]

        expected_row = [[
            "uuid1", "http://localhost:8080", "presto-main:0.97", True
        ], ["uuid2", "http://worker:8080", "presto-main:0.97", False]]
        self.assertEqual(client.get_rows(), expected_row)
        self.assertEqual(client.next_uri, "")
Ejemplo n.º 2
0
    def test_retrieve_rows(self, mock_uri, mock_get_from_uri, mock_port):
        mock_port.return_value = 8080
        client = PrestoClient('any_host', 'any_user')
        dir = os.path.abspath(os.path.dirname(__file__))

        with open(dir + '/resources/valid_rest_response_level1.txt') \
                as json_file:
            client.response_from_server = json.load(json_file)
        mock_get_from_uri.return_value = True
        mock_uri.side_effect = [
            "http://localhost:8080/v1/statement/2015_harih/2", ""
        ]

        self.assertEqual(client.get_rows(), [])
        self.assertEqual(client.next_uri,
                         "http://localhost:8080/v1/statement/2015_harih/2")

        with open(dir + '/resources/valid_rest_response_level2.txt') \
                as json_file:
            client.response_from_server = json.load(json_file)
        mock_uri.side_effect = [
            "http://localhost:8080/v1/statement/2015_harih/2", ""
        ]

        expected_row = [["uuid1", "http://localhost:8080", "presto-main:0.97",
                         True],
                        ["uuid2", "http://worker:8080", "presto-main:0.97",
                         False]]
        self.assertEqual(client.get_rows(), expected_row)
        self.assertEqual(client.next_uri, "")
Ejemplo n.º 3
0
    def test_limit_rows(self, mock_uri, mock_get_from_uri):
        client = PrestoClient('any_host', 'any_user', 8080)
        dir = os.path.abspath(os.path.dirname(__file__))
        with open(dir + '/files/valid_rest_response_level2.txt') as json_file:
            client.response_from_server = json.load(json_file)
        mock_get_from_uri.return_value = True
        mock_uri.side_effect = ["any_next_uri", ""]

        self.assertEqual(client.get_rows(0), [])
Ejemplo n.º 4
0
    def test_limit_rows(self, mock_uri, mock_get_from_uri, mock_presto_config):
        client = PrestoClient('any_host', 'any_user')
        dir = os.path.abspath(os.path.dirname(__file__))
        with open(dir + '/resources/valid_rest_response_level2.txt') \
                as json_file:
            client.response_from_server = json.load(json_file)
        mock_get_from_uri.return_value = True
        mock_uri.side_effect = ["any_next_uri", ""]

        self.assertEqual(client.get_rows(0), [])
Ejemplo n.º 5
0
 def test_execute_query_get_port(self, run_mock, conn_mock):
     client = PrestoClient('any_host', 'any_user')
     client.rows = ['hello']
     client.next_uri = 'hello'
     client.response_from_server = {'hello': 'hello'}
     run_mock.return_value = _AttributeString('http-server.http.port=8080')
     run_mock.return_value.failed = False
     client.execute_query('select * from nation')
     self.assertEqual(client.port, 8080)
     self.assertEqual(client.rows, [])
     self.assertEqual(client.next_uri, '')
     self.assertEqual(client.response_from_server, {})
 def testrun_sql_get_port(self, sudo_mock, conn_mock, mock_presto_config):
     client = PrestoClient('any_host', 'any_user')
     client.rows = ['hello']
     client.next_uri = 'hello'
     client.response_from_server = {'hello': 'hello'}
     sudo_mock.return_value = _AttributeString('http-server.http.port=8080')
     sudo_mock.return_value.failed = False
     sudo_mock.return_value.return_code = 0
     client.run_sql('select * from nation')
     self.assertEqual(client.port, 8080)
     self.assertEqual(client.rows, [])
     self.assertEqual(client.next_uri, '')
     self.assertEqual(client.response_from_server, {})
Ejemplo n.º 7
0
 def testrun_sql_get_port(self, sudo_mock, conn_mock, mock_presto_config):
     client = PrestoClient('any_host', 'any_user')
     client.rows = ['hello']
     client.next_uri = 'hello'
     client.response_from_server = {'hello': 'hello'}
     sudo_mock.return_value = _AttributeString('http-server.http.port=8080')
     sudo_mock.return_value.failed = False
     sudo_mock.return_value.return_code = 0
     client.run_sql('select * from nation')
     self.assertEqual(client.port, 8080)
     self.assertEqual(client.rows, [])
     self.assertEqual(client.next_uri, '')
     self.assertEqual(client.response_from_server, {})
Ejemplo n.º 8
0
    def test_append_rows(self, mock_uri, mock_get_from_uri, mock_port):
        mock_port.return_value = 8080
        client = PrestoClient('any_host', 'any_user')
        dir = os.path.abspath(os.path.dirname(__file__))

        with open(dir + '/resources/valid_rest_response_level2.txt') \
                as json_file:
            client.response_from_server = json.load(json_file)
        mock_get_from_uri.return_value = True
        mock_uri.side_effect = ["any_next_uri", "any_next_next_uri", "", ""]
        expected_row = [
            ["uuid1", "http://localhost:8080", "presto-main:0.97", True],
            ["uuid2", "http://worker:8080", "presto-main:0.97", False],
            ["uuid1", "http://localhost:8080", "presto-main:0.97", True],
            ["uuid2", "http://worker:8080", "presto-main:0.97", False]
        ]
        self.assertEqual(client.get_rows(), expected_row)
Ejemplo n.º 9
0
    def test_append_rows(self, mock_uri, mock_get_from_uri):
        client = PrestoClient('any_host', 'any_user', 8080)
        dir = os.path.abspath(os.path.dirname(__file__))

        with open(dir + '/files/valid_rest_response_level2.txt') as json_file:
            client.response_from_server = json.load(json_file)
        mock_get_from_uri.return_value = True
        mock_uri.side_effect = ["any_next_uri", "any_next_next_uri", "", ""]
        expected_row = [["uuid1", "http://localhost:8080", "presto-main:0.97",
                         True],
                        ["uuid2", "http://worker:8080", "presto-main:0.97",
                         False],
                        ["uuid1", "http://localhost:8080", "presto-main:0.97",
                         True],
                        ["uuid2", "http://worker:8080",  "presto-main:0.97",
                         False]]
        self.assertEqual(client.get_rows(), expected_row)