Exemplo n.º 1
0
def test_simple(fake_stdout, fake_stderr):
    tmp = maketemp()
    repo = os.path.join(tmp, 'repo')
    os.mkdir(repo)
    remote = os.path.join(tmp, 'remote')
    os.mkdir(remote)
    scratch = os.path.join(tmp, 'scratch')
    os.mkdir(scratch)
    flag = os.path.join(tmp, 'flag')
    subprocess.check_call(args=[
        'git',
        '--git-dir={0}'.format(remote),
        'init',
        '--quiet',
        '--bare',
    ], )
    fast_import(
        repo=remote,
        commits=[
            dict(
                message='Initial import.',
                committer='John Doe <*****@*****.**>',
                commit_time='1216235872 +0300',
                files=[
                    dict(
                        path='requirements.txt',
                        content="""\
# dummy
""",
                    ),
                    dict(
                        path='deploy.py',
                        content="""\
import json
import os
print "fakedeploy start"
print json.dumps(dict(cwd=os.getcwd()))
with file(FLAGPATH, "w") as f:
    f.write('xyzzy')
print "fakedeploy end"
""".replace('FLAGPATH', repr(flag)),
                    ),
                ],
            ),
            dict(
                message='Second commit.',
                committer='Jack Smith <*****@*****.**>',
                commit_time='1216243120 +0300',
                files=[
                    dict(
                        path='deploy.py',
                        content="""\
import json
import os
print "fakedeploy2 start"
print json.dumps(dict(cwd=os.getcwd()))
with file(FLAGPATH, "w") as f:
    f.write('thud')
print "fakedeploy2 end"
""".replace('FLAGPATH', repr(flag)),
                    ),
                ],
            ),
        ],
    )
    subprocess.check_call(args=[
        'git',
        '--git-dir={0}'.format(repo),
        'init',
        '--quiet',
        '--bare',
    ], )
    subprocess.check_call(args=[
        'git',
        '--git-dir={0}'.format(repo),
        'remote',
        'add',
        'origin',
        '--',
        remote,
    ], )
    subprocess.check_call(args=[
        'git',
        '--git-dir={0}'.format(repo),
        'fetch',
        '--quiet',
        '--all',
    ], )
    # cause remote to have something new for us
    subprocess.check_call(args=[
        'git',
        '--git-dir={0}'.format(repo),
        'update-ref',
        'HEAD',
        'remotes/origin/master~1',
    ], )
    subprocess.check_call(args=[
        'git',
        '--git-dir={0}'.format(repo),
        'symbolic-ref',
        'refs/remotes/origin/HEAD',
        'refs/remotes/origin/master',
    ], )
    out = StringIO()
    fake_stdout.expects('write').calls(out.write)
    assert not os.path.exists(flag)
    main(args=[
        'pull',
        '--repository',
        repo,
        '--temp',
        scratch,
    ], )
    assert os.path.exists(flag)
    with file(flag) as f:
        got = f.read()
    eq(got, 'thud')
    got = out.getvalue().splitlines()
    eq(got[0], 'fakedeploy2 start')
    eq(got[2], 'fakedeploy2 end')
    eq(got[3:], [])
    got = json.loads(got[1])
    cwd = got.pop('cwd')
    (head, tail) = os.path.split(cwd)
    eq(head, scratch)
    assert re.match(r'^troops-[a-zA-Z0-9_]{6,}$', tail), \
        "Odd cwd for deploy: {path!r}".format(path=cwd)
    eq(got, {})
