Skip to content

Commit 1d98afa

Browse files
committed
tests: split apart test_cli_commands into one file per command
Signed-off-by: Cole Robinson <[email protected]>
1 parent c10a673 commit 1d98afa

7 files changed

Lines changed: 439 additions & 407 deletions

File tree

tests/test_cli_attach.py

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

0 commit comments

Comments
 (0)