2020-06-02 22:22:17 +02:00
|
|
|
try:
|
|
|
|
# Works up to Python 3.8, needed for Python < 3.3 (inc 2.7)
|
|
|
|
from xml.etree import cElementTree as ET
|
|
|
|
except ImportError:
|
|
|
|
# will import a fast implementation from 3.3 onwards, needed
|
|
|
|
# for 3.9+
|
|
|
|
from xml.etree import ElementTree as ET
|
|
|
|
|
2010-12-30 02:27:15 +01:00
|
|
|
import osc.core
|
|
|
|
import osc.oscerr
|
|
|
|
import os
|
2022-02-17 13:28:47 +01:00
|
|
|
from .common import OscTestCase
|
2010-12-30 02:27:15 +01:00
|
|
|
|
2022-02-17 13:28:47 +01:00
|
|
|
FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'request_fixtures')
|
2010-12-30 02:27:15 +01:00
|
|
|
|
|
|
|
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>"""
|
tests: Ignore the ordering of attributes in XML documents
Old xml.etree.cElementTree versions (python2) reorder the attributes
while recent xml.etree.cElementTree versions (python3) keep the
document order.
Example:
python3:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
b'<foo y="foo" x="bar" />'
>>>
python2:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
'<foo x="bar" y="foo" />'
>>>
So far, the testsuite compared two serialized XML documents via a simple
string comparison. For instance via,
self.assertEqual(actual_serialized_xml, expected_serialized_xml) where
the expected_serialized_xml is, for instance, a hardcoded str. Obviously,
this would only work for python2 or python3.
In order to support both python versions, we first parse both XML
documents and then compare the corresponding trees (this is OK because
we do not care about comments etc.).
A related issue is the way how the testsuite compares data that is "send"
to the API. So far, this was a plain bytes comparison. Again, this won't
work in case of XML documents (see above). Moreover, we have currently
no notion to "indicate" that the transmitted data is an XML document.
As a workaround, we keep the plain bytes comparison and in case it fails,
we try an xml comparison (see above) as a last resort. Strictly speaking,
this is "wrong" (there might be cases (in the future) where we want to
ensure that the transmitted XML data is bit identical to a fixture file)
but a reasonable comprise for now.
Fixes: #751 ("[python3.8] Testsuite fails")
2020-06-03 21:06:26 +02:00
|
|
|
self.assertXMLEqual(exp, r.to_str())
|
2010-12-30 02:27:15 +01:00
|
|
|
|
|
|
|
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>"""
|
tests: Ignore the ordering of attributes in XML documents
Old xml.etree.cElementTree versions (python2) reorder the attributes
while recent xml.etree.cElementTree versions (python3) keep the
document order.
Example:
python3:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
b'<foo y="foo" x="bar" />'
>>>
python2:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
'<foo x="bar" y="foo" />'
>>>
So far, the testsuite compared two serialized XML documents via a simple
string comparison. For instance via,
self.assertEqual(actual_serialized_xml, expected_serialized_xml) where
the expected_serialized_xml is, for instance, a hardcoded str. Obviously,
this would only work for python2 or python3.
In order to support both python versions, we first parse both XML
documents and then compare the corresponding trees (this is OK because
we do not care about comments etc.).
A related issue is the way how the testsuite compares data that is "send"
to the API. So far, this was a plain bytes comparison. Again, this won't
work in case of XML documents (see above). Moreover, we have currently
no notion to "indicate" that the transmitted data is an XML document.
As a workaround, we keep the plain bytes comparison and in case it fails,
we try an xml comparison (see above) as a last resort. Strictly speaking,
this is "wrong" (there might be cases (in the future) where we want to
ensure that the transmitted XML data is bit identical to a fixture file)
but a reasonable comprise for now.
Fixes: #751 ("[python3.8] Testsuite fails")
2020-06-03 21:06:26 +02:00
|
|
|
self.assertXMLEqual(exp, r.to_str())
|
2010-12-30 02:27:15 +01:00
|
|
|
|
|
|
|
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>"""
|
tests: Ignore the ordering of attributes in XML documents
Old xml.etree.cElementTree versions (python2) reorder the attributes
while recent xml.etree.cElementTree versions (python3) keep the
document order.
Example:
python3:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
b'<foo y="foo" x="bar" />'
>>>
python2:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
'<foo x="bar" y="foo" />'
>>>
So far, the testsuite compared two serialized XML documents via a simple
string comparison. For instance via,
self.assertEqual(actual_serialized_xml, expected_serialized_xml) where
the expected_serialized_xml is, for instance, a hardcoded str. Obviously,
this would only work for python2 or python3.
In order to support both python versions, we first parse both XML
documents and then compare the corresponding trees (this is OK because
we do not care about comments etc.).
A related issue is the way how the testsuite compares data that is "send"
to the API. So far, this was a plain bytes comparison. Again, this won't
work in case of XML documents (see above). Moreover, we have currently
no notion to "indicate" that the transmitted data is an XML document.
As a workaround, we keep the plain bytes comparison and in case it fails,
we try an xml comparison (see above) as a last resort. Strictly speaking,
this is "wrong" (there might be cases (in the future) where we want to
ensure that the transmitted XML data is bit identical to a fixture file)
but a reasonable comprise for now.
Fixes: #751 ("[python3.8] Testsuite fails")
2020-06-03 21:06:26 +02:00
|
|
|
self.assertXMLEqual(exp, r.to_str())
|
2010-12-30 02:27:15 +01:00
|
|
|
|
|
|
|
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>"""
|
tests: Ignore the ordering of attributes in XML documents
Old xml.etree.cElementTree versions (python2) reorder the attributes
while recent xml.etree.cElementTree versions (python3) keep the
document order.
Example:
python3:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
b'<foo y="foo" x="bar" />'
>>>
python2:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
'<foo x="bar" y="foo" />'
>>>
So far, the testsuite compared two serialized XML documents via a simple
string comparison. For instance via,
self.assertEqual(actual_serialized_xml, expected_serialized_xml) where
the expected_serialized_xml is, for instance, a hardcoded str. Obviously,
this would only work for python2 or python3.
In order to support both python versions, we first parse both XML
documents and then compare the corresponding trees (this is OK because
we do not care about comments etc.).
A related issue is the way how the testsuite compares data that is "send"
to the API. So far, this was a plain bytes comparison. Again, this won't
work in case of XML documents (see above). Moreover, we have currently
no notion to "indicate" that the transmitted data is an XML document.
As a workaround, we keep the plain bytes comparison and in case it fails,
we try an xml comparison (see above) as a last resort. Strictly speaking,
this is "wrong" (there might be cases (in the future) where we want to
ensure that the transmitted XML data is bit identical to a fixture file)
but a reasonable comprise for now.
Fixes: #751 ("[python3.8] Testsuite fails")
2020-06-03 21:06:26 +02:00
|
|
|
self.assertXMLEqual(exp, r.to_str())
|
2010-12-30 02:27:15 +01:00
|
|
|
|
|
|
|
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>"""
|
tests: Ignore the ordering of attributes in XML documents
Old xml.etree.cElementTree versions (python2) reorder the attributes
while recent xml.etree.cElementTree versions (python3) keep the
document order.
Example:
python3:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
b'<foo y="foo" x="bar" />'
>>>
python2:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
'<foo x="bar" y="foo" />'
>>>
So far, the testsuite compared two serialized XML documents via a simple
string comparison. For instance via,
self.assertEqual(actual_serialized_xml, expected_serialized_xml) where
the expected_serialized_xml is, for instance, a hardcoded str. Obviously,
this would only work for python2 or python3.
In order to support both python versions, we first parse both XML
documents and then compare the corresponding trees (this is OK because
we do not care about comments etc.).
A related issue is the way how the testsuite compares data that is "send"
to the API. So far, this was a plain bytes comparison. Again, this won't
work in case of XML documents (see above). Moreover, we have currently
no notion to "indicate" that the transmitted data is an XML document.
As a workaround, we keep the plain bytes comparison and in case it fails,
we try an xml comparison (see above) as a last resort. Strictly speaking,
this is "wrong" (there might be cases (in the future) where we want to
ensure that the transmitted XML data is bit identical to a fixture file)
but a reasonable comprise for now.
Fixes: #751 ("[python3.8] Testsuite fails")
2020-06-03 21:06:26 +02:00
|
|
|
self.assertXMLEqual(exp, r.to_str())
|
2010-12-30 02:27:15 +01:00
|
|
|
|
|
|
|
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>"""
|
tests: Ignore the ordering of attributes in XML documents
Old xml.etree.cElementTree versions (python2) reorder the attributes
while recent xml.etree.cElementTree versions (python3) keep the
document order.
Example:
python3:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
b'<foo y="foo" x="bar" />'
>>>
python2:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
'<foo x="bar" y="foo" />'
>>>
So far, the testsuite compared two serialized XML documents via a simple
string comparison. For instance via,
self.assertEqual(actual_serialized_xml, expected_serialized_xml) where
the expected_serialized_xml is, for instance, a hardcoded str. Obviously,
this would only work for python2 or python3.
In order to support both python versions, we first parse both XML
documents and then compare the corresponding trees (this is OK because
we do not care about comments etc.).
A related issue is the way how the testsuite compares data that is "send"
to the API. So far, this was a plain bytes comparison. Again, this won't
work in case of XML documents (see above). Moreover, we have currently
no notion to "indicate" that the transmitted data is an XML document.
As a workaround, we keep the plain bytes comparison and in case it fails,
we try an xml comparison (see above) as a last resort. Strictly speaking,
this is "wrong" (there might be cases (in the future) where we want to
ensure that the transmitted XML data is bit identical to a fixture file)
but a reasonable comprise for now.
Fixes: #751 ("[python3.8] Testsuite fails")
2020-06-03 21:06:26 +02:00
|
|
|
self.assertXMLEqual(exp, r.to_str())
|
2010-12-30 02:27:15 +01:00
|
|
|
|
|
|
|
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>"""
|
tests: Ignore the ordering of attributes in XML documents
Old xml.etree.cElementTree versions (python2) reorder the attributes
while recent xml.etree.cElementTree versions (python3) keep the
document order.
Example:
python3:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
b'<foo y="foo" x="bar" />'
>>>
python2:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
'<foo x="bar" y="foo" />'
>>>
So far, the testsuite compared two serialized XML documents via a simple
string comparison. For instance via,
self.assertEqual(actual_serialized_xml, expected_serialized_xml) where
the expected_serialized_xml is, for instance, a hardcoded str. Obviously,
this would only work for python2 or python3.
In order to support both python versions, we first parse both XML
documents and then compare the corresponding trees (this is OK because
we do not care about comments etc.).
A related issue is the way how the testsuite compares data that is "send"
to the API. So far, this was a plain bytes comparison. Again, this won't
work in case of XML documents (see above). Moreover, we have currently
no notion to "indicate" that the transmitted data is an XML document.
As a workaround, we keep the plain bytes comparison and in case it fails,
we try an xml comparison (see above) as a last resort. Strictly speaking,
this is "wrong" (there might be cases (in the future) where we want to
ensure that the transmitted XML data is bit identical to a fixture file)
but a reasonable comprise for now.
Fixes: #751 ("[python3.8] Testsuite fails")
2020-06-03 21:06:26 +02:00
|
|
|
self.assertXMLEqual(exp, r.to_str())
|
2010-12-30 02:27:15 +01:00
|
|
|
|
|
|
|
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>"""
|
tests: Ignore the ordering of attributes in XML documents
Old xml.etree.cElementTree versions (python2) reorder the attributes
while recent xml.etree.cElementTree versions (python3) keep the
document order.
Example:
python3:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
b'<foo y="foo" x="bar" />'
>>>
python2:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
'<foo x="bar" y="foo" />'
>>>
So far, the testsuite compared two serialized XML documents via a simple
string comparison. For instance via,
self.assertEqual(actual_serialized_xml, expected_serialized_xml) where
the expected_serialized_xml is, for instance, a hardcoded str. Obviously,
this would only work for python2 or python3.
In order to support both python versions, we first parse both XML
documents and then compare the corresponding trees (this is OK because
we do not care about comments etc.).
A related issue is the way how the testsuite compares data that is "send"
to the API. So far, this was a plain bytes comparison. Again, this won't
work in case of XML documents (see above). Moreover, we have currently
no notion to "indicate" that the transmitted data is an XML document.
As a workaround, we keep the plain bytes comparison and in case it fails,
we try an xml comparison (see above) as a last resort. Strictly speaking,
this is "wrong" (there might be cases (in the future) where we want to
ensure that the transmitted XML data is bit identical to a fixture file)
but a reasonable comprise for now.
Fixes: #751 ("[python3.8] Testsuite fails")
2020-06-03 21:06:26 +02:00
|
|
|
self.assertXMLEqual(exp, r.to_str())
|
2010-12-30 02:27:15 +01:00
|
|
|
|
|
|
|
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>"""
|
tests: Ignore the ordering of attributes in XML documents
Old xml.etree.cElementTree versions (python2) reorder the attributes
while recent xml.etree.cElementTree versions (python3) keep the
document order.
Example:
python3:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
b'<foo y="foo" x="bar" />'
>>>
python2:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
'<foo x="bar" y="foo" />'
>>>
So far, the testsuite compared two serialized XML documents via a simple
string comparison. For instance via,
self.assertEqual(actual_serialized_xml, expected_serialized_xml) where
the expected_serialized_xml is, for instance, a hardcoded str. Obviously,
this would only work for python2 or python3.
In order to support both python versions, we first parse both XML
documents and then compare the corresponding trees (this is OK because
we do not care about comments etc.).
A related issue is the way how the testsuite compares data that is "send"
to the API. So far, this was a plain bytes comparison. Again, this won't
work in case of XML documents (see above). Moreover, we have currently
no notion to "indicate" that the transmitted data is an XML document.
As a workaround, we keep the plain bytes comparison and in case it fails,
we try an xml comparison (see above) as a last resort. Strictly speaking,
this is "wrong" (there might be cases (in the future) where we want to
ensure that the transmitted XML data is bit identical to a fixture file)
but a reasonable comprise for now.
Fixes: #751 ("[python3.8] Testsuite fails")
2020-06-03 21:06:26 +02:00
|
|
|
self.assertXMLEqual(exp, r.to_str())
|
2010-12-30 02:27:15 +01:00
|
|
|
|
|
|
|
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>"""
|
tests: Ignore the ordering of attributes in XML documents
Old xml.etree.cElementTree versions (python2) reorder the attributes
while recent xml.etree.cElementTree versions (python3) keep the
document order.
Example:
python3:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
b'<foo y="foo" x="bar" />'
>>>
python2:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
'<foo x="bar" y="foo" />'
>>>
So far, the testsuite compared two serialized XML documents via a simple
string comparison. For instance via,
self.assertEqual(actual_serialized_xml, expected_serialized_xml) where
the expected_serialized_xml is, for instance, a hardcoded str. Obviously,
this would only work for python2 or python3.
In order to support both python versions, we first parse both XML
documents and then compare the corresponding trees (this is OK because
we do not care about comments etc.).
A related issue is the way how the testsuite compares data that is "send"
to the API. So far, this was a plain bytes comparison. Again, this won't
work in case of XML documents (see above). Moreover, we have currently
no notion to "indicate" that the transmitted data is an XML document.
As a workaround, we keep the plain bytes comparison and in case it fails,
we try an xml comparison (see above) as a last resort. Strictly speaking,
this is "wrong" (there might be cases (in the future) where we want to
ensure that the transmitted XML data is bit identical to a fixture file)
but a reasonable comprise for now.
Fixes: #751 ("[python3.8] Testsuite fails")
2020-06-03 21:06:26 +02:00
|
|
|
self.assertXMLEqual(exp, r.to_str())
|
2010-12-30 02:27:15 +01:00
|
|
|
|
|
|
|
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>"""
|
tests: Ignore the ordering of attributes in XML documents
Old xml.etree.cElementTree versions (python2) reorder the attributes
while recent xml.etree.cElementTree versions (python3) keep the
document order.
Example:
python3:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
b'<foo y="foo" x="bar" />'
>>>
python2:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
'<foo x="bar" y="foo" />'
>>>
So far, the testsuite compared two serialized XML documents via a simple
string comparison. For instance via,
self.assertEqual(actual_serialized_xml, expected_serialized_xml) where
the expected_serialized_xml is, for instance, a hardcoded str. Obviously,
this would only work for python2 or python3.
In order to support both python versions, we first parse both XML
documents and then compare the corresponding trees (this is OK because
we do not care about comments etc.).
A related issue is the way how the testsuite compares data that is "send"
to the API. So far, this was a plain bytes comparison. Again, this won't
work in case of XML documents (see above). Moreover, we have currently
no notion to "indicate" that the transmitted data is an XML document.
As a workaround, we keep the plain bytes comparison and in case it fails,
we try an xml comparison (see above) as a last resort. Strictly speaking,
this is "wrong" (there might be cases (in the future) where we want to
ensure that the transmitted XML data is bit identical to a fixture file)
but a reasonable comprise for now.
Fixes: #751 ("[python3.8] Testsuite fails")
2020-06-03 21:06:26 +02:00
|
|
|
self.assertXMLEqual(exp, r.to_str())
|
2010-12-30 02:27:15 +01:00
|
|
|
|
|
|
|
def test_action_from_xml1(self):
|
|
|
|
"""create action from xml"""
|
|
|
|
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')
|
tests: Ignore the ordering of attributes in XML documents
Old xml.etree.cElementTree versions (python2) reorder the attributes
while recent xml.etree.cElementTree versions (python3) keep the
document order.
Example:
python3:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
b'<foo y="foo" x="bar" />'
>>>
python2:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
'<foo x="bar" y="foo" />'
>>>
So far, the testsuite compared two serialized XML documents via a simple
string comparison. For instance via,
self.assertEqual(actual_serialized_xml, expected_serialized_xml) where
the expected_serialized_xml is, for instance, a hardcoded str. Obviously,
this would only work for python2 or python3.
In order to support both python versions, we first parse both XML
documents and then compare the corresponding trees (this is OK because
we do not care about comments etc.).
A related issue is the way how the testsuite compares data that is "send"
to the API. So far, this was a plain bytes comparison. Again, this won't
work in case of XML documents (see above). Moreover, we have currently
no notion to "indicate" that the transmitted data is an XML document.
As a workaround, we keep the plain bytes comparison and in case it fails,
we try an xml comparison (see above) as a last resort. Strictly speaking,
this is "wrong" (there might be cases (in the future) where we want to
ensure that the transmitted XML data is bit identical to a fixture file)
but a reasonable comprise for now.
Fixes: #751 ("[python3.8] Testsuite fails")
2020-06-03 21:06:26 +02:00
|
|
|
self.assertXMLEqual(xml, action.to_str())
|
2010-12-30 02:27:15 +01:00
|
|
|
|
|
|
|
def test_action_from_xml2(self):
|
|
|
|
"""create action from xml"""
|
|
|
|
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)
|
tests: Ignore the ordering of attributes in XML documents
Old xml.etree.cElementTree versions (python2) reorder the attributes
while recent xml.etree.cElementTree versions (python3) keep the
document order.
Example:
python3:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
b'<foo y="foo" x="bar" />'
>>>
python2:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
'<foo x="bar" y="foo" />'
>>>
So far, the testsuite compared two serialized XML documents via a simple
string comparison. For instance via,
self.assertEqual(actual_serialized_xml, expected_serialized_xml) where
the expected_serialized_xml is, for instance, a hardcoded str. Obviously,
this would only work for python2 or python3.
In order to support both python versions, we first parse both XML
documents and then compare the corresponding trees (this is OK because
we do not care about comments etc.).
A related issue is the way how the testsuite compares data that is "send"
to the API. So far, this was a plain bytes comparison. Again, this won't
work in case of XML documents (see above). Moreover, we have currently
no notion to "indicate" that the transmitted data is an XML document.
As a workaround, we keep the plain bytes comparison and in case it fails,
we try an xml comparison (see above) as a last resort. Strictly speaking,
this is "wrong" (there might be cases (in the future) where we want to
ensure that the transmitted XML data is bit identical to a fixture file)
but a reasonable comprise for now.
Fixes: #751 ("[python3.8] Testsuite fails")
2020-06-03 21:06:26 +02:00
|
|
|
self.assertXMLEqual(xml, action.to_str())
|
2010-12-30 02:27:15 +01:00
|
|
|
|
2011-01-12 22:20:47 +01:00
|
|
|
def test_action_from_xml3(self):
|
|
|
|
"""create action from xml (with acceptinfo element)"""
|
|
|
|
xml = """<action type="submit">
|
|
|
|
<source package="bar" project="testprj" />
|
|
|
|
<target package="baz" project="foobar" />
|
|
|
|
<acceptinfo rev="5" srcmd5="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" xsrcmd5="ffffffffffffffffffffffffffffffff" />
|
|
|
|
</action>"""
|
|
|
|
action = osc.core.Action.from_xml(ET.fromstring(xml))
|
|
|
|
self.assertEqual(action.type, 'submit')
|
|
|
|
self.assertEqual(action.src_project, 'testprj')
|
|
|
|
self.assertEqual(action.src_package, 'bar')
|
|
|
|
self.assertEqual(action.tgt_project, 'foobar')
|
|
|
|
self.assertEqual(action.tgt_package, 'baz')
|
|
|
|
self.assertTrue(action.opt_sourceupdate is None)
|
|
|
|
self.assertTrue(action.opt_updatelink is None)
|
|
|
|
self.assertTrue(action.src_rev is None)
|
|
|
|
self.assertEqual(action.acceptinfo_rev, '5')
|
|
|
|
self.assertEqual(action.acceptinfo_srcmd5, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
|
|
|
|
self.assertEqual(action.acceptinfo_xsrcmd5, 'ffffffffffffffffffffffffffffffff')
|
|
|
|
self.assertTrue(action.acceptinfo_osrcmd5 is None)
|
|
|
|
self.assertTrue(action.acceptinfo_oxsrcmd5 is None)
|
tests: Ignore the ordering of attributes in XML documents
Old xml.etree.cElementTree versions (python2) reorder the attributes
while recent xml.etree.cElementTree versions (python3) keep the
document order.
Example:
python3:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
b'<foo y="foo" x="bar" />'
>>>
python2:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
'<foo x="bar" y="foo" />'
>>>
So far, the testsuite compared two serialized XML documents via a simple
string comparison. For instance via,
self.assertEqual(actual_serialized_xml, expected_serialized_xml) where
the expected_serialized_xml is, for instance, a hardcoded str. Obviously,
this would only work for python2 or python3.
In order to support both python versions, we first parse both XML
documents and then compare the corresponding trees (this is OK because
we do not care about comments etc.).
A related issue is the way how the testsuite compares data that is "send"
to the API. So far, this was a plain bytes comparison. Again, this won't
work in case of XML documents (see above). Moreover, we have currently
no notion to "indicate" that the transmitted data is an XML document.
As a workaround, we keep the plain bytes comparison and in case it fails,
we try an xml comparison (see above) as a last resort. Strictly speaking,
this is "wrong" (there might be cases (in the future) where we want to
ensure that the transmitted XML data is bit identical to a fixture file)
but a reasonable comprise for now.
Fixes: #751 ("[python3.8] Testsuite fails")
2020-06-03 21:06:26 +02:00
|
|
|
self.assertXMLEqual(xml, action.to_str())
|
2011-01-12 22:20:47 +01:00
|
|
|
|
2010-12-30 02:27:15 +01:00
|
|
|
def test_action_from_xml_unknown_type(self):
|
|
|
|
"""try to create action from xml with unknown type"""
|
|
|
|
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"""
|
|
|
|
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')
|
2018-10-17 15:31:23 +02:00
|
|
|
self.assertEqual(r.state.approver, None)
|
2010-12-30 02:27:15 +01:00
|
|
|
self.assertEqual(r.state.comment, '')
|
|
|
|
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)
|
tests: Ignore the ordering of attributes in XML documents
Old xml.etree.cElementTree versions (python2) reorder the attributes
while recent xml.etree.cElementTree versions (python3) keep the
document order.
Example:
python3:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
b'<foo y="foo" x="bar" />'
>>>
python2:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
'<foo x="bar" y="foo" />'
>>>
So far, the testsuite compared two serialized XML documents via a simple
string comparison. For instance via,
self.assertEqual(actual_serialized_xml, expected_serialized_xml) where
the expected_serialized_xml is, for instance, a hardcoded str. Obviously,
this would only work for python2 or python3.
In order to support both python versions, we first parse both XML
documents and then compare the corresponding trees (this is OK because
we do not care about comments etc.).
A related issue is the way how the testsuite compares data that is "send"
to the API. So far, this was a plain bytes comparison. Again, this won't
work in case of XML documents (see above). Moreover, we have currently
no notion to "indicate" that the transmitted data is an XML document.
As a workaround, we keep the plain bytes comparison and in case it fails,
we try an xml comparison (see above) as a last resort. Strictly speaking,
this is "wrong" (there might be cases (in the future) where we want to
ensure that the transmitted XML data is bit identical to a fixture file)
but a reasonable comprise for now.
Fixes: #751 ("[python3.8] Testsuite fails")
2020-06-03 21:06:26 +02:00
|
|
|
self.assertXMLEqual(xml, r.to_str())
|
2010-12-30 02:27:15 +01:00
|
|
|
|
|
|
|
def test_read_request2(self):
|
|
|
|
"""read in a request (with reviews)"""
|
|
|
|
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')
|
2018-10-17 15:31:23 +02:00
|
|
|
self.assertEqual(r.state.approver, 'someone')
|
2010-12-30 02:27:15 +01:00
|
|
|
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].when, '2010-12-11T00:00:00')
|
|
|
|
self.assertEqual(r.statehistory[0].who, 'creator')
|
|
|
|
self.assertEqual(r.statehistory[0].comment, '')
|
2017-04-12 12:55:16 +02:00
|
|
|
self.assertEqual(r.creator, 'creator')
|
2010-12-30 02:27:15 +01:00
|
|
|
self.assertTrue(len(r.statehistory) == 1)
|
|
|
|
self.assertTrue(len(r.reviews) == 1)
|
tests: Ignore the ordering of attributes in XML documents
Old xml.etree.cElementTree versions (python2) reorder the attributes
while recent xml.etree.cElementTree versions (python3) keep the
document order.
Example:
python3:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
b'<foo y="foo" x="bar" />'
>>>
python2:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
'<foo x="bar" y="foo" />'
>>>
So far, the testsuite compared two serialized XML documents via a simple
string comparison. For instance via,
self.assertEqual(actual_serialized_xml, expected_serialized_xml) where
the expected_serialized_xml is, for instance, a hardcoded str. Obviously,
this would only work for python2 or python3.
In order to support both python versions, we first parse both XML
documents and then compare the corresponding trees (this is OK because
we do not care about comments etc.).
A related issue is the way how the testsuite compares data that is "send"
to the API. So far, this was a plain bytes comparison. Again, this won't
work in case of XML documents (see above). Moreover, we have currently
no notion to "indicate" that the transmitted data is an XML document.
As a workaround, we keep the plain bytes comparison and in case it fails,
we try an xml comparison (see above) as a last resort. Strictly speaking,
this is "wrong" (there might be cases (in the future) where we want to
ensure that the transmitted XML data is bit identical to a fixture file)
but a reasonable comprise for now.
Fixes: #751 ("[python3.8] Testsuite fails")
2020-06-03 21:06:26 +02:00
|
|
|
self.assertXMLEqual(xml, r.to_str())
|
2010-12-30 02:27:15 +01:00
|
|
|
|
|
|
|
def test_read_request3(self):
|
|
|
|
"""read in a request (with an "empty" comment+description)"""
|
2017-04-12 12:55:16 +02:00
|
|
|
xml = """<request creator="xyz" id="2">
|
2010-12-30 02:27:15 +01:00
|
|
|
<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)
|
2017-04-12 12:55:16 +02:00
|
|
|
self.assertEqual(r.creator, 'xyz')
|
|
|
|
exp = """<request creator="xyz" id="2">
|
2010-12-30 02:27:15 +01:00
|
|
|
<action type="set_bugowner">
|
|
|
|
<target project="foo" />
|
|
|
|
<person name="buguser" />
|
|
|
|
</action>
|
|
|
|
<state name="new" when="2010-12-28T12:36:29" who="xyz" />
|
|
|
|
</request>"""
|
|
|
|
|
tests: Ignore the ordering of attributes in XML documents
Old xml.etree.cElementTree versions (python2) reorder the attributes
while recent xml.etree.cElementTree versions (python3) keep the
document order.
Example:
python3:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
b'<foo y="foo" x="bar" />'
>>>
python2:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
'<foo x="bar" y="foo" />'
>>>
So far, the testsuite compared two serialized XML documents via a simple
string comparison. For instance via,
self.assertEqual(actual_serialized_xml, expected_serialized_xml) where
the expected_serialized_xml is, for instance, a hardcoded str. Obviously,
this would only work for python2 or python3.
In order to support both python versions, we first parse both XML
documents and then compare the corresponding trees (this is OK because
we do not care about comments etc.).
A related issue is the way how the testsuite compares data that is "send"
to the API. So far, this was a plain bytes comparison. Again, this won't
work in case of XML documents (see above). Moreover, we have currently
no notion to "indicate" that the transmitted data is an XML document.
As a workaround, we keep the plain bytes comparison and in case it fails,
we try an xml comparison (see above) as a last resort. Strictly speaking,
this is "wrong" (there might be cases (in the future) where we want to
ensure that the transmitted XML data is bit identical to a fixture file)
but a reasonable comprise for now.
Fixes: #751 ("[python3.8] Testsuite fails")
2020-06-03 21:06:26 +02:00
|
|
|
self.assertXMLEqual(exp, r.to_str())
|
2010-12-30 02:27:15 +01:00
|
|
|
|
|
|
|
def test_request_list_view1(self):
|
|
|
|
"""test the list_view method"""
|
|
|
|
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
|
2014-02-27 11:13:10 +01:00
|
|
|
submit: srcprj/srcpackage -> tgtprj/tgtpackage
|
|
|
|
submit: foo/bar -> baz
|
2010-12-30 02:27:15 +01:00
|
|
|
delete: deleteme
|
2011-08-18 15:24:24 +02:00
|
|
|
delete: foo/bar\n"""
|
2010-12-30 02:27:15 +01:00
|
|
|
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)"""
|
|
|
|
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
|
2014-09-11 14:34:22 +02:00
|
|
|
From: Created Request: user -> Review Approved: foobar
|
2010-12-30 02:27:15 +01:00
|
|
|
Descr: This is a simple request with a lot of ... ... text and other
|
|
|
|
stuff. This request also contains a description. This is useful
|
2011-08-18 15:24:24 +02:00
|
|
|
to describe the request. blabla blabla\n"""
|
2010-12-30 02:27:15 +01:00
|
|
|
self.assertEqual(exp, r.list_view())
|
|
|
|
|
|
|
|
def test_request_str1(self):
|
|
|
|
"""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))
|
2017-04-12 12:55:16 +02:00
|
|
|
self.assertEqual(r.creator, 'creator')
|
2010-12-30 02:27:15 +01:00
|
|
|
exp = """\
|
|
|
|
Request: #123
|
|
|
|
|
2015-03-09 09:04:33 +01:00
|
|
|
submit: xyz/abc(cleanup) -> foo ***update link***
|
2010-12-30 02:27:15 +01:00
|
|
|
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
|
|
|
|
|
2015-08-13 07:57:08 +02:00
|
|
|
Review: accepted Group: group1 2010-12-29T00:11:22 abc
|
|
|
|
accepted
|
|
|
|
new Group: group1 2010-12-28T00:11:22 abc
|
|
|
|
review start
|
2010-12-30 02:27:15 +01:00
|
|
|
|
2014-09-11 14:34:22 +02:00
|
|
|
History: 2010-12-12T00:00:00 creator revoked
|
|
|
|
2010-12-11T00:00:00 creator new"""
|
2010-12-30 02:27:15 +01:00
|
|
|
self.assertEqual(exp, str(r))
|
|
|
|
|
|
|
|
def test_request_str2(self):
|
|
|
|
"""test the __str__ method"""
|
|
|
|
xml = """\
|
2017-04-12 12:55:16 +02:00
|
|
|
<request creator="creator" id="98765">
|
2010-12-30 02:27:15 +01:00
|
|
|
<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))
|
2017-04-12 12:55:16 +02:00
|
|
|
self.assertEqual(r.creator, 'creator')
|
2010-12-30 02:27:15 +01:00
|
|
|
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"""
|
|
|
|
xml = """\
|
2017-04-12 12:55:16 +02:00
|
|
|
<request creator="olduser" id="1234" type="submit">
|
2010-12-30 02:27:15 +01:00
|
|
|
<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, '')
|
2017-04-12 12:55:16 +02:00
|
|
|
self.assertEqual(r.creator, 'olduser')
|
2010-12-30 02:27:15 +01:00
|
|
|
exp = """\
|
2017-04-12 12:55:16 +02:00
|
|
|
<request creator="olduser" id="1234">
|
2010-12-30 02:27:15 +01:00
|
|
|
<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>"""
|
tests: Ignore the ordering of attributes in XML documents
Old xml.etree.cElementTree versions (python2) reorder the attributes
while recent xml.etree.cElementTree versions (python3) keep the
document order.
Example:
python3:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
b'<foo y="foo" x="bar" />'
>>>
python2:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
'<foo x="bar" y="foo" />'
>>>
So far, the testsuite compared two serialized XML documents via a simple
string comparison. For instance via,
self.assertEqual(actual_serialized_xml, expected_serialized_xml) where
the expected_serialized_xml is, for instance, a hardcoded str. Obviously,
this would only work for python2 or python3.
In order to support both python versions, we first parse both XML
documents and then compare the corresponding trees (this is OK because
we do not care about comments etc.).
A related issue is the way how the testsuite compares data that is "send"
to the API. So far, this was a plain bytes comparison. Again, this won't
work in case of XML documents (see above). Moreover, we have currently
no notion to "indicate" that the transmitted data is an XML document.
As a workaround, we keep the plain bytes comparison and in case it fails,
we try an xml comparison (see above) as a last resort. Strictly speaking,
this is "wrong" (there might be cases (in the future) where we want to
ensure that the transmitted XML data is bit identical to a fixture file)
but a reasonable comprise for now.
Fixes: #751 ("[python3.8] Testsuite fails")
2020-06-03 21:06:26 +02:00
|
|
|
self.assertXMLEqual(exp, r.to_str())
|
2010-12-30 02:27:15 +01:00
|
|
|
|
2011-01-29 17:43:36 +01:00
|
|
|
def test_get_actions(self):
|
|
|
|
"""test get_actions method"""
|
|
|
|
xml = open(os.path.join(self._get_fixtures_dir(), 'test_request_list_view1.xml'), 'r').read().strip()
|
|
|
|
r = osc.core.Request()
|
|
|
|
r.read(ET.fromstring(xml))
|
|
|
|
sr_actions = r.get_actions('submit')
|
|
|
|
self.assertTrue(len(sr_actions) == 2)
|
|
|
|
for i in sr_actions:
|
|
|
|
self.assertEqual(i.type, 'submit')
|
|
|
|
self.assertTrue(len(r.get_actions('submit', 'delete', 'change_devel')) == 5)
|
|
|
|
self.assertTrue(len(r.get_actions()) == 8)
|
|
|
|
|
2010-12-30 02:27:15 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import unittest
|
|
|
|
unittest.main()
|