2014-10-08 14:31:55 +02:00
|
|
|
import os
|
|
|
|
import unittest
|
|
|
|
import logging
|
|
|
|
import httpretty
|
|
|
|
import osc
|
|
|
|
import re
|
2017-01-09 21:49:50 -06:00
|
|
|
from osclib.cache import Cache
|
2021-09-03 15:33:09 +02:00
|
|
|
from . import OBSLocal
|
2014-10-08 14:31:55 +02:00
|
|
|
|
2020-05-02 10:50:33 +02:00
|
|
|
from urllib.parse import urlparse, parse_qs
|
2014-10-08 14:31:55 +02:00
|
|
|
from check_source_in_factory import FactorySourceChecker
|
|
|
|
|
2019-05-04 11:17:57 +02:00
|
|
|
APIURL = 'http://testhost.example.com'
|
2014-10-08 14:31:55 +02:00
|
|
|
FIXTURES = os.path.join(os.getcwd(), 'tests/fixtures')
|
|
|
|
|
2021-09-03 15:33:09 +02:00
|
|
|
class TestFactorySourceAccept(OBSLocal.TestCase):
|
2014-10-08 14:31:55 +02:00
|
|
|
|
2019-05-02 20:34:21 +02:00
|
|
|
def tearDown(self):
|
|
|
|
httpretty.disable()
|
|
|
|
httpretty.reset()
|
|
|
|
|
2014-10-08 14:31:55 +02:00
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Initialize the configuration
|
|
|
|
"""
|
2021-09-03 15:33:09 +02:00
|
|
|
super().setUp()
|
2014-10-08 14:31:55 +02:00
|
|
|
|
2017-01-09 21:49:50 -06:00
|
|
|
Cache.last_updated[APIURL] = {'__oldest': '2016-12-18T11:49:37Z'}
|
2014-10-08 14:31:55 +02:00
|
|
|
httpretty.reset()
|
2020-05-02 10:50:33 +02:00
|
|
|
httpretty.enable(allow_net_connect=False)
|
2014-10-08 14:31:55 +02:00
|
|
|
|
|
|
|
logging.basicConfig()
|
|
|
|
self.logger = logging.getLogger(__file__)
|
|
|
|
self.logger.setLevel(logging.DEBUG)
|
|
|
|
|
2019-12-10 12:41:11 +01:00
|
|
|
self.checker = FactorySourceChecker(apiurl = APIURL,
|
|
|
|
user = 'factory-source',
|
2014-10-08 14:31:55 +02:00
|
|
|
logger = self.logger)
|
2018-03-05 17:21:15 -06:00
|
|
|
self.checker.override_allow = False # Test setup cannot handle.
|
2014-10-08 14:31:55 +02:00
|
|
|
|
|
|
|
def test_accept_request(self):
|
|
|
|
|
2018-06-26 15:18:55 +02:00
|
|
|
httpretty.register_uri(httpretty.GET,
|
2019-05-04 11:17:57 +02:00
|
|
|
APIURL + '/source/openSUSE:Factory/00Meta/lookup.yml',
|
2018-06-26 15:18:55 +02:00
|
|
|
status = 404)
|
|
|
|
|
2014-10-08 14:31:55 +02:00
|
|
|
httpretty.register_uri(httpretty.GET,
|
|
|
|
APIURL + "/request/770001",
|
|
|
|
body = """
|
2017-04-13 15:08:15 -05:00
|
|
|
<request id="770001" creator="chameleon">
|
2014-10-08 14:31:55 +02:00
|
|
|
<action type="submit">
|
|
|
|
<source project="Base:System" package="timezone" rev="481ecbe0dfc63ece3a1f1b5598f7d96c"/>
|
|
|
|
<target project="openSUSE:13.2" package="timezone"/>
|
|
|
|
</action>
|
|
|
|
<state name="new" who="factory-source" when="2014-10-08T12:06:07">
|
|
|
|
<comment>...</comment>
|
|
|
|
</state>
|
|
|
|
<review state="new" by_user="factory-source"/>
|
|
|
|
<description>...</description>
|
|
|
|
</request>
|
|
|
|
""")
|
|
|
|
|
|
|
|
httpretty.register_uri(httpretty.GET,
|
2019-05-04 11:17:57 +02:00
|
|
|
APIURL + "/source/Base:System/timezone?view=info&rev=481ecbe0dfc63ece3a1f1b5598f7d96c",
|
2014-10-08 14:31:55 +02:00
|
|
|
match_querystring = True,
|
|
|
|
body = """
|
|
|
|
<sourceinfo package="timezone"
|
|
|
|
rev="481ecbe0dfc63ece3a1f1b5598f7d96c"
|
|
|
|
srcmd5="481ecbe0dfc63ece3a1f1b5598f7d96c"
|
|
|
|
verifymd5="67bac34d29d70553239d33aaf92d2fdd">
|
|
|
|
<filename>timezone.spec</filename>
|
|
|
|
</sourceinfo>
|
|
|
|
""")
|
2020-05-02 10:50:33 +02:00
|
|
|
|
|
|
|
httpretty.register_uri(httpretty.GET,
|
|
|
|
APIURL + "/source/openSUSE:Factory/timezone/_meta",
|
|
|
|
body = """
|
|
|
|
<package name="timezone" project="openSUSE:Factory">
|
|
|
|
<title>timezone</title>
|
|
|
|
<description></description>
|
|
|
|
</package>
|
|
|
|
""")
|
|
|
|
|
|
|
|
httpretty.register_uri(httpretty.GET,
|
|
|
|
APIURL + "/source/Base:System/timezone/_meta",
|
|
|
|
body = """
|
|
|
|
<package name="timezone" project="Base:System">
|
|
|
|
<title>timezone</title>
|
|
|
|
<description></description>
|
|
|
|
</package>
|
|
|
|
""")
|
|
|
|
|
2014-10-08 14:31:55 +02:00
|
|
|
httpretty.register_uri(httpretty.GET,
|
2019-05-04 11:17:57 +02:00
|
|
|
APIURL + "/source/openSUSE:Factory/timezone?view=info",
|
2014-10-08 14:31:55 +02:00
|
|
|
match_querystring = True,
|
|
|
|
body = """
|
|
|
|
<sourceinfo package="timezone"
|
|
|
|
rev="89"
|
|
|
|
vrev="1"
|
|
|
|
srcmd5="a36605617cbeefa8168bf0ccf3058074"
|
|
|
|
verifymd5="a36605617cbeefa8168bf0ccf3058074">
|
|
|
|
<filename>timezone.spec</filename>
|
|
|
|
</sourceinfo>
|
|
|
|
""")
|
|
|
|
|
|
|
|
httpretty.register_uri(httpretty.GET,
|
2019-05-04 11:17:57 +02:00
|
|
|
APIURL + "/source/openSUSE:Factory/timezone/_history?limit=5",
|
2014-10-08 14:31:55 +02:00
|
|
|
match_querystring = True,
|
|
|
|
body = """
|
|
|
|
<sourceinfo package="timezone"
|
|
|
|
rev="89"
|
|
|
|
vrev="1"
|
|
|
|
srcmd5="a36605617cbeefa8168bf0ccf3058074"
|
|
|
|
verifymd5="a36605617cbeefa8168bf0ccf3058074">
|
|
|
|
<filename>timezone.spec</filename>
|
|
|
|
</sourceinfo>
|
|
|
|
""")
|
2019-05-02 20:34:21 +02:00
|
|
|
|
2014-10-08 14:31:55 +02:00
|
|
|
httpretty.register_uri(httpretty.GET,
|
2019-05-04 11:17:57 +02:00
|
|
|
APIURL + '/search/request',
|
2014-10-08 14:31:55 +02:00
|
|
|
responses = [
|
|
|
|
httpretty.Response( body = """
|
|
|
|
<collection matches="1">
|
2017-04-13 15:08:15 -05:00
|
|
|
<request id="254684" creator="chameleon">
|
2014-10-08 14:31:55 +02:00
|
|
|
<action type="submit">
|
|
|
|
<source project="Base:System" package="timezone" rev="481ecbe0dfc63ece3a1f1b5598f7d96c"/>
|
|
|
|
<target project="openSUSE:Factory" package="timezone"/>
|
|
|
|
</action>
|
|
|
|
<state name="review" who="factory-auto" when="2014-10-08T11:55:56">
|
|
|
|
<comment>...</comment>
|
|
|
|
</state>
|
2016-08-19 10:17:06 +02:00
|
|
|
<review state="new" by_group="opensuse-review-team">
|
|
|
|
<comment/>
|
|
|
|
</review>
|
2014-10-08 14:31:55 +02:00
|
|
|
<description> ... </description>
|
|
|
|
</request>
|
|
|
|
</collection>
|
|
|
|
"""),
|
|
|
|
httpretty.Response( body = """
|
|
|
|
<collection matches="1">
|
2017-04-13 15:08:15 -05:00
|
|
|
<request id="254684" creator="chameleon">
|
2014-10-08 14:31:55 +02:00
|
|
|
<action type="submit">
|
|
|
|
<source project="Base:System" package="timezone" rev="481ecbe0dfc63ece3a1f1b5598f7d96c"/>
|
|
|
|
<target project="openSUSE:Factory" package="timezone"/>
|
|
|
|
</action>
|
|
|
|
<state name="new" who="factory-auto" when="2014-10-08T11:55:56">
|
|
|
|
<comment>...</comment>
|
|
|
|
</state>
|
|
|
|
<description> ... </description>
|
|
|
|
</request>
|
|
|
|
</collection>
|
|
|
|
""")
|
|
|
|
])
|
|
|
|
|
2019-12-10 08:54:32 +01:00
|
|
|
result = { 'status': None }
|
2014-10-08 14:31:55 +02:00
|
|
|
|
|
|
|
def change_request(result, method, uri, headers):
|
2019-05-04 11:17:57 +02:00
|
|
|
query = parse_qs(urlparse(uri).query)
|
|
|
|
if query == {'by_user': ['factory-source'], 'cmd': ['changereviewstate'], 'newstate': ['accepted']}:
|
2014-10-08 14:31:55 +02:00
|
|
|
result['status'] = True
|
2016-08-19 10:17:06 +02:00
|
|
|
else:
|
|
|
|
result['status'] = 'ERROR'
|
2014-10-08 14:31:55 +02:00
|
|
|
return (200, headers, '<status code="blah"/>')
|
|
|
|
|
|
|
|
httpretty.register_uri(httpretty.POST,
|
|
|
|
APIURL + "/request/770001",
|
|
|
|
body = lambda method, uri, headers: change_request(result, method, uri, headers))
|
|
|
|
|
|
|
|
# first time request is in in review
|
|
|
|
self.checker.set_request_ids(['770001'])
|
|
|
|
self.checker.check_requests()
|
|
|
|
|
|
|
|
self.assertEqual(result['status'], None)
|
|
|
|
|
|
|
|
# second time request is in state new so we can accept
|
|
|
|
self.checker.set_request_ids(['770001'])
|
|
|
|
self.checker.check_requests()
|
|
|
|
|
|
|
|
self.assertTrue(result['status'])
|
|
|
|
|
|
|
|
def test_source_not_in_factory(self):
|
|
|
|
|
|
|
|
httpretty.register_uri(httpretty.GET,
|
2019-05-04 11:17:57 +02:00
|
|
|
APIURL + '/search/request?match=state%2F%40name%3D%27review%27+and+review%5B%40by_user%3D%27factory-source%27+and+%40state%3D%27new%27%5D&withfullhistory=1',
|
2014-10-08 14:31:55 +02:00
|
|
|
match_querystring = True,
|
|
|
|
body = """
|
|
|
|
<collection matches="1">
|
2017-04-13 15:08:15 -05:00
|
|
|
<request id="261411" creator="lnussel">
|
2014-10-08 14:31:55 +02:00
|
|
|
<action type="maintenance_incident">
|
2015-02-04 16:43:56 +01:00
|
|
|
<source project="home:lnussel:branches:openSUSE:Backports:SLE-12" package="plan" rev="71e76daf2c2e9ddb0b9208f54a14f608"/>
|
|
|
|
<target project="openSUSE:Maintenance" releaseproject="openSUSE:Backports:SLE-12"/>
|
2014-10-08 14:31:55 +02:00
|
|
|
</action>
|
|
|
|
<state name="review" who="maintbot" when="2014-11-13T13:22:02">
|
|
|
|
<comment></comment>
|
|
|
|
</state>
|
|
|
|
<review state="accepted" when="2014-11-13T13:22:02" who="maintbot" by_user="maintbot">
|
|
|
|
<comment>accepted</comment>
|
|
|
|
<history who="maintbot" when="2014-11-13T16:43:09">
|
|
|
|
<description>Review got accepted</description>
|
|
|
|
<comment>accepted</comment>
|
|
|
|
</history>
|
|
|
|
</review>
|
|
|
|
<review state="new" by_user="factory-source"/>
|
|
|
|
<history who="lnussel" when="2014-11-13T13:22:02">
|
|
|
|
<description>Request created</description>
|
|
|
|
<comment>test update</comment>
|
|
|
|
</history>
|
|
|
|
<history who="maintbot" when="2014-11-13T16:43:08">
|
|
|
|
<description>Request got a new review request</description>
|
|
|
|
</history>
|
|
|
|
<description>test update</description>
|
|
|
|
</request>
|
|
|
|
</collection>
|
|
|
|
""")
|
|
|
|
|
|
|
|
httpretty.register_uri(httpretty.GET,
|
|
|
|
APIURL + "/request/261411",
|
|
|
|
body = """
|
2017-04-13 15:08:15 -05:00
|
|
|
<request id="261411" creator="lnussel">
|
2014-10-08 14:31:55 +02:00
|
|
|
<action type="maintenance_incident">
|
2015-02-04 16:43:56 +01:00
|
|
|
<source project="home:lnussel:branches:openSUSE:Backports:SLE-12" package="plan" rev="71e76daf2c2e9ddb0b9208f54a14f608"/>
|
|
|
|
<target project="openSUSE:Maintenance" releaseproject="openSUSE:Backports:SLE-12"/>
|
2014-10-08 14:31:55 +02:00
|
|
|
</action>
|
|
|
|
<state name="review" who="maintbot" when="2014-11-13T13:22:02">
|
|
|
|
<comment></comment>
|
|
|
|
</state>
|
|
|
|
<review state="accepted" when="2014-11-13T13:22:02" who="maintbot" by_user="maintbot">
|
|
|
|
<comment>accepted</comment>
|
|
|
|
<history who="maintbot" when="2014-11-13T16:43:09">
|
|
|
|
<description>Review got accepted</description>
|
|
|
|
<comment>accepted</comment>
|
|
|
|
</history>
|
|
|
|
</review>
|
|
|
|
<review state="new" by_user="factory-source"/>
|
|
|
|
<history who="lnussel" when="2014-11-13T13:22:02">
|
|
|
|
<description>Request created</description>
|
|
|
|
<comment>test update</comment>
|
|
|
|
</history>
|
|
|
|
<history who="maintbot" when="2014-11-13T16:43:08">
|
|
|
|
<description>Request got a new review request</description>
|
|
|
|
</history>
|
|
|
|
<description>test update</description>
|
|
|
|
</request>
|
|
|
|
""")
|
|
|
|
|
|
|
|
httpretty.register_uri(httpretty.GET,
|
2015-02-04 16:43:56 +01:00
|
|
|
APIURL + "/source/home:lnussel:branches:openSUSE:Backports:SLE-12/plan",
|
2014-10-08 14:31:55 +02:00
|
|
|
body = """
|
|
|
|
<directory name="plan" rev="1" vrev="1" srcmd5="b4ed19dc30c1b328168bc62a81ec6998">
|
|
|
|
<linkinfo project="home:lnussel:plan" package="plan" srcmd5="7a2353f73b29dba970702053229542a0" baserev="7a2353f73b29dba970702053229542a0" xsrcmd5="71e76daf2c2e9ddb0b9208f54a14f608" lsrcmd5="b4ed19dc30c1b328168bc62a81ec6998" />
|
|
|
|
<entry name="_link" md5="91f81d88456818a18a7332999fb2da18" size="125" mtime="1415807350" />
|
|
|
|
<entry name="plan.spec" md5="b6814215f6d2e8559b43de9a214b2cbd" size="8103" mtime="1413627959" />
|
|
|
|
</directory>
|
|
|
|
|
|
|
|
""")
|
|
|
|
|
|
|
|
httpretty.register_uri(httpretty.GET,
|
2020-05-02 10:50:33 +02:00
|
|
|
APIURL + "/source/openSUSE:Factory/plan/_meta",
|
2014-10-08 14:31:55 +02:00
|
|
|
status = 404,
|
|
|
|
body = """
|
|
|
|
<status code="unknown_package">
|
|
|
|
<summary>openSUSE:Factory/plan</summary>
|
|
|
|
</status>
|
|
|
|
""")
|
|
|
|
|
2018-06-26 15:18:55 +02:00
|
|
|
httpretty.register_uri(httpretty.GET,
|
2019-05-04 11:17:57 +02:00
|
|
|
APIURL + '/source/openSUSE:Factory/00Meta/lookup.yml',
|
2018-06-26 15:18:55 +02:00
|
|
|
status = 404)
|
|
|
|
|
2014-10-08 14:31:55 +02:00
|
|
|
httpretty.register_uri(httpretty.GET,
|
2020-05-02 10:50:33 +02:00
|
|
|
APIURL + '/search/request',
|
2014-10-08 14:31:55 +02:00
|
|
|
body = """
|
|
|
|
<collection matches="0">
|
|
|
|
</collection>
|
|
|
|
""")
|
|
|
|
|
2019-12-10 08:54:32 +01:00
|
|
|
result = { 'factory_source_declined': None }
|
2014-10-08 14:31:55 +02:00
|
|
|
|
|
|
|
def change_request(result, method, uri, headers):
|
2019-05-04 11:17:57 +02:00
|
|
|
query = parse_qs(urlparse(uri).query)
|
|
|
|
if query == {'by_user': ['factory-source'], 'cmd': ['changereviewstate'], 'newstate': ['declined']}:
|
2014-10-08 14:31:55 +02:00
|
|
|
result['factory_source_declined'] = True
|
|
|
|
return (200, headers, '<status code="ok"/>')
|
|
|
|
|
|
|
|
httpretty.register_uri(httpretty.POST,
|
|
|
|
APIURL + "/request/261411",
|
|
|
|
body = lambda method, uri, headers: change_request(result, method, uri, headers))
|
|
|
|
|
|
|
|
self.checker.requests = []
|
|
|
|
self.checker.set_request_ids_search_review()
|
|
|
|
self.checker.check_requests()
|
|
|
|
|
|
|
|
self.assertTrue(result['factory_source_declined'])
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|