AcceptCommand only adds one comment
Added tests for AcceptCommand with a new Staging:C fixture.
This commit is contained in:
parent
05aa1e3900
commit
c7774d8b8b
@ -40,20 +40,23 @@ class AcceptCommand(object):
|
|||||||
|
|
||||||
meta = self.api.get_prj_pseudometa(project)
|
meta = self.api.get_prj_pseudometa(project)
|
||||||
requests = []
|
requests = []
|
||||||
|
packages = []
|
||||||
for req in meta['requests']:
|
for req in meta['requests']:
|
||||||
self.api.rm_from_prj(project, request_id=req['id'], msg='ready to accept')
|
self.api.rm_from_prj(project, request_id=req['id'], msg='ready to accept')
|
||||||
|
requests.append(req['id'])
|
||||||
|
packages.append(req['package'])
|
||||||
msg = 'Accepting staging review for {0}'.format(req['package'])
|
msg = 'Accepting staging review for {0}'.format(req['package'])
|
||||||
print(msg)
|
print(msg)
|
||||||
|
|
||||||
# Write a comment in the project.
|
|
||||||
user = get_request(self.api.apiurl, str(req['id'])).get_creator()
|
|
||||||
self.comment.add_comment(project_name=project, comment='[at]%s: %s' % (user, msg))
|
|
||||||
|
|
||||||
requests.append(req['id'])
|
|
||||||
|
|
||||||
for req in requests:
|
for req in requests:
|
||||||
change_request_state(self.api.apiurl, str(req), 'accepted', message='Accept to factory')
|
change_request_state(self.api.apiurl, str(req), 'accepted', message='Accept to factory')
|
||||||
|
|
||||||
|
# A single comment should be enough to notify everybody, since they are
|
||||||
|
# already mentioned in the comments created by select/unselect
|
||||||
|
pkg_list = ", ".join(packages)
|
||||||
|
cmmt = 'Project "{0}" accepted. The following packages have been submitted to factory: {1}.'.format(project, pkg_list)
|
||||||
|
self.comment.add_comment(project_name=project, comment=cmmt)
|
||||||
|
|
||||||
# XXX CAUTION - AFAIK the 'accept' command is expected to clean the messages here.
|
# XXX CAUTION - AFAIK the 'accept' command is expected to clean the messages here.
|
||||||
self.comment.delete_from(project_name=project)
|
self.comment.delete_from(project_name=project)
|
||||||
|
|
||||||
|
47
tests/accept_tests.py
Normal file
47
tests/accept_tests.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# (C) 2014 tchvatal@suse.cz, openSUSE.org
|
||||||
|
# Distribute under GPLv2 or later
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import unittest
|
||||||
|
import httpretty
|
||||||
|
import mock
|
||||||
|
|
||||||
|
from obs import APIURL
|
||||||
|
from obs import OBS
|
||||||
|
from osc import oscerr
|
||||||
|
from osclib.accept_command import AcceptCommand
|
||||||
|
from oscs import StagingAPI
|
||||||
|
from osclib.comments import CommentAPI
|
||||||
|
|
||||||
|
class TestAccept(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
"""
|
||||||
|
Initialize the configuration
|
||||||
|
"""
|
||||||
|
self.obs = OBS()
|
||||||
|
self.api = StagingAPI(APIURL)
|
||||||
|
|
||||||
|
def test_accept_comments(self):
|
||||||
|
c_api = CommentAPI(self.api.apiurl)
|
||||||
|
staging_c = 'openSUSE:Factory:Staging:C'
|
||||||
|
comments = c_api.get_comments(project_name=staging_c)
|
||||||
|
|
||||||
|
# Accept staging C (containing apparmor and mariadb)
|
||||||
|
with mock.patch('oscs.StagingAPI.find_openqa_state', return_value='Nothing'):
|
||||||
|
self.assertEqual(True, AcceptCommand(self.api).perform(staging_c))
|
||||||
|
|
||||||
|
# Comments are cleared up
|
||||||
|
accepted_comments = c_api.get_comments(project_name=staging_c)
|
||||||
|
self.assertNotEqual(len(comments), 0)
|
||||||
|
self.assertEqual(len(accepted_comments), 0)
|
||||||
|
|
||||||
|
# But the comment was written at some point
|
||||||
|
self.assertEqual(len(self.obs.comment_bodies), 1)
|
||||||
|
comment = self.obs.comment_bodies[0]
|
||||||
|
self.assertTrue('The following packages have been submitted to factory' in comment)
|
||||||
|
self.assertTrue('apparmor' in comment)
|
||||||
|
self.assertTrue('mariadb' in comment)
|
10
tests/fixtures/build/openSUSE:Factory:Staging:C/_result
vendored
Normal file
10
tests/fixtures/build/openSUSE:Factory:Staging:C/_result
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<resultlist state="c7856c90c70c53fae88aacec964b80c0">
|
||||||
|
<result project="openSUSE:Factory:Staging:C" repository="standard" arch="x86_64" code="published" state="published">
|
||||||
|
<status package="apparmor" code="succeeded" />
|
||||||
|
<status package="mariadb" code="succeeded" />
|
||||||
|
</result>
|
||||||
|
<result project="openSUSE:Factory:Staging:C" repository="standard" arch="i585" code="unpublished" state="unpublished">
|
||||||
|
<status package="apparmor" code="succeeded" />
|
||||||
|
<status package="mariadb" code="succeeded" />
|
||||||
|
</result>
|
||||||
|
</resultlist>
|
1
tests/fixtures/request/501
vendored
Symbolic link
1
tests/fixtures/request/501
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
template_request.xml
|
1
tests/fixtures/request/502
vendored
Symbolic link
1
tests/fixtures/request/502
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
template_request.xml
|
1
tests/fixtures/source/home:Admin/apparmor
vendored
Normal file
1
tests/fixtures/source/home:Admin/apparmor
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
<directory name="${name}" rev="${rev}" vrev="${vrev}" srcmd5="${srcmd5}"/>
|
1
tests/fixtures/source/home:Admin/mariadb
vendored
Normal file
1
tests/fixtures/source/home:Admin/mariadb
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
<directory name="${name}" rev="${rev}" vrev="${vrev}" srcmd5="${srcmd5}"/>
|
1
tests/fixtures/source/openSUSE:Factory:Staging:C/_meta
vendored
Symbolic link
1
tests/fixtures/source/openSUSE:Factory:Staging:C/_meta
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../openSUSE:Factory:Staging:A/_meta
|
1
tests/fixtures/source/openSUSE:Factory:Staging:C/_project
vendored
Symbolic link
1
tests/fixtures/source/openSUSE:Factory:Staging:C/_project
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../openSUSE:Factory:Staging:A/_project
|
1
tests/fixtures/source/openSUSE:Factory:Staging:C/apparmor
vendored
Symbolic link
1
tests/fixtures/source/openSUSE:Factory:Staging:C/apparmor
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../linksource.xml
|
1
tests/fixtures/source/openSUSE:Factory:Staging:C/mariadb
vendored
Symbolic link
1
tests/fixtures/source/openSUSE:Factory:Staging:C/mariadb
vendored
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../linksource.xml
|
96
tests/obs.py
96
tests/obs.py
@ -141,6 +141,24 @@ class OBS(object):
|
|||||||
'by_who': 'openSUSE:Factory:Staging:B',
|
'by_who': 'openSUSE:Factory:Staging:B',
|
||||||
'package': 'wine',
|
'package': 'wine',
|
||||||
},
|
},
|
||||||
|
'501': {
|
||||||
|
'request': 'review',
|
||||||
|
'review': 'new',
|
||||||
|
'who': 'Admin',
|
||||||
|
'by': 'project',
|
||||||
|
'id': '501',
|
||||||
|
'by_who': 'openSUSE:Factory:Staging:C',
|
||||||
|
'package': 'apparmor',
|
||||||
|
},
|
||||||
|
'502': {
|
||||||
|
'request': 'review',
|
||||||
|
'review': 'new',
|
||||||
|
'who': 'Admin',
|
||||||
|
'by': 'project',
|
||||||
|
'id': '502',
|
||||||
|
'by_who': 'openSUSE:Factory:Staging:C',
|
||||||
|
'package': 'mariadb',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
self.staging_project = {
|
self.staging_project = {
|
||||||
@ -159,6 +177,12 @@ class OBS(object):
|
|||||||
'title': 'wine',
|
'title': 'wine',
|
||||||
'description': 'requests:\n- {id: 333, package: wine}',
|
'description': 'requests:\n- {id: 333, package: wine}',
|
||||||
},
|
},
|
||||||
|
'C': {
|
||||||
|
'project': 'openSUSE:Factory:Staging:C',
|
||||||
|
'title': 'A project ready to be accepted',
|
||||||
|
'description': ("requests:\n - {id: 501, package: apparmor, author: Admin}\n"
|
||||||
|
" - {id: 502, package: mariadb, author: Admin}"),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
self.links = {
|
self.links = {
|
||||||
@ -167,6 +191,16 @@ class OBS(object):
|
|||||||
'pkg': 'wine',
|
'pkg': 'wine',
|
||||||
'devprj': 'home:Admin',
|
'devprj': 'home:Admin',
|
||||||
},
|
},
|
||||||
|
'openSUSE:Factory:Staging:C/apparmor': {
|
||||||
|
'prj': 'openSUSE:Factory:Staging:C',
|
||||||
|
'pkg': 'apparmor',
|
||||||
|
'devprj': 'home:Admin',
|
||||||
|
},
|
||||||
|
'openSUSE:Factory:Staging:C/mariadb': {
|
||||||
|
'prj': 'openSUSE:Factory:Staging:C',
|
||||||
|
'pkg': 'mariadb',
|
||||||
|
'devprj': 'home:Admin',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
self.meta = {}
|
self.meta = {}
|
||||||
@ -208,6 +242,30 @@ class OBS(object):
|
|||||||
'name': 'wine',
|
'name': 'wine',
|
||||||
'srcmd5': 'de7a9f5e3bedb01980465f3be3d236cb',
|
'srcmd5': 'de7a9f5e3bedb01980465f3be3d236cb',
|
||||||
},
|
},
|
||||||
|
'home:Admin/apparmor': {
|
||||||
|
'rev': '1',
|
||||||
|
'vrev': '1',
|
||||||
|
'name': 'apparmor',
|
||||||
|
'srcmd5': 'de7a9f5e3bedb01980465f3be3d236cb',
|
||||||
|
},
|
||||||
|
'openSUSE:Factory/apparmor': {
|
||||||
|
'rev': '1',
|
||||||
|
'vrev': '1',
|
||||||
|
'name': 'apparmor',
|
||||||
|
'srcmd5': 'de7a9f5e3bedb01980465f3be3d236cb',
|
||||||
|
},
|
||||||
|
'home:Admin/mariadb': {
|
||||||
|
'rev': '1',
|
||||||
|
'vrev': '1',
|
||||||
|
'name': 'mariadb',
|
||||||
|
'srcmd5': 'de7a9f5e3bedb01980465f3be3d236cb',
|
||||||
|
},
|
||||||
|
'openSUSE:Factory/mariadb': {
|
||||||
|
'rev': '1',
|
||||||
|
'vrev': '1',
|
||||||
|
'name': 'mariadb',
|
||||||
|
'srcmd5': 'de7a9f5e3bedb01980465f3be3d236cb',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
self.comments = {
|
self.comments = {
|
||||||
@ -217,9 +275,20 @@ class OBS(object):
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
'openSUSE:Factory:Staging:U': [],
|
'openSUSE:Factory:Staging:U': [],
|
||||||
'openSUSE:Factory:Staging:B': []
|
'openSUSE:Factory:Staging:B': [],
|
||||||
|
'openSUSE:Factory:Staging:C': [
|
||||||
|
{'who': 'Admin', 'when': '2014-06-01 17:56:28 UTC', 'id': '2',
|
||||||
|
'body': ("The list of requests tracked in openSUSE:Factory:Staging:C has changed:\n\n"
|
||||||
|
" * Request#501 for package apparmor submitted by Admin\n"
|
||||||
|
" * Request#502 for package mariadb submitted by Admin\n")
|
||||||
|
}
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# To track comments created during test execution, even if they have
|
||||||
|
# been deleted afterward
|
||||||
|
self.comment_bodies = []
|
||||||
|
|
||||||
#
|
#
|
||||||
# /request/
|
# /request/
|
||||||
#
|
#
|
||||||
@ -316,7 +385,7 @@ class OBS(object):
|
|||||||
# /source/
|
# /source/
|
||||||
#
|
#
|
||||||
|
|
||||||
@GET(re.compile(r'/source/openSUSE:Factory:Staging:[A|B]/_project'))
|
@GET(re.compile(r'/source/openSUSE:Factory:Staging:[A|B|C]/_project'))
|
||||||
def source_staging_project_project(self, request, uri, headers):
|
def source_staging_project_project(self, request, uri, headers):
|
||||||
"""Return the _project information for a staging project."""
|
"""Return the _project information for a staging project."""
|
||||||
# Load the proper fixture and adjust mtime according the
|
# Load the proper fixture and adjust mtime according the
|
||||||
@ -338,7 +407,7 @@ class OBS(object):
|
|||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@GET(re.compile(r'/source/openSUSE:Factory:Staging:[A|B|U](/\w+)?/_meta'))
|
@GET(re.compile(r'/source/openSUSE:Factory:Staging:[A|B|C|U](/\w+)?/_meta'))
|
||||||
def source_staging_project_meta(self, request, uri, headers):
|
def source_staging_project_meta(self, request, uri, headers):
|
||||||
"""Return the _meta information for a staging project."""
|
"""Return the _meta information for a staging project."""
|
||||||
key = re.search(r'openSUSE:Factory:Staging:(\w(?:/\w+)?)/_meta', uri).group(1)
|
key = re.search(r'openSUSE:Factory:Staging:(\w(?:/\w+)?)/_meta', uri).group(1)
|
||||||
@ -360,7 +429,7 @@ class OBS(object):
|
|||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@PUT(re.compile(r'/source/openSUSE:Factory:Staging:[A|B|U](/\w+)?/_meta'))
|
@PUT(re.compile(r'/source/openSUSE:Factory:Staging:[A|B|C|U](/\w+)?/_meta'))
|
||||||
def put_source_staging_project_meta(self, request, uri, headers):
|
def put_source_staging_project_meta(self, request, uri, headers):
|
||||||
"""Set the _meta information for a staging project."""
|
"""Set the _meta information for a staging project."""
|
||||||
key = re.search(r'openSUSE:Factory:Staging:(\w(?:/\w+)?)/_meta', uri).group(1)
|
key = re.search(r'openSUSE:Factory:Staging:(\w(?:/\w+)?)/_meta', uri).group(1)
|
||||||
@ -392,13 +461,21 @@ class OBS(object):
|
|||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@DELETE('/source/openSUSE:Factory:Staging:B/wine')
|
@DELETE(re.compile('/source/openSUSE:Factory:Staging:[B|C]/\w+'))
|
||||||
def delete_wine(self, request, uri, headers):
|
def delete_package(self, request, uri, headers):
|
||||||
"""Delete the wine source package from B."""
|
"""Delete a source package from a Staging project."""
|
||||||
del self.links['openSUSE:Factory:Staging:B/wine']
|
package = re.search(r'/source/([\w:]+/\w+)', uri).group(1)
|
||||||
response = (200, headers, '<result>Ok</result>')
|
response = (404, headers, '<result>Not found</result>')
|
||||||
|
try:
|
||||||
|
del self.links[package]
|
||||||
|
response = (200, headers, '<result>Ok</result>')
|
||||||
|
except Exception as e:
|
||||||
|
if DEBUG:
|
||||||
|
print uri, e
|
||||||
|
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print 'DELETE', uri, response
|
print 'DELETE', uri, response
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@GET(re.compile(r'/source/home:Admin/wine'))
|
@GET(re.compile(r'/source/home:Admin/wine'))
|
||||||
@ -585,6 +662,7 @@ class OBS(object):
|
|||||||
comment = {'who': 'Admin', 'when': time.strftime('%Y-%m-%d %H:%M:%S UTC', time.gmtime()),
|
comment = {'who': 'Admin', 'when': time.strftime('%Y-%m-%d %H:%M:%S UTC', time.gmtime()),
|
||||||
'id': str(sum(len(c) for c in self.comments.values()) + 1), 'body': request.body }
|
'id': str(sum(len(c) for c in self.comments.values()) + 1), 'body': request.body }
|
||||||
self.comments[prj].append(comment)
|
self.comments[prj].append(comment)
|
||||||
|
self.comment_bodies.append(request.body)
|
||||||
response = (200, headers, '<result>Ok</result>')
|
response = (200, headers, '<result>Ok</result>')
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user