Exemplo n.º 2
0
def test_simple(fake_stdout, fake_stderr):
    tmp = maketemp()
    repo = os.path.join(tmp, 'repo')
    os.mkdir(repo)
    scratch = os.path.join(tmp, 'scratch')
    os.mkdir(scratch)
    flag = os.path.join(tmp, 'flag')
    subprocess.check_call(
        args=[
            'git',
            '--git-dir={0}'.format(repo),
            'init',
            '--quiet',
            '--bare',
            ],
        )
    fast_import(
        repo=repo,
        commits=[
            dict(
                message='Initial import.',
                committer='John Doe <*****@*****.**>',
                commit_time='1216235872 +0300',
                files=[
                    dict(
                        path='requirements.txt',
                        content="""\
# pip complains if this file is left empty, so say something we know
# is easily accessible
pip
""",
                        ),
                    dict(
                        path='deploy.py',
                        content="""\
import json
import os
print "fakedeploy start"
print json.dumps(dict(cwd=os.getcwd()))
with file(FLAGPATH, "a") as f:
    f.write('xyzzy')
print "fakedeploy end"
""".replace('FLAGPATH', repr(flag)),
                        ),
                    ],
                ),
            dict(
                message='Second commit.',
                committer='Jack Smith <*****@*****.**>',
                commit_time='1216243120 +0300',
                files=[
                    dict(
                        path='deploy.py',
                        content="""\
import json
import os
print "fakedeploy2 start"
print json.dumps(dict(cwd=os.getcwd()))
with file(FLAGPATH, "a") as f:
    f.write('thud')
print "fakedeploy2 end"
""".replace('FLAGPATH', repr(flag)),
                        ),
                    ],
                ),
            ],
        )
    # cause remote to have something new for us
    subprocess.check_call(
        args=[
            'git',
            '--git-dir={0}'.format(repo),
            'update-ref',
            'refs/remotes/origin/master',
            'HEAD',
            ],
        )
    subprocess.check_call(
        args=[
            'git',
            '--git-dir={0}'.format(repo),
            'update-ref',
            'HEAD',
            'HEAD~1',
            ],
        )
    subprocess.check_call(
        args=[
            'git',
            '--git-dir={0}'.format(repo),
            'symbolic-ref',
            'refs/remotes/origin/HEAD',
            'refs/remotes/origin/master',
            ],
        )
    out = StringIO()
    fake_stdout.expects('write').calls(out.write)
    assert not os.path.exists(flag)
    main(
        args=[
            'merge',
            '--repository', repo,
            '--temp', scratch,
            ],
        )
    got = out.getvalue().splitlines()
    eq(got[0], 'fakedeploy2 start')
    eq(got[2], 'fakedeploy2 end')
    eq(got[3:], [])
    got = json.loads(got[1])
    cwd = got.pop('cwd')
    (head, tail) = os.path.split(cwd)
    eq(head, scratch)
    assert re.match(r'^troops-[a-zA-Z0-9_]{6,}$', tail), \
        "Odd cwd for deploy: {path!r}".format(path=cwd)
    eq(got, {})
    assert os.path.exists(flag)
    with file(flag) as f:
        got = f.read()
    eq(got, 'thud')
Exemplo n.º 3
0
def test_uptodate(fake_stdout, fake_stderr):
    tmp = maketemp()
    repo = os.path.join(tmp, 'repo')
    os.mkdir(repo)
    scratch = os.path.join(tmp, 'scratch')
    os.mkdir(scratch)
    flag = os.path.join(tmp, 'flag')
    subprocess.check_call(
        args=[
            'git',
            '--git-dir={0}'.format(repo),
            'init',
            '--quiet',
            '--bare',
            ],
        )
    fast_import(
        repo=repo,
        commits=[
            dict(
                message='Initial import.',
                committer='John Doe <*****@*****.**>',
                commit_time='1216235872 +0300',
                files=[
                    dict(
                        path='requirements.txt',
                        content="""\
# pip complains if this file is left empty, so say something we know
# is easily accessible
pip
""",
                        ),
                    dict(
                        path='deploy.py',
                        content="""\
import json
import os
print "fakedeploy start"
print json.dumps(dict(cwd=os.getcwd()))
with file(FLAGPATH, "a") as f:
    f.write('xyzzy')
print "fakedeploy end"
""".replace('FLAGPATH', repr(flag)),
                        ),
                    ],
                ),
            ],
        )
    # cause remote to have something new for us
    subprocess.check_call(
        args=[
            'git',
            '--git-dir={0}'.format(repo),
            'update-ref',
            'refs/remotes/origin/master',
            'HEAD',
            ],
        )
    subprocess.check_call(
        args=[
            'git',
            '--git-dir={0}'.format(repo),
            'symbolic-ref',
            'refs/remotes/origin/HEAD',
            'refs/remotes/origin/master',
            ],
        )
    out = StringIO()
    fake_stdout.provides('write').calls(out.write)
    assert not os.path.exists(flag)
    main(
        args=[
            'merge',
            '--repository', repo,
            '--temp', scratch,
            ],
        )
    got = out.getvalue().splitlines()
    eq(got, [])
    assert not os.path.exists(flag)
Exemplo n.º 4
0
def test_uptodate(fake_stdout, fake_stderr):
    tmp = maketemp()
    repo = os.path.join(tmp, 'repo')
    os.mkdir(repo)
    scratch = os.path.join(tmp, 'scratch')
    os.mkdir(scratch)
    flag = os.path.join(tmp, 'flag')
    subprocess.check_call(args=[
        'git',
        '--git-dir={0}'.format(repo),
        'init',
        '--quiet',
        '--bare',
    ], )
    fast_import(
        repo=repo,
        commits=[
            dict(
                message='Initial import.',
                committer='John Doe <*****@*****.**>',
                commit_time='1216235872 +0300',
                files=[
                    dict(
                        path='requirements.txt',
                        content="""\
# dummy
""",
                    ),
                    dict(
                        path='deploy.py',
                        content="""\
import json
import os
print "fakedeploy start"
print json.dumps(dict(cwd=os.getcwd()))
with file(FLAGPATH, "a") as f:
    f.write('xyzzy')
print "fakedeploy end"
""".replace('FLAGPATH', repr(flag)),
                    ),
                ],
            ),
        ],
    )
    # cause remote to have something new for us
    subprocess.check_call(args=[
        'git',
        '--git-dir={0}'.format(repo),
        'update-ref',
        'refs/remotes/origin/master',
        'HEAD',
    ], )
    subprocess.check_call(args=[
        'git',
        '--git-dir={0}'.format(repo),
        'symbolic-ref',
        'refs/remotes/origin/HEAD',
        'refs/remotes/origin/master',
    ], )
    out = StringIO()
    fake_stdout.provides('write').calls(out.write)
    assert not os.path.exists(flag)
    main(args=[
        'merge',
        '--repository',
        repo,
        '--temp',
        scratch,
    ], )
    got = out.getvalue().splitlines()
    eq(got, [])
    assert not os.path.exists(flag)
