forked from umeshrege/python-bugzilla
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_misc.py
More file actions
160 lines (129 loc) · 4.57 KB
/
Copy pathtest_misc.py
File metadata and controls
160 lines (129 loc) · 4.57 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#
# Copyright Red Hat, Inc. 2012
#
# This work is licensed under the terms of the GNU GPL, version 2 or later.
# See the COPYING file in the top-level directory.
#
"""
Unit tests for building query strings with bin/bugzilla
"""
from __future__ import print_function
import os
import tempfile
import unittest
import pytest
import bugzilla
import tests
class MiscCLI(unittest.TestCase):
"""
Test miscellaneous CLI bits to get build out our code coverage
"""
maxDiff = None
def testHelp(self):
out = tests.clicomm("bugzilla --help", None)
assert len(out.splitlines()) > 18
def testCmdHelp(self):
out = tests.clicomm("bugzilla query --help", None)
assert len(out.splitlines()) > 40
def testVersion(self):
out = tests.clicomm("bugzilla --version", None)
assert len(out.splitlines()) >= 2
def testPositionalArgs(self):
# Make sure cli correctly rejects ambiguous positional args
out = tests.clicomm("bugzilla login --xbadarg foo",
None, expectfail=True)
assert "unrecognized arguments: --xbadarg" in out
out = tests.clicomm("bugzilla modify 123456 --foobar --status NEW",
None, expectfail=True)
assert "unrecognized arguments: --foobar" in out
class MiscAPI(unittest.TestCase):
"""
Test miscellaneous API bits
"""
def testUserAgent(self):
b3 = tests.make_bz("3.0.0")
assert "python-bugzilla" in b3.user_agent
def testCookies(self):
cookiesbad = os.path.join(os.getcwd(), "tests/data/cookies-bad.txt")
cookieslwp = os.path.join(os.getcwd(), "tests/data/cookies-lwp.txt")
cookiesmoz = os.path.join(os.getcwd(), "tests/data/cookies-moz.txt")
# We used to convert LWP cookies, but it shouldn't matter anymore,
# so verify they fail at least
with pytest.raises(bugzilla.BugzillaError):
tests.make_bz("3.0.0", cookiefile=cookieslwp)
with pytest.raises(bugzilla.BugzillaError):
tests.make_bz("3.0.0", cookiefile=cookiesbad)
# Mozilla should 'just work'
tests.make_bz("3.0.0", cookiefile=cookiesmoz)
def test_readconfig(self):
# Testing for bugzillarc handling
bzapi = tests.make_bz("4.4.0", rhbz=True)
bzapi.url = "foo.example.com"
temp = tempfile.NamedTemporaryFile(mode="w")
content = """
[example.com]
foo=1
user=test1
password=test2"""
temp.write(content)
temp.flush()
bzapi.readconfig(temp.name)
assert bzapi.user == "test1"
assert bzapi.password == "test2"
assert bzapi.api_key is None
content = """
[foo.example.com]
user=test3
password=test4
api_key=123abc
"""
temp.write(content)
temp.flush()
bzapi.readconfig(temp.name)
assert bzapi.user == "test3"
assert bzapi.password == "test4"
assert bzapi.api_key == "123abc"
bzapi.url = "bugzilla.redhat.com"
bzapi.user = None
bzapi.password = None
bzapi.api_key = None
bzapi.readconfig(temp.name)
assert bzapi.user is None
assert bzapi.password is None
assert bzapi.api_key is None
def testPostTranslation(self):
def _testPostCompare(bz, indict, outexpect):
outdict = indict.copy()
bz.post_translation({}, outdict)
assert outdict == outexpect
# Make sure multiple calls don't change anything
bz.post_translation({}, outdict)
assert outdict == outexpect
bug3 = tests.make_bz("3.4.0")
rhbz = tests.make_bz("4.4.0", rhbz=True)
test1 = {
"component": ["comp1"],
"version": ["ver1", "ver2"],
'flags': [{
'is_active': 1,
'name': 'qe_test_coverage',
'setter': 'pm-rhel@redhat.com',
'status': '?',
}, {
'is_active': 1,
'name': 'rhel-6.4.0',
'setter': 'pm-rhel@redhat.com',
'status': '+',
}],
'alias': ["FOO", "BAR"],
'blocks': [782183, 840699, 923128],
'keywords': ['Security'],
'groups': ['redhat'],
}
out_simple = test1.copy()
out_simple["components"] = out_simple["component"]
out_simple["component"] = out_simple["components"][0]
out_simple["versions"] = out_simple["version"]
out_simple["version"] = out_simple["versions"][0]
_testPostCompare(bug3, test1, test1)
_testPostCompare(rhbz, test1, out_simple)