Add some basic check for the non-ring acceptance.

This commit is contained in:
Tomáš Chvátal 2014-02-10 13:58:59 +01:00
parent f2c67f6cb3
commit 9e1f61c1a8
2 changed files with 48 additions and 9 deletions

View File

@ -92,10 +92,8 @@ class StagingApi(object):
'by_group': 'factory-staging', 'by_group': 'factory-staging',
'comment': message} 'comment': message}
u = makeurl(self.apiurl, ['request', str(id)], query=query) url = makeurl(self.apiurl, ['request', str(id)], query=query)
f = http_POST(u, data=message) f = http_POST(url, data=message)
root = ET.parse(f).getroot()
return root.attrib['code']
def accept_non_ring_request(self, request): def accept_non_ring_request(self, request):
""" """
@ -122,9 +120,10 @@ class StagingApi(object):
# Verify the package ring # Verify the package ring
ring = self.ring_packages.get(target_package, None) ring = self.ring_packages.get(target_package, None)
# DVD and main desktops are ignored for now
if ring is None or ring == 'openSUSE:Factory:DVD' or ring == 'openSUSE:Factory:MainDesktops': if ring is None or ring == 'openSUSE:Factory:DVD' or ring == 'openSUSE:Factory:MainDesktops':
# accept the request here # accept the request here
message = "No need for staging, not in tested ring project" message = "No need for staging, not in tested ring project."
self.staging_change_review_state(request_id, 'accepted', message) self.staging_change_review_state(request_id, 'accepted', message)

View File

@ -30,7 +30,7 @@ class TestApiCalls(unittest.TestCase):
def _register_pretty_url_get(self, url, filename): def _register_pretty_url_get(self, url, filename):
""" """
Register specified url with specific filename in fixtures Register specified get url with specific filename in fixtures
:param url: url address to "open" :param url: url address to "open"
:param filename: name of the fixtures file :param filename: name of the fixtures file
""" """
@ -43,6 +43,22 @@ class TestApiCalls(unittest.TestCase):
url, url,
body=content) body=content)
def _register_pretty_url_post(self, url, filename):
"""
Register specified post url with specific filename in fixtures
:param url: url address to "open"
:param filename: name of the fixtures file
"""
response = open(os.path.join(self._get_fixtures_dir(), filename), 'r')
content = response.read()
response.close()
httpretty.register_uri(httpretty.POST,
url,
body=content)
def setUp(self): def setUp(self):
""" """
Initialize the configuration so the osc is happy Initialize the configuration so the osc is happy
@ -81,12 +97,37 @@ class TestApiCalls(unittest.TestCase):
self.assertEqual(ring_packages, self.assertEqual(ring_packages,
api.ring_packages) api.ring_packages)
@httpretty.activate
def test_dispatch_open_requests(self):
"""
Test dispatching and closure of non-ring packages
"""
pkglist = []
# Initiate the pretty overrides
self._register_pretty_url_get('http://localhost/search/request?match=state/@name=\'review\'+and+review[@by_group=\'factory-staging\'+and+@state=\'new\']',
'open-requests.xml')
# There should be just one request that gets closed
# We don't care about the return so just reuse the above :P
# If there is bug in the function we get assertion about closing more issues than we should
self._register_pretty_url_post('http://localhost/request/220956?comment=No+need+for+staging%2C+not+in+tested+ring+project.&newstate=accepted&by_group=factory-staging&cmd=changereviewstate',
'open-requests.xml')
# Initiate the api with mocked rings
with mock_generate_ring_packages():
api = oscs.StagingApi('http://localhost')
# get the open requests
requests = api.dispatch_open_requests()
@httpretty.activate @httpretty.activate
def test_list_projects(self): def test_list_projects(self):
""" """
List projects and their content List projects and their content
""" """
prjlist = [ prjlist = [
'openSUSE:Factory:Staging:A', 'openSUSE:Factory:Staging:A',
'openSUSE:Factory:Staging:B', 'openSUSE:Factory:Staging:B',
@ -111,9 +152,8 @@ class TestApiCalls(unittest.TestCase):
""" """
List projects and their content List projects and their content
""" """
requests = [
]
requests = []
# Initiate the pretty overrides # Initiate the pretty overrides
self._register_pretty_url_get('http://localhost/search/request?match=state/@name=\'review\'+and+review[@by_group=\'factory-staging\'+and+@state=\'new\']', self._register_pretty_url_get('http://localhost/search/request?match=state/@name=\'review\'+and+review[@by_group=\'factory-staging\'+and+@state=\'new\']',
@ -137,5 +177,5 @@ def mock_generate_ring_packages():
with mock.patch('oscs.StagingApi._generate_ring_packages', return_value={'AGGR-antlr': 'openSUSE:Factory:MainDesktops', with mock.patch('oscs.StagingApi._generate_ring_packages', return_value={'AGGR-antlr': 'openSUSE:Factory:MainDesktops',
'Botan': 'openSUSE:Factory:DVD', 'Botan': 'openSUSE:Factory:DVD',
'DirectFB': 'openSUSE:Factory:Core', 'DirectFB': 'openSUSE:Factory:Core',
'zlib': 'openSUSE:Factory:Build'}): 'xf86-video-intel': 'openSUSE:Factory:Build'}):
yield yield