1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
# This work is licensed under the GNU GPLv2 or later.
# See the COPYING file in the top-level directory.
import os
import tests
import tests.mockbackend
import tests.utils
##################################
# 'bugzilla attach' mock testing #
##################################
def test_attach(run_cli):
attachfile = os.path.dirname(__file__) + "/data/bz-attach-get1.txt"
attachcontent = open(attachfile).read()
# Hit error when no ID specified
fakebz = tests.mockbackend.make_bz()
out = run_cli("bugzilla attach", fakebz, expectfail=True)
assert "ID must be specified" in out
# Hit error when using tty and no --file specified
out = run_cli("bugzilla attach 123456", fakebz, expectfail=True)
assert "--file must be specified" in out
# Hit error when using stdin, but no --desc
out = run_cli("bugzilla attach 123456", fakebz, expectfail=True,
stdin=attachcontent)
assert "--description must be specified" in out
# Basic CLI attach
cmd = "bugzilla attach 123456 --file=%s " % attachfile
cmd += "--type text/x-patch --private "
cmd += "--comment 'some comment to go with it'"
fakebz = tests.mockbackend.make_bz(
bug_attachment_create_args="data/mockargs/test_attach1.txt",
bug_attachment_create_return={'ids': [1557949]})
out = run_cli(cmd, fakebz)
assert "Created attachment 1557949 on bug 123456" in out
# Attach from stdin
cmd = "bugzilla attach 123456 --file=fake-file-name.txt "
cmd += "--description 'Some attachment description' "
fakebz = tests.mockbackend.make_bz(
bug_attachment_create_args="data/mockargs/test_attach2.txt",
bug_attachment_create_return={'ids': [1557949]})
out = run_cli(cmd, fakebz, stdin=attachcontent)
assert "Created attachment 1557949 on bug 123456" in out
# Test --field passthrough
cmd = "bugzilla attach 123456 --file=%s " % attachfile
cmd += "--field=is_obsolete=1 "
cmd += "--field-json "
cmd += ('\'{"flags": [{"name": "review"'
', "requestee": "crobinso@redhat.com", "status": "-"}]}\'')
fakebz = tests.mockbackend.make_bz(
bug_attachment_create_args="data/mockargs/test_attach3.txt",
bug_attachment_create_return={'ids': [1557949]})
out = run_cli(cmd, fakebz)
assert "Created attachment 1557949 on bug 123456" in out
def _test_attach_get(run_cli):
# Hit error when using ids with --get*
fakebz = tests.mockbackend.make_bz()
out = run_cli("bugzilla attach 123456 --getall 123456",
fakebz, expectfail=True)
assert "not used for" in out
# Basic --get ATTID usage
filename = "Klíč memorial test file.txt"
cmd = "bugzilla attach --get 112233"
fakebz = tests.mockbackend.make_bz(
bug_attachment_get_args="data/mockargs/test_attach_get1.txt",
bug_attachment_get_return="data/mockreturn/test_attach_get1.txt")
out = run_cli(cmd, fakebz)
assert filename in out
# Basic --getall with --ignore-obsolete
cmd = "bugzilla attach --getall 663674 --ignore-obsolete"
fakebz = tests.mockbackend.make_bz(
bug_attachment_get_all_args="data/mockargs/test_attach_get2.txt",
bug_attachment_get_all_return="data/mockreturn/test_attach_get2.txt")
out = run_cli(cmd, fakebz)
os.system("ls %s" % os.getcwd())
filename += ".1"
assert filename in out
assert "bugzilla-filename" in out
def test_attach_get(run_cli):
import tempfile
import shutil
tmpdir = tempfile.mkdtemp(dir=os.getcwd())
origcwd = os.getcwd()
os.chdir(tmpdir)
try:
_test_attach_get(run_cli)
finally:
os.chdir(origcwd)
shutil.rmtree(tmpdir)
|