1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-01-12 16:56:15 +01:00

- added testcases for the rewritten Request class

This commit is contained in:
Marcus Huewe 2010-12-30 02:27:15 +01:00
parent b99a903873
commit 8c26c74620
8 changed files with 762 additions and 0 deletions

View File

@ -0,0 +1,104 @@
[general]
# URL to access API server, e.g. https://api.opensuse.org
# you also need a section [https://api.opensuse.org] with the credentials
apiurl = http://localhost
# Downloaded packages are cached here. Must be writable by you.
#packagecachedir = /var/tmp/osbuild-packagecache
# Wrapper to call build as root (sudo, su -, ...)
#su-wrapper = su -c
# rootdir to setup the chroot environment
# can contain %(repo)s, %(arch)s, %(project)s and %(package)s for replacement, e.g.
# /srv/oscbuild/%(repo)s-%(arch)s or
# /srv/oscbuild/%(repo)s-%(arch)s-%(project)s-%(package)s
#build-root = /var/tmp/build-root
# compile with N jobs (default: "getconf _NPROCESSORS_ONLN")
#build-jobs = N
# build-type to use - values can be (depending on the capabilities of the 'build' script)
# empty - chroot build
# kvm - kvm VM build (needs build-device, build-swap, build-memory)
# xen - xen VM build (needs build-device, build-swap, build-memory)
# experimental:
# qemu - qemu VM build
# lxc - lxc build
#build-type =
# build-device is the disk-image file to use as root for VM builds
# e.g. /var/tmp/FILE.root
#build-device = /var/tmp/FILE.root
# build-swap is the disk-image to use as swap for VM builds
# e.g. /var/tmp/FILE.swap
#build-swap = /var/tmp/FILE.swap
# build-memory is the amount of memory used in the VM
# value in MB - e.g. 512
#build-memory = 512
# build-vmdisk-rootsize is the size of the disk-image used as root in a VM build
# values in MB - e.g. 4096
#build-vmdisk-rootsize = 4096
# build-vmdisk-swapsize is the size of the disk-image used as swap in a VM build
# values in MB - e.g. 1024
#build-vmdisk-swapsize = 1024
# Numeric uid:gid to assign to the "abuild" user in the build-root
# or "caller" to use the current users uid:gid
# This is convenient when sharing the buildroot with ordinary userids
# on the host.
# This should not be 0
# build-uid =
# extra packages to install when building packages locally (osc build)
# this corresponds to osc build's -x option and can be overridden with that
# -x '' can also be given on the command line to override this setting, or
# you can have an empty setting here.
#extra-pkgs = vim gdb strace
# build platform is used if the platform argument is omitted to osc build
#build_repository = openSUSE_Factory
# default project for getpac or bco
#getpac_default_project = openSUSE:Factory
# alternate filesystem layout: have multiple subdirs, where colons were.
#checkout_no_colon = 0
# local files to ignore with status, addremove, ....
#exclude_glob = .osc CVS .svn .* _linkerror *~ #*# *.orig *.bak *.changes.*
# keep passwords in plaintext. If you see this comment, your osc
# already uses the encrypted password, and only keeps them in plain text
# for backwards compatibility. Default will change to 0 in future releases.
# You can remove the plaintext password without harm, if you do not need
# backwards compatibility.
#plaintext_passwd = 1
# limit the age of requests shown with 'osc req list'.
# this is a default only, can be overridden by 'osc req list -D NNN'
# Use 0 for unlimted.
#request_list_days = 0
# show info useful for debugging
#debug = 1
# show HTTP traffic useful for debugging
#http_debug = 1
# Skip signature verification of packages used for build.
#no_verify = 1
# jump into the debugger in case of errors
#post_mortem = 1
# print call traces in case of errors
#traceback = 1
# use KDE/Gnome/MacOS/Windows keyring for credentials if available
#use_keyring = 1
# check for unversioned/removed files before commit
#check_filelist = 1
# check for pending requests after executing an action (e.g. checkout, update, commit)
#check_for_request_on_action = 0
# what to do with the source package if the submitrequest has been accepted. If
# nothing is specified the API default is used
#submitrequest_on_accept_action = cleanup|update|noupdate
#review requests interactively (default: off)
#request_show_review = 1
# Directory with executables to validate sources, esp before committing
#source_validator_directory = /usr/lib/osc/source_validators
[http://localhost]
user = Admin
pass = opensuse
passx = QlpoOTFBWSZTWeTSblkAAAGBgAIBygAgADDACGNEHxaYXckU4UJDk0m5ZA==
# set aliases for this apiurl
# aliases = foo, bar
# email used in .changes, unless the one from osc meta prj <user> will be used
# email =
# additional headers to pass to a request, e.g. for special authentication
#http_headers = Host: foofoobar,
# User: mumblegack
# Force using of keyring for this API
#keyring = 1

View File

@ -0,0 +1,17 @@
<request id="42">
<action type="submit">
<source package="bar" project="foo" rev="1" />
<target package="bar" project="foobar" />
</action>
<action type="delete">
<target project="deleteme" />
</action>
<state name="accepted" when="2010-12-27T01:36:29" who="user1" />
<history name="new" when="2010-12-13T13:02:03" who="creator">
<comment>foobar</comment>
</history>
<title>title of the request</title>
<description>this is a
very long
description</description>
</request>

View File

@ -0,0 +1,19 @@
<request id="123">
<action type="submit">
<source package="abc" project="xyz" />
<options>
<sourceupdate>cleanup</sourceupdate>
<updatelink>1</updatelink>
</options>
</action>
<action type="add_role">
<target project="home:foo" />
<person name="bar" role="maintainer" />
<group name="groupxyz" role="reader" />
</action>
<state name="review" when="2010-12-27T01:36:29" who="abc" />
<review by_group="group1" state="new" when="2010-12-28T00:11:22" who="abc">
<comment>review start</comment>
</review>
<history name="new" when="2010-12-11T00:00:00" who="creator" />
</request>

View File

@ -0,0 +1,36 @@
<request id="62">
<action type="set_bugowner">
<target project="foo" />
<person name="buguser" />
</action>
<action type="add_role">
<target project="foobar" />
<person name="xyz" role="maintainer" />
<group name="group1" role="reader" />
</action>
<action type="add_role">
<target project="foo" package="bar" />
<person name="abc" role="reviewer" />
</action>
<action type="change_devel">
<source project="devprj" package="devpkg" />
<target project="foo" package="bar" />
</action>
<action type="submit">
<source project="srcprj" package="srcpackage" />
<target project="tgtprj" package="tgtpackage" />
</action>
<action type="submit">
<source project="foo" package="bar" />
<target project="baz" />
</action>
<action type="delete">
<target project="deleteme" />
</action>
<action type="delete">
<target project="foo" package="bar" />
</action>
<state name="new" when="2010-12-29T14:57:25" who="Admin">
<comment></comment>
</state>
</request>

View File

@ -0,0 +1,14 @@
<request id="21">
<action type="set_bugowner">
<target project="foo" />
<person name="buguser" />
</action>
<state name="accepted" when="2010-12-29T16:37:45" who="foobar" />
<history name="new" when="2010-12-28T16:37:45" who="user" />
<history name="review" when="2010-12-28T18:37:45" who="foobar" />
<description>This is
a simple request with a lot of ... ... text and other stuff. This request also contains a
description. This is useful to
describe the request. blabla
blabla</description>
</request>

View File

@ -0,0 +1,30 @@
<request id="123">
<action type="submit">
<source package="abc" project="xyz" />
<target project="foo" />
<options>
<sourceupdate>cleanup</sourceupdate>
<updatelink>1</updatelink>
</options>
</action>
<action type="add_role">
<target project="home:foo" />
<person name="bar" role="maintainer" />
<group name="groupxyz" role="reader" />
</action>
<state name="review" when="2010-12-27T01:36:29" who="abc">
<comment>currently in review</comment>
</state>
<review by_group="group1" state="new" when="2010-12-28T00:11:22" who="abc">
<comment>review start</comment>
</review>
<review by_group="group1" state="accepted" when="2010-12-29T00:11:22" who="abc">
<comment>accepted</comment>
</review>
<history name="new" when="2010-12-11T00:00:00" who="creator" />
<history name="revoked" when="2010-12-12T00:00:00" who="creator" />
<description>just a samll description
in order to describe this
request - blablabla
test.</description>
</request>

View File

@ -11,6 +11,7 @@ import test_commit
import test_repairwc
import test_package_status
import test_project_status
import test_request
suite = unittest.TestSuite()
suite.addTests(test_addfiles.suite())
@ -24,5 +25,6 @@ suite.addTests(test_commit.suite())
suite.addTests(test_repairwc.suite())
suite.addTests(test_package_status.suite())
suite.addTests(test_project_status.suite())
suite.addTests(test_request.suite())
result = unittest.TextTestRunner(verbosity=1).run(suite)
sys.exit(not result.wasSuccessful())

540
tests/test_request.py Normal file
View File

@ -0,0 +1,540 @@
import osc.core
import osc.oscerr
import os
from common import OscTestCase
FIXTURES_DIR = os.path.join(os.getcwd(), 'request_fixtures')
def suite():
import unittest
return unittest.makeSuite(TestRequest)
class TestRequest(OscTestCase):
def _get_fixtures_dir(self):
return FIXTURES_DIR
def setUp(self):
OscTestCase.setUp(self, copytree=False)
def test_createsr(self):
"""create a simple submitrequest"""
r = osc.core.Request()
r.add_action('submit', src_project='foo', src_package='bar', src_rev='42',
tgt_project='foobar', tgt_package='bar')
self.assertEqual(r.actions[0].type, 'submit')
self.assertEqual(r.actions[0].src_project, 'foo')
self.assertEqual(r.actions[0].src_package, 'bar')
self.assertEqual(r.actions[0].src_rev, '42')
self.assertEqual(r.actions[0].tgt_project, 'foobar')
self.assertEqual(r.actions[0].tgt_package, 'bar')
self.assertTrue(r.actions[0].opt_sourceupdate is None)
self.assertTrue(r.actions[0].opt_updatelink is None)
self.assertTrue(len(r.statehistory) == 0)
self.assertTrue(len(r.reviews) == 0)
self.assertRaises(AttributeError, getattr, r.actions[0], 'doesnotexist')
exp = """<request>
<action type="submit">
<source package="bar" project="foo" rev="42" />
<target package="bar" project="foobar" />
</action>
</request>"""
self.assertEqual(exp, r.to_str())
def test_createsr_with_option(self):
"""create a submitrequest with option"""
"""create a simple submitrequest"""
r = osc.core.Request()
r.add_action('submit', src_project='foo', src_package='bar',
tgt_project='foobar', tgt_package='bar', opt_sourceupdate='cleanup', opt_updatelink='1')
self.assertEqual(r.actions[0].type, 'submit')
self.assertEqual(r.actions[0].src_project, 'foo')
self.assertEqual(r.actions[0].src_package, 'bar')
self.assertEqual(r.actions[0].tgt_project, 'foobar')
self.assertEqual(r.actions[0].tgt_package, 'bar')
self.assertEqual(r.actions[0].opt_sourceupdate, 'cleanup')
self.assertEqual(r.actions[0].opt_updatelink, '1')
self.assertTrue(r.actions[0].src_rev is None)
self.assertTrue(len(r.statehistory) == 0)
self.assertTrue(len(r.reviews) == 0)
self.assertRaises(AttributeError, getattr, r.actions[0], 'doesnotexist')
exp = """<request>
<action type="submit">
<source package="bar" project="foo" />
<target package="bar" project="foobar" />
<options>
<sourceupdate>cleanup</sourceupdate>
<updatelink>1</updatelink>
</options>
</action>
</request>"""
self.assertEqual(exp, r.to_str())
def test_createsr_missing_tgt_package(self):
"""create a submitrequest with missing target package"""
r = osc.core.Request()
r.add_action('submit', src_project='foo', src_package='bar',
tgt_project='foobar')
self.assertEqual(r.actions[0].type, 'submit')
self.assertEqual(r.actions[0].src_project, 'foo')
self.assertEqual(r.actions[0].src_package, 'bar')
self.assertEqual(r.actions[0].tgt_project, 'foobar')
self.assertTrue(len(r.statehistory) == 0)
self.assertTrue(len(r.reviews) == 0)
self.assertTrue(r.actions[0].tgt_package is None)
self.assertRaises(AttributeError, getattr, r.actions[0], 'doesnotexist')
exp = """<request>
<action type="submit">
<source package="bar" project="foo" />
<target project="foobar" />
</action>
</request>"""
self.assertEqual(exp, r.to_str())
def test_createsr_invalid_argument(self):
"""create a submitrequest with invalid action argument"""
r = osc.core.Request()
self.assertRaises(osc.oscerr.WrongArgs, r.add_action, 'submit', src_project='foo', src_invalid='bar')
def test_create_request_invalid_type(self):
"""create a request with an invalid action type"""
r = osc.core.Request()
self.assertRaises(osc.oscerr.WrongArgs, r.add_action, 'invalid', foo='bar')
def test_create_add_role_person(self):
"""create an add_role request (person element)"""
r = osc.core.Request()
r.add_action('add_role', tgt_project='foo', tgt_package='bar', person_name='user', person_role='reader')
self.assertEqual(r.actions[0].type, 'add_role')
self.assertEqual(r.actions[0].tgt_project, 'foo')
self.assertEqual(r.actions[0].tgt_package, 'bar')
self.assertEqual(r.actions[0].person_name, 'user')
self.assertEqual(r.actions[0].person_role, 'reader')
self.assertTrue(r.actions[0].group_name is None)
self.assertTrue(r.actions[0].group_role is None)
exp = """<request>
<action type="add_role">
<target package="bar" project="foo" />
<person name="user" role="reader" />
</action>
</request>"""
self.assertEqual(exp, r.to_str())
def test_create_add_role_group(self):
"""create an add_role request (group element)"""
r = osc.core.Request()
r.add_action('add_role', tgt_project='foo', tgt_package='bar', group_name='group', group_role='reviewer')
self.assertEqual(r.actions[0].type, 'add_role')
self.assertEqual(r.actions[0].tgt_project, 'foo')
self.assertEqual(r.actions[0].tgt_package, 'bar')
self.assertEqual(r.actions[0].group_name, 'group')
self.assertEqual(r.actions[0].group_role, 'reviewer')
self.assertTrue(r.actions[0].person_name is None)
self.assertTrue(r.actions[0].person_role is None)
self.assertTrue(len(r.statehistory) == 0)
self.assertTrue(len(r.reviews) == 0)
exp = """<request>
<action type="add_role">
<target package="bar" project="foo" />
<group name="group" role="reviewer" />
</action>
</request>"""
self.assertEqual(exp, r.to_str())
def test_create_add_role_person_group(self):
"""create an add_role request (person+group element)"""
r = osc.core.Request()
r.add_action('add_role', tgt_project='foo', tgt_package='bar', person_name='user', person_role='reader',
group_name='group', group_role='reviewer')
self.assertEqual(r.actions[0].type, 'add_role')
self.assertEqual(r.actions[0].tgt_project, 'foo')
self.assertEqual(r.actions[0].tgt_package, 'bar')
self.assertEqual(r.actions[0].person_name, 'user')
self.assertEqual(r.actions[0].person_role, 'reader')
self.assertEqual(r.actions[0].group_name, 'group')
self.assertEqual(r.actions[0].group_role, 'reviewer')
self.assertTrue(len(r.statehistory) == 0)
self.assertTrue(len(r.reviews) == 0)
exp = """<request>
<action type="add_role">
<target package="bar" project="foo" />
<person name="user" role="reader" />
<group name="group" role="reviewer" />
</action>
</request>"""
self.assertEqual(exp, r.to_str())
def test_create_set_bugowner_project(self):
"""create a set_bugowner request for a project"""
r = osc.core.Request()
r.add_action('set_bugowner', tgt_project='foobar', person_name='buguser')
self.assertEqual(r.actions[0].type, 'set_bugowner')
self.assertEqual(r.actions[0].tgt_project, 'foobar')
self.assertEqual(r.actions[0].person_name, 'buguser')
self.assertTrue(r.actions[0].tgt_package is None)
self.assertTrue(len(r.statehistory) == 0)
self.assertTrue(len(r.reviews) == 0)
exp = """<request>
<action type="set_bugowner">
<target project="foobar" />
<person name="buguser" />
</action>
</request>"""
self.assertEqual(exp, r.to_str())
def test_create_set_bugowner_package(self):
"""create a set_bugowner request for a package"""
r = osc.core.Request()
r.add_action('set_bugowner', tgt_project='foobar', tgt_package='baz', person_name='buguser')
self.assertEqual(r.actions[0].type, 'set_bugowner')
self.assertEqual(r.actions[0].tgt_project, 'foobar')
self.assertEqual(r.actions[0].tgt_package, 'baz')
self.assertEqual(r.actions[0].person_name, 'buguser')
self.assertTrue(len(r.statehistory) == 0)
self.assertTrue(len(r.reviews) == 0)
exp = """<request>
<action type="set_bugowner">
<target package="baz" project="foobar" />
<person name="buguser" />
</action>
</request>"""
self.assertEqual(exp, r.to_str())
def test_create_delete_project(self):
"""create a delete request for a project"""
r = osc.core.Request()
r.add_action('delete', tgt_project='foo')
self.assertEqual(r.actions[0].type, 'delete')
self.assertEqual(r.actions[0].tgt_project, 'foo')
self.assertTrue(r.actions[0].tgt_package is None)
self.assertTrue(len(r.statehistory) == 0)
self.assertTrue(len(r.reviews) == 0)
exp = """<request>
<action type="delete">
<target project="foo" />
</action>
</request>"""
self.assertEqual(exp, r.to_str())
def test_create_delete_package(self):
"""create a delete request for a package"""
r = osc.core.Request()
r.add_action('delete', tgt_project='foo', tgt_package='deleteme')
self.assertEqual(r.actions[0].type, 'delete')
self.assertEqual(r.actions[0].tgt_project, 'foo')
self.assertEqual(r.actions[0].tgt_package, 'deleteme')
self.assertTrue(len(r.statehistory) == 0)
self.assertTrue(len(r.reviews) == 0)
exp = """<request>
<action type="delete">
<target package="deleteme" project="foo" />
</action>
</request>"""
self.assertEqual(exp, r.to_str())
def test_create_change_devel(self):
"""create a change devel request"""
r = osc.core.Request()
r.add_action('change_devel', src_project='foo', src_package='bar', tgt_project='devprj', tgt_package='devpkg')
self.assertEqual(r.actions[0].type, 'change_devel')
self.assertEqual(r.actions[0].src_project, 'foo')
self.assertEqual(r.actions[0].src_package, 'bar')
self.assertEqual(r.actions[0].tgt_project, 'devprj')
self.assertEqual(r.actions[0].tgt_package, 'devpkg')
self.assertTrue(len(r.statehistory) == 0)
self.assertTrue(len(r.reviews) == 0)
exp = """<request>
<action type="change_devel">
<source package="bar" project="foo" />
<target package="devpkg" project="devprj" />
</action>
</request>"""
self.assertEqual(exp, r.to_str())
def test_action_from_xml1(self):
"""create action from xml"""
from xml.etree import cElementTree as ET
xml = """<action type="add_role">
<target package="bar" project="foo" />
<person name="user" role="reader" />
<group name="group" role="reviewer" />
</action>"""
action = osc.core.Action.from_xml(ET.fromstring(xml))
self.assertEqual(action.type, 'add_role')
self.assertEqual(action.tgt_project, 'foo')
self.assertEqual(action.tgt_package, 'bar')
self.assertEqual(action.person_name, 'user')
self.assertEqual(action.person_role, 'reader')
self.assertEqual(action.group_name, 'group')
self.assertEqual(action.group_role, 'reviewer')
self.assertEqual(xml, action.to_str())
def test_action_from_xml2(self):
"""create action from xml"""
from xml.etree import cElementTree as ET
xml = """<action type="submit">
<source package="bar" project="foo" />
<target package="bar" project="foobar" />
<options>
<sourceupdate>cleanup</sourceupdate>
<updatelink>1</updatelink>
</options>
</action>"""
action = osc.core.Action.from_xml(ET.fromstring(xml))
self.assertEqual(action.type, 'submit')
self.assertEqual(action.src_project, 'foo')
self.assertEqual(action.src_package, 'bar')
self.assertEqual(action.tgt_project, 'foobar')
self.assertEqual(action.tgt_package, 'bar')
self.assertEqual(action.opt_sourceupdate, 'cleanup')
self.assertEqual(action.opt_updatelink, '1')
self.assertTrue(action.src_rev is None)
self.assertEqual(xml, action.to_str())
def test_action_from_xml_unknown_type(self):
"""try to create action from xml with unknown type"""
from xml.etree import cElementTree as ET
xml = '<action type="foo"><source package="bar" project="foo" /></action>'
self.assertRaises(osc.oscerr.WrongArgs, osc.core.Action.from_xml, ET.fromstring(xml))
def test_read_request1(self):
"""read in a request"""
from xml.etree import cElementTree as ET
xml = open(os.path.join(self._get_fixtures_dir(), 'test_read_request1.xml'), 'r').read().strip()
r = osc.core.Request()
r.read(ET.fromstring(xml))
self.assertEqual(r.reqid, '42')
self.assertEqual(r.actions[0].type, 'submit')
self.assertEqual(r.actions[0].src_project, 'foo')
self.assertEqual(r.actions[0].src_package, 'bar')
self.assertEqual(r.actions[0].src_rev, '1')
self.assertEqual(r.actions[0].tgt_project, 'foobar')
self.assertEqual(r.actions[0].tgt_package, 'bar')
self.assertTrue(r.actions[0].opt_sourceupdate is None)
self.assertTrue(r.actions[0].opt_updatelink is None)
self.assertEqual(r.actions[1].type, 'delete')
self.assertEqual(r.actions[1].tgt_project, 'deleteme')
self.assertTrue(r.actions[1].tgt_package is None)
self.assertEqual(r.state.name, 'accepted')
self.assertEqual(r.state.when, '2010-12-27T01:36:29')
self.assertEqual(r.state.who, 'user1')
self.assertEqual(r.state.comment, '')
self.assertEqual(r.statehistory[0].name, 'new')
self.assertEqual(r.statehistory[0].when, '2010-12-13T13:02:03')
self.assertEqual(r.statehistory[0].who, 'creator')
self.assertEqual(r.statehistory[0].comment, 'foobar')
self.assertEqual(r.title, 'title of the request')
self.assertEqual(r.description, 'this is a\nvery long\ndescription')
self.assertTrue(len(r.statehistory) == 1)
self.assertTrue(len(r.reviews) == 0)
self.assertEqual(xml, r.to_str())
def test_read_request2(self):
"""read in a request (with reviews)"""
from xml.etree import cElementTree as ET
xml = open(os.path.join(self._get_fixtures_dir(), 'test_read_request2.xml'), 'r').read().strip()
r = osc.core.Request()
r.read(ET.fromstring(xml))
self.assertEqual(r.reqid, '123')
self.assertEqual(r.actions[0].type, 'submit')
self.assertEqual(r.actions[0].src_project, 'xyz')
self.assertEqual(r.actions[0].src_package, 'abc')
self.assertTrue(r.actions[0].src_rev is None)
self.assertEqual(r.actions[0].opt_sourceupdate, 'cleanup')
self.assertEqual(r.actions[0].opt_updatelink, '1')
self.assertEqual(r.actions[1].type, 'add_role')
self.assertEqual(r.actions[1].tgt_project, 'home:foo')
self.assertEqual(r.actions[1].person_name, 'bar')
self.assertEqual(r.actions[1].person_role, 'maintainer')
self.assertEqual(r.actions[1].group_name, 'groupxyz')
self.assertEqual(r.actions[1].group_role, 'reader')
self.assertTrue(r.actions[1].tgt_package is None)
self.assertEqual(r.state.name, 'review')
self.assertEqual(r.state.when, '2010-12-27T01:36:29')
self.assertEqual(r.state.who, 'abc')
self.assertEqual(r.state.comment, '')
self.assertEqual(r.reviews[0].state, 'new')
self.assertEqual(r.reviews[0].by_group, 'group1')
self.assertEqual(r.reviews[0].when, '2010-12-28T00:11:22')
self.assertEqual(r.reviews[0].who, 'abc')
self.assertEqual(r.reviews[0].comment, 'review start')
self.assertTrue(r.reviews[0].by_user is None)
self.assertEqual(r.statehistory[0].name, 'new')
self.assertEqual(r.statehistory[0].when, '2010-12-11T00:00:00')
self.assertEqual(r.statehistory[0].who, 'creator')
self.assertEqual(r.statehistory[0].comment, '')
self.assertEqual(r.get_creator(), 'creator')
self.assertTrue(len(r.statehistory) == 1)
self.assertTrue(len(r.reviews) == 1)
self.assertEqual(xml, r.to_str())
def test_read_request3(self):
"""read in a request (with an "empty" comment+description)"""
from xml.etree import cElementTree as ET
xml = """<request id="2">
<action type="set_bugowner">
<target project="foo" />
<person name="buguser" />
</action>
<state name="new" when="2010-12-28T12:36:29" who="xyz">
<comment></comment>
</state>
<description></description>
</request>"""
r = osc.core.Request()
r.read(ET.fromstring(xml))
self.assertEqual(r.reqid, '2')
self.assertEqual(r.actions[0].type, 'set_bugowner')
self.assertEqual(r.actions[0].tgt_project, 'foo')
self.assertEqual(r.actions[0].person_name, 'buguser')
self.assertEqual(r.state.name, 'new')
self.assertEqual(r.state.when, '2010-12-28T12:36:29')
self.assertEqual(r.state.who, 'xyz')
self.assertEqual(r.state.comment, '')
self.assertEqual(r.description, '')
self.assertTrue(len(r.statehistory) == 0)
self.assertTrue(len(r.reviews) == 0)
self.assertEqual(r.get_creator(), 'xyz')
exp = """<request id="2">
<action type="set_bugowner">
<target project="foo" />
<person name="buguser" />
</action>
<state name="new" when="2010-12-28T12:36:29" who="xyz" />
</request>"""
self.assertEqual(exp, r.to_str())
def test_request_list_view1(self):
"""test the list_view method"""
from xml.etree import cElementTree as ET
xml = open(os.path.join(self._get_fixtures_dir(), 'test_request_list_view1.xml'), 'r').read().strip()
exp = """\
62 State:new By:Admin When:2010-12-29T14:57:25
set_bugowner: buguser foo
add_role: person: xyz as maintainer, group: group1 as reader foobar
add_role: person: abc as reviewer foo/bar
change_devel: foo/bar developed in devprj/devpkg
submit: srcprj/srcpackage -> tgtprj/tgtpackage
submit: foo/bar -> baz
delete: deleteme
delete: foo/bar"""
r = osc.core.Request()
r.read(ET.fromstring(xml))
self.assertEqual(exp, r.list_view())
def test_request_list_view2(self):
"""test the list_view method (with history elements and description)"""
from xml.etree import cElementTree as ET
xml = open(os.path.join(self._get_fixtures_dir(), 'test_request_list_view2.xml'), 'r').read().strip()
r = osc.core.Request()
r.read(ET.fromstring(xml))
exp = """\
21 State:accepted By:foobar When:2010-12-29T16:37:45
set_bugowner: buguser foo
From: new(user) -> review(foobar)
Descr: This is a simple request with a lot of ... ... text and other
stuff. This request also contains a description. This is useful
to describe the request. blabla blabla"""
self.assertEqual(exp, r.list_view())
def test_request_str1(self):
from xml.etree import cElementTree as ET
"""test the __str__ method"""
xml = open(os.path.join(self._get_fixtures_dir(), 'test_request_str1.xml'), 'r').read().strip()
r = osc.core.Request()
r = osc.core.Request()
r.read(ET.fromstring(xml))
self.assertEqual(r.get_creator(), 'creator')
exp = """\
Request: #123
submit: xyz/abc(cleanup) -> foo
add_role: person: bar as maintainer, group: groupxyz as reader home:foo
Message:
just a samll description
in order to describe this
request - blablabla
test.
State: review 2010-12-27T01:36:29 abc
Comment: currently in review
Review: accepted <no by_user> group1 2010-12-29T00:11:22 abc accepted
new <no by_user> group1 2010-12-28T00:11:22 abc review start
History: revoked 2010-12-12T00:00:00 creator
new 2010-12-11T00:00:00 creator"""
self.assertEqual(exp, str(r))
def test_request_str2(self):
"""test the __str__ method"""
from xml.etree import cElementTree as ET
xml = """\
<request id="98765">
<action type="change_devel">
<source project="devprj" package="devpkg" />
<target project="foo" package="bar" />
</action>
<action type="delete">
<target project="deleteme" />
</action>
<state name="new" when="2010-12-29T00:11:22" who="creator" />
</request>"""
r = osc.core.Request()
r.read(ET.fromstring(xml))
self.assertEqual(r.get_creator(), 'creator')
exp = """\
Request: #98765
change_devel: foo/bar developed in devprj/devpkg
delete: deleteme
Message:
<no message>
State: new 2010-12-29T00:11:22 creator
Comment: <no comment>"""
self.assertEqual(exp, str(r))
def test_legacy_request(self):
"""load old-style submitrequest"""
from xml.etree import cElementTree as ET
xml = """\
<request id="1234" type="submit">
<submit>
<source package="baz" project="foobar" />
<target package="baz" project="foo" />
</submit>
<state name="new" when="2010-12-30T02:11:22" who="olduser" />
</request>"""
r = osc.core.Request()
r.read(ET.fromstring(xml))
self.assertEqual(r.reqid, '1234')
self.assertEqual(r.actions[0].type, 'submit')
self.assertEqual(r.actions[0].src_project, 'foobar')
self.assertEqual(r.actions[0].src_package, 'baz')
self.assertEqual(r.actions[0].tgt_project, 'foo')
self.assertEqual(r.actions[0].tgt_package, 'baz')
self.assertTrue(r.actions[0].opt_sourceupdate is None)
self.assertTrue(r.actions[0].opt_updatelink is None)
self.assertEqual(r.state.name, 'new')
self.assertEqual(r.state.when, '2010-12-30T02:11:22')
self.assertEqual(r.state.who, 'olduser')
self.assertEqual(r.state.comment, '')
self.assertEqual(r.get_creator(), 'olduser')
exp = """\
<request id="1234">
<action type="submit">
<source package="baz" project="foobar" />
<target package="baz" project="foo" />
</action>
<state name="new" when="2010-12-30T02:11:22" who="olduser" />
</request>"""
self.assertEqual(exp, r.to_str())
if __name__ == '__main__':
import unittest
unittest.main()