Exemplo n.º 5
0
def test_simple(fake_stdout, fake_stderr):
    tmp = maketemp()
    repo = os.path.join(tmp, 'repo')
    os.mkdir(repo)
    scratch = os.path.join(tmp, 'scratch')
    os.mkdir(scratch)
    flag = os.path.join(tmp, 'flag')
    subprocess.check_call(args=[
        'git',
        '--git-dir={0}'.format(repo),
        'init',
        '--quiet',
        '--bare',
    ], )
    fast_import(
        repo=repo,
        commits=[
            dict(
                message='Initial import.',
                committer='John Doe <*****@*****.**>',
                commit_time='1216235872 +0300',
                files=[
                    dict(
                        path='requirements.txt',
                        content="""\
# pip complains if this file is left empty, so say something we know
# is easily accessible
pip
""",
                    ),
                    dict(
                        path='deploy.py',
                        content="""\
import json
import os
print "fakedeploy start"
print json.dumps(dict(cwd=os.getcwd()))
with file(FLAGPATH, "w") as f:
    f.write('xyzzy')
print "fakedeploy end"
""".replace('FLAGPATH', repr(flag)),
                    ),
                ],
            ),
        ],
    )
    out = StringIO()
    fake_stdout.expects('write').calls(out.write)
    assert not os.path.exists(flag)
    main(args=[
        'deploy',
        '--repository',
        repo,
        '--temp',
        scratch,
    ], )
    assert os.path.exists(flag)
    with file(flag) as f:
        got = f.read()
    eq(got, 'xyzzy')
    got = out.getvalue().splitlines()
    eq(got[0], 'fakedeploy start')
    eq(got[2], 'fakedeploy end')
    eq(got[3:], [])
    got = json.loads(got[1])
    cwd = got.pop('cwd')
    (head, tail) = os.path.split(cwd)
    eq(head, scratch)
    assert re.match(r'^troops-[a-zA-Z0-9_]{6,}$', tail), \
        "Odd cwd for deploy: {path!r}".format(path=cwd)
    eq(got, {})
Exemplo n.º 6
0
def test_simple(fake_stdout, fake_stderr):
    tmp = maketemp()
    repo = os.path.join(tmp, 'repo')
    os.mkdir(repo)
    scratch = os.path.join(tmp, 'scratch')
    os.mkdir(scratch)
    flag = os.path.join(tmp, 'flag')
    subprocess.check_call(
        args=[
            'git',
            '--git-dir={0}'.format(repo),
            'init',
            '--quiet',
            '--bare',
            ],
        )
    fast_import(
        repo=repo,
        commits=[
            dict(
                message='Initial import.',
                committer='John Doe <*****@*****.**>',
                commit_time='1216235872 +0300',
                files=[
                    dict(
                        path='requirements.txt',
                        content="""\
# dummy
""",
                        ),
                    dict(
                        path='deploy.py',
                        content="""\
import json
import os
print "fakedeploy start"
print json.dumps(dict(cwd=os.getcwd()))
with file(FLAGPATH, "w") as f:
    f.write('xyzzy')
print "fakedeploy end"
""".replace('FLAGPATH', repr(flag)),
                        ),
                    ],
                ),
            ],
        )
    out = StringIO()
    fake_stdout.expects('write').calls(out.write)
    assert not os.path.exists(flag)
    main(
        args=[
            'deploy',
            '--repository', repo,
            '--temp', scratch,
            ],
        )
    assert os.path.exists(flag)
    with file(flag) as f:
        got = f.read()
    eq(got, 'xyzzy')
    got = out.getvalue().splitlines()
    eq(got[0], 'fakedeploy start')
    eq(got[2], 'fakedeploy end')
    eq(got[3:], [])
    got = json.loads(got[1])
    cwd = got.pop('cwd')
    (head, tail) = os.path.split(cwd)
    eq(head, scratch)
    assert re.match(r'^troops-[a-zA-Z0-9_]{6,}$', tail), \
        "Odd cwd for deploy: {path!r}".format(path=cwd)
    eq(got, {})