Repository: jina-ai/jina
File: tests/unit/orchestrate/flow/flow-construct/test_flow_to_docker_compose_yaml.py (Python)

Code before:
        uses='docker://image', name='executor0', disable_auto_volume=True
    )

    dump_path = os.path.join(str(tmpdir), 'test_flow_docker_compose_volume.yml')

    flow.to_docker_compose_yaml(output_path=dump_path)

    configuration = None
    with open(dump_path) as f:
        configuration = yaml.safe_load(f)

    assert set(configuration.keys()) == {'version', 'services', 'networks'}
    assert configuration['version'] == '3.3'
    assert configuration['networks'] == {'jina-network': {'driver': 'bridge'}}
    services = configuration['services']
    assert len(services) == 2  # gateway, executor0-head, executor0
    assert set(services.keys()) == {
        'gateway',
        'executor0',
    }
    assert 'volumes' not in services['executor0']


@pytest.mark.parametrize(
    'uses',
    ['jinahub+sandbox://DummyHubExecutor', 'jinaai+sandbox://jina-ai/DummyHubExecutor'],
)
def test_flow_to_docker_compose_sandbox(tmpdir, uses):
    flow = Flow(name='test-flow', port=8080).add(uses=uses)

    dump_path = os.path.join(str(tmpdir), 'test_flow_docker_compose.yml')

    flow.to_docker_compose_yaml(
        output_path=dump_path,
    )

    configuration = None
    with open(dump_path) as f:
        configuration = yaml.safe_load(f)

    services = configuration['services']
    gateway_service = services['gateway']
    gateway_args = gateway_service['command']

    deployment_addresses = json.loads(
        gateway_args[gateway_args.index('--deployments-addresses') + 1]
    )
    assert deployment_addresses['executor0'][0].startswith('grpcs://')


@pytest.mark.parametrize('count', [1, 'all'])

Review comment (suggestion):
```suggestion
    ['jinaai+sandbox://jina-ai/DummyHubExecutor'],
```

Code after:
        uses='docker://image', name='executor0', disable_auto_volume=True
    )

    dump_path = os.path.join(str(tmpdir), 'test_flow_docker_compose_volume.yml')

    flow.to_docker_compose_yaml(output_path=dump_path)

    configuration = None
    with open(dump_path) as f:
        configuration = yaml.safe_load(f)

    assert set(configuration.keys()) == {'version', 'services', 'networks'}
    assert configuration['version'] == '3.3'
    assert configuration['networks'] == {'jina-network': {'driver': 'bridge'}}
    services = configuration['services']
    assert len(services) == 2  # gateway, executor0-head, executor0
    assert set(services.keys()) == {
        'gateway',
        'executor0',
    }
    assert 'volumes' not in services['executor0']


@pytest.mark.parametrize(
    'uses',
    ['jinaai+sandbox://jina-ai/DummyHubExecutor'],
)
def test_flow_to_docker_compose_sandbox(tmpdir, uses):
    flow = Flow(name='test-flow', port=8080).add(uses=uses)

    dump_path = os.path.join(str(tmpdir), 'test_flow_docker_compose.yml')

    flow.to_docker_compose_yaml(
        output_path=dump_path,
    )

    configuration = None
    with open(dump_path) as f:
        configuration = yaml.safe_load(f)

    services = configuration['services']
    gateway_service = services['gateway']
    gateway_args = gateway_service['command']

    deployment_addresses = json.loads(
        gateway_args[gateway_args.index('--deployments-addresses') + 1]
    )
    assert deployment_addresses['executor0'][0].startswith('grpcs://')


@pytest.mark.parametrize('count', [1, 'all'])