Ejemplo n.º 1
0
def test_deploy_public_sandbox_existing(mocker, monkeypatch):
    mock = mocker.Mock()

    def _mock_post(url, json, headers=None):
        mock(url=url, json=json)
        return SandboxGetMockResponse(response_code=200)

    monkeypatch.setattr(requests, "post", _mock_post)

    args = Namespace(
        uses='jinahub+sandbox://dummy_mwu_encoder',
        uses_with={'foo': 'bar'},
        test_string='text',
        test_number=1,
    )
    host, port = HubIO.deploy_public_sandbox(args)
    assert host == 'http://test_existing_deployment.com'
    assert port == 4321

    _, kwargs = mock.call_args
    assert kwargs['json']['args'] == {
        'uses_with': {
            'foo': 'bar'
        },
        'test_number': 1,
        'test_string': 'text',
    }
Ejemplo n.º 2
0
 def update_sandbox_args(self):
     """Update args of all its pods based on the host and port returned by Hubble"""
     if self.is_sandbox:
         host, port = HubIO.deploy_public_sandbox(self.args)
         self._sandbox_deployed = True
         self.first_pod_args.host = host
         self.first_pod_args.port = port
         if self.head_args:
             self.pod_args['head'].host = host
             self.pod_args['head'].port = port
Ejemplo n.º 3
0
    def update_pod_args(self):
        """ Update args of all its pods based on Deployment args. Including head/tail"""
        if isinstance(self.args, Dict):
            # This is used when a Deployment is created in a remote context, where pods & their connections are already given.
            self.pod_args = self.args
        else:
            self.pod_args = self._parse_args(self.args)

        if self.is_sandbox:
            host, port = HubIO.deploy_public_sandbox(
                getattr(self.args, 'uses', ''))
            self.first_pod_args.host = host
            self.first_pod_args.port_in = port
            self.pod_args['head'].host = host
            self.pod_args['head'].port_in = port
Ejemplo n.º 4
0
def test_deploy_public_sandbox_create_new(mocker, monkeypatch):
    mock = mocker.Mock()

    def _mock_post(url, json, headers=None):
        mock(url=url, json=json)
        if url.endswith('/sandbox.get'):
            return SandboxGetMockResponse(response_code=404)
        else:
            return SandboxCreateMockResponse(response_code=requests.codes.created)

    monkeypatch.setattr(requests, 'post', _mock_post)

    args = Namespace(uses='jinahub+sandbox://dummy_mwu_encoder')
    host, port = HubIO.deploy_public_sandbox(args)
    assert host == 'http://test_new_deployment.com'
    assert port == 4322