def test_flow_depends_localpath(monkeypatch):
    monkeypatch.setattr(dependencies, 'change_cwd', nullcontext)
    monkeypatch.setattr(dependencies, 'get_workspace_path', lambda *args: filename)
    f = FlowDepends(DaemonID('jworkspace'), filename, Environment(envs=['a=b']))
    assert str(f.localpath()) == filename

    with pytest.raises(HTTPException) as e:
        monkeypatch.setattr(dependencies, "get_workspace_path", lambda *args: 'abc')
        f = FlowDepends(DaemonID('jworkspace'), filename, Environment(envs=['a=b']))
        f.localpath()
Exemple #2
0
def test_flow_depends_localpath(monkeypatch, tmpdir):
    filename = os.path.join(cur_dir, 'flow1.yml')
    monkeypatch.setattr(dependencies, 'change_cwd', nullcontext)
    monkeypatch.setattr(dependencies, 'get_workspace_path', lambda *args: filename)
    monkeypatch.setattr(FlowDepends, 'newfile', os.path.join(tmpdir, 'abc.yml'))
    f = FlowDepends(DaemonID('jworkspace'), filename, Environment(envs=['a=b']))
    assert str(f.localpath()) == filename

    with pytest.raises(HTTPException) as e:
        monkeypatch.setattr(dependencies, "get_workspace_path", lambda *args: 'abc')
        f = FlowDepends(DaemonID('jworkspace'), filename, Environment(envs=['a=b']))
        f.localpath()
Exemple #3
0
def test_flow_depends_load_and_dump(monkeypatch, tmpdir):
    filename = os.path.join(cur_dir, 'flow2.yml')
    monkeypatch.setattr(dependencies, 'get_workspace_path',
                        lambda *args: tmpdir)
    monkeypatch.setattr(FlowDepends, 'localpath',
                        lambda *args: os.path.join(tmpdir, filename))
    monkeypatch.setattr(FlowDepends, 'newfile',
                        os.path.join(tmpdir, 'abc.yml'))
    monkeypatch.setattr(FlowDepends, 'newname', 'abc.yml')
    copy(os.path.join(cur_dir, filename), tmpdir)

    fd = FlowDepends(
        workspace_id=DaemonID('jworkspace'),
        filename=filename,
        envs=Environment(envs=['a=b']),
    )
    with change_cwd(tmpdir):
        f: Flow = Flow.load_config(fd.params.uses).build()
        assert f.port_expose == 12345
        assert f.protocol == GatewayProtocolType.HTTP
        assert f['gateway'].args.runs_in_docker
        assert f['local_replicas'].args.runs_in_docker
        assert f['local_replicas'].args.port_in == 45678
        assert f['local_replicas'].args.port_in is not None
        assert all(port in fd.ports.ports for port in [
            f.port_expose,
            f['gateway'].args.port_in,
            f['gateway'].args.port_out,
            f['gateway'].args.port_ctrl,
            f['local_replicas'].args.port_in,
            f['local_replicas'].args.port_out,
            f['local_replicas'].args.port_ctrl,
            f['local_compound'].head_args.port_in,
            f['local_compound'].tail_args.port_out,
        ])
def test_flow_depends_ports(monkeypatch):
    expected_port = 28956
    monkeypatch.setattr(dependencies, 'change_cwd', nullcontext)
    monkeypatch.setattr(dependencies, 'get_workspace_path', lambda *args: filename)
    f = FlowDepends(DaemonID('jworkspace'), filename, Environment(envs=['a=b']))
    assert f.port_expose == expected_port
    assert f.ports == {f'{expected_port}/tcp': expected_port}
Exemple #5
0
def test_dump(monkeypatch, tmpdir):
    filename = os.path.join(cur_dir, 'flow3.yml')
    monkeypatch.setattr(dependencies, 'get_workspace_path',
                        lambda *args: tmpdir)
    monkeypatch.setattr(FlowDepends, 'localpath',
                        lambda *args: os.path.join(tmpdir, filename))
    monkeypatch.setattr(FlowDepends, 'newname',
                        os.path.join(tmpdir, 'abc.yml'))
    monkeypatch.setattr(FlowDepends, 'newfile', 'abc.yml')
    copy(os.path.join(cur_dir, filename), tmpdir)

    fd = FlowDepends(
        workspace_id=DaemonID('jworkspace'),
        filename=filename,
        envs=Environment(envs=['a=b']),
    )
    with change_cwd(tmpdir):
        f: Flow = Flow.load_config(fd.params.uses).build()
        assert f.port_expose == 12345
        assert f.protocol == GatewayProtocolType.HTTP
        assert f['local_replicas'].args.port_in == 45678
Exemple #6
0
def test_flow_depends_load_and_dump_given_context(monkeypatch, tmpdir):
    filename = os.path.join(cur_dir, 'flow_with_env.yml')
    monkeypatch.setattr(dependencies, 'get_workspace_path',
                        lambda *args: tmpdir)
    monkeypatch.setattr(FlowDepends, 'localpath',
                        lambda *args: os.path.join(tmpdir, filename))
    monkeypatch.setattr(FlowDepends, 'newfile',
                        os.path.join(tmpdir, 'abc.yml'))
    monkeypatch.setattr(FlowDepends, 'newname', 'abc.yml')
    copy(os.path.join(cur_dir, filename), tmpdir)

    fd = FlowDepends(
        workspace_id=DaemonID('jworkspace'),
        filename=filename,
        envs=Environment(envs=[
            'context_var1=val1', 'context_var2=val2', 'context_var3=val3'
        ]),
    )
    fd.load_and_dump()
    f = Flow.load_config(source=os.path.join(tmpdir, 'abc.yml'))
    envs = f.args.env
    assert envs['key1'] == 'val1'
    assert envs['key2'] != 'val2'
    assert envs['key3'] != 'val3'
Exemple #7
0
def test_environment(envs, expected):
    assert Environment(envs=envs).vars == expected