示例#1
0
    def test_make_deployment_throws_if_no_default_deployment(
            self, requests_mock):
        self._setUpSession(requests_mock)

        requests_mock.request(
            method='post',
            url='http://localhost:8080{}'.format(
                sql_validate_endpoint(self.namespace)),
            text=
            """ { "validationResult": "VALIDATION_RESULT_VALID_INSERT_QUERY" } """,
            status_code=201)

        requests_mock.request(
            method='get',
            url='http://localhost:8080{}'.format(
                deployment_defaults_endpoint(self.namespace)),
            text="""{ "kind": "DeploymentDefaults", "spec": {} }""",
            status_code=200)

        cell = """SOME VALID DML QUERY"""

        with self.assertRaises(VvpConfigurationException) as raised_exception:
            Deployments().make_deployment(cell, self.session, ShellMock({}),
                                          ArgsMock(None))

        assert raised_exception.exception.__str__(
        ) == NO_DEFAULT_DEPLOYMENT_MESSAGE
    def test_deal_with_errors(self, requests_mock):
        self._setUpSession(requests_mock)
        requests_mock.request(method='post',
                              url='http://localhost:8080{}'.format(
                                  sql_complete_endpoint(self.namespace)),
                              text=""" {
                                          "error": "Does not compute"
                                        } """)

        cell = """%%flink_sql\nSHOW TAB"""

        response = _do_flink_completion(cell, 38)
        assert response is None
示例#3
0
    def test_connect_vvp_calls_https_endpoint_if_specified(
            self, requests_mock):
        namespaces_response = '{{ "namespaces": [{{ "name": "namespaces/{}" }}] }}'.format(
            self.namespace)
        requests_mock.request(
            method='get',
            url='https://localhost:8080/namespaces/v1/namespaces',
            text=namespaces_response)
        magic_line = "localhost -p 8080 -S"
        magics = VvpMagics()

        response = magics.connect_vvp(magic_line)

        assert response['namespaces']
示例#4
0
    def _setUpSession(self, requests_mock):
        requests_mock.request(
            method='get',
            url='http://localhost:8080/api/v1/namespaces/{}/deployment-targets'
            .format(self.namespace),
            text="Ignored in session setup.")

        requests_mock.request(
            method='get',
            url='http://localhost:8080/namespaces/v1/namespaces/{}'.format(
                self.namespace),
            text="""
                                {{ "namespace": [{{ "name": "namespaces/{}" }}] }}
                                """.format(self.namespace))
        self.session = VvpSession.create_session(self.vvp_base_url,
                                                 self.namespace, "session1")
    def test_ignore_cursor_in_command_line(self, requests_mock):
        self._setUpSession(requests_mock)
        requests_mock.request(method='post',
                              url='http://localhost:8080{}'.format(
                                  sql_complete_endpoint(self.namespace)),
                              text=""" {
                                          "completions": [{
                                            "text": "TABLES",
                                            "type": "HINT_TYPE_UNKNOWN"
                                          }]
                                        } """)

        cell = """%%flink_sql\nSHOW TAB"""

        response = _do_flink_completion(cell, 6)
        assert response is None
示例#6
0
    def setup_mocks_with_key(self, requests_mock, key):
        def match_headers(request):
            return request.headers['Authorization'] == "Bearer {}".format(key)

        requests_mock.request(
            method='get',
            url='http://localhost:8080/api/v1/namespaces/{}/deployment-targets'
            .format(self.namespace),
            additional_matcher=match_headers,
            text="Ignored in session setup.")
        requests_mock.request(
            method='get',
            url='http://localhost:8080/namespaces/v1/namespaces',
            additional_matcher=match_headers,
            text="""
        { "namespaces": [{ "name": "namespaces/test" }] }
        """)
    def test_complete_correct_line(self, requests_mock):
        self._setUpSession(requests_mock)
        requests_mock.request(method='post',
                              url='http://localhost:8080{}'.format(
                                  sql_complete_endpoint(self.namespace)),
                              text=""" {
                                          "completions": [{
                                            "text": "TABLES",
                                            "type": "HINT_TYPE_UNKNOWN"
                                          }]
                                        } """)

        cell = """%%flink_sql\nSHOW TAB"""

        response = _do_flink_completion(cell, 20)
        assert response['status'] == 'ok'
        assert response['matches'][0] == "TABLES"
        assert response['cursor_end'] == 20
        assert response['cursor_start'] == 17
示例#8
0
def _compare_requests(requests_mock,
                      vast_func,
                      vast_args,
                      vast_client_method,
                      response_json=None,
                      **kwargs):
    with pytest.raises(NoMockAddress):
        resp = capture_output(vast_func, vast_args)
    print("pytest.py requested: ", requests_mock.last_request.method,
          requests_mock.last_request.url)
    print("       request body: ", requests_mock.last_request.text)

    # Now test new VastClient.get_instances() and make sure the request matches the one vast.py made.
    last_req = requests_mock.last_request
    requests_mock.request(last_req.method,
                          last_req.url,
                          json=response_json or {})
    result = vast_client_method(**kwargs)

    print("vastai requested:    ", requests_mock.last_request.method,
          requests_mock.last_request.url)
    print("       request body: ", requests_mock.last_request.text)

    assert requests_mock.last_request.url == last_req.url, "Request url should be the same as vast.py."
    assert requests_mock.last_request.method == last_req.method, "Request method should be the same as vast.py."
    #assert requests_mock.last_request.text == last_req.text, "Request text should be the same as vast.py."
    if requests_mock.last_request.text is not None and last_req.text is not None:
        data0 = json.loads(last_req.text)
        data1 = json.loads(requests_mock.last_request.text)
        for attr in data0:
            if data0[attr] not in [False, None]:
                assert data0[attr] == data1[
                    attr], "'%s' attributes should match" % attr
        for attr in data1:
            if data1[attr] not in [False, None]:
                assert data1[attr] == data0[
                    attr], "'%s' attributes should match" % attr
    else:
        assert requests_mock.last_request.text == last_req.text, "Request text should be the same as vast.py."

    return result
示例#9
0
    def test_make_deployment_returns_deployment_id(self, requests_mock):
        self._setUpSession(requests_mock)

        deployment_id = """58ea758d-02e2-4b8e-8d60-3c36c3413bf3"""
        requests_mock.request(method='post',
                              url='http://localhost:8080{}'.format(
                                  sql_deployment_create_endpoint(
                                      self.namespace)),
                              text=("""{ "kind" : "Deployment",
                                 "metadata" : {
                                   "id" : "%s",
                                   "name" : "INSERT INTO testTable1836f SELECT * FROM testTable22293",
                                   "namespace" : "default"
                                 },
                                 "spec" : {
                                   "state" : "RUNNING",
                                   "deploymentTargetId" : "0b7e8f13-6943-404e-9809-c14db57d195e"
                                 } 
                                 }
                                 """ % deployment_id),
                              status_code=201)

        requests_mock.request(method='get',
                              url='http://localhost:8080{}'.format(
                                  deployment_defaults_endpoint(
                                      self.namespace)),
                              text=""" { "kind": "DeploymentDefaults",
                                "spec": { "deploymentTargetId": "0b7e8f13-6943-404e-9809-c14db57d195e" } } """,
                              status_code=200)

        requests_mock.request(method='get',
                              url='http://localhost:8080{}/{}'.format(
                                  sql_deployment_create_endpoint(
                                      self.namespace), deployment_id),
                              text="""{"DummyKey": "DummyValue"}""",
                              status_code=200)
        requests_mock.request(
            method='get',
            url='http://localhost:8080{}'.format(
                sql_deployment_endpoint(self.namespace, deployment_id)),
            text="""{ "kind" : "Deployment",   "status" : { "state" : "RUNNING",
                                  "running" : { "jobId" : "68ab92d0-1acc-459f-a6ed-26a374e08717" } }
                                }""")

        cell = """SOME VALID DML QUERY"""

        response = Deployments().make_deployment(cell, self.session,
                                                 ShellMock({}), ArgsMock(None))
        assert response == deployment_id
示例#10
0
    def setUpMocks(self, requests_mock):
        namespaces_response = '{{ "namespaces": [{{ "name": "namespaces/{}" }}] }}'.format(
            self.namespace)
        requests_mock.request(
            method='get',
            url='http://localhost:8080/namespaces/v1/namespaces',
            text=namespaces_response)

        requests_mock.request(
            method='get',
            url='http://localhost:8080/namespaces/v1/namespaces/{}'.format(
                self.namespace),
            text="""
        {{ "namespace": [{{ "name": "namespaces/{}" }}] }}
        """.format(self.namespace))
        requests_mock.request(
            method='get',
            url='http://localhost:8080/api/v1/namespaces/{}/deployment-targets'
            .format(self.namespace),
            text="Ignored in session setup.")