本文整理汇总了Python中tests.FakeFasUser.username方法的典型用法代码示例。如果您正苦于以下问题:Python FakeFasUser.username方法的具体用法?Python FakeFasUser.username怎么用?Python FakeFasUser.username使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.FakeFasUser
的用法示例。
在下文中一共展示了FakeFasUser.username方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_package_request_new
# 需要导入模块: from tests import FakeFasUser [as 别名]
# 或者: from tests.FakeFasUser import username [as 别名]
def test_package_request_new(self, login_func, mock_func):
""" Test the package_request_new function. """
login_func.return_value = None
mock_func.return_value = ['pingou', 'toshio']
create_package_acl(self.session)
data = {
'pkgname': 'gnome-terminal',
'summary': 'terminal for GNOME',
'description': 'desc',
'review_url': 'https://bz.rh.c/123',
'status': 'Approved',
'critpath': False,
'poc': 'pingou',
'upstream_url': 'http://gnome.org',
'branches': 'master',
'namespace': 'rpms',
}
user = FakeFasUser()
user.username = 'toshio'
data['branches'] = 'epel7'
with user_set(pkgdb2.APP, user):
# Branch EPEL7 does not exist
output = self.app.post(
'/request/package/', follow_redirects=True,
data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<td class="errors">'epel7' is not a valid choice'
in output.data)
csrf_token = output.data.split(
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
data['csrf_token'] = csrf_token
data['branches'] = 'master'
# All good
user = FakeFasUser()
with user_set(pkgdb2.APP, user):
output = self.app.post(
'/request/package/',
follow_redirects=True, data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="message">user: pingou request package: '
'gnome-terminal on branch master</li>' in output.data)
示例2: test_comaintain_package
# 需要导入模块: from tests import FakeFasUser [as 别名]
# 或者: from tests.FakeFasUser import username [as 别名]
def test_comaintain_package(self, login_func):
""" Test the comaintain_package function. """
login_func.return_value = None
create_package_acl(self.session)
user = FakeFasUser()
with user_set(pkgdb2.APP, user):
output = self.app.get(
'/acl/guake/comaintain/', follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="error">You are already a co-maintainer on '
'F-18</li>' in output.data)
self.assertFalse(
'<li class="message">ACLs updated</li>' in output.data)
output = self.app.get(
'/acl/random/comaintain/', follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="error">No package found by this name</li>'
in output.data)
user = FakeFasUser()
user.username = 'kevin'
with user_set(pkgdb2.APP, user):
output = self.app.get(
'/acl/guake/comaintain/', follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="message">ACLs updated</li>' in output.data)
output = self.app.get(
'/acl/random/comaintain/', follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="error">No package found by this name</li>'
in output.data)
user = FakeFasUser()
user.groups = ['gitr2spec']
with user_set(pkgdb2.APP, user):
output = self.app.get(
'/acl/guake/comaintain/', follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="errors">You must be a packager</li>'
in output.data)
示例3: test_package_orphan
# 需要导入模块: from tests import FakeFasUser [as 别名]
# 或者: from tests.FakeFasUser import username [as 别名]
def test_package_orphan(self, login_func, mock_func):
""" Test the package_orphan function. """
login_func.return_value = None
create_package_acl(self.session)
user = FakeFasUser()
user.username = 'toshio'
with user_set(pkgdb2.APP, user):
output = self.app.get(
'/package/guake/devel/orphan', follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="error">You are not allowed to change the point '
'of contact.</li>' in output.data)
user = FakeFasUser()
with user_set(pkgdb2.APP, user):
output = self.app.get(
'/package/guake/devel/orphan', follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="message">You are no longer point of contact on '
'branch: devel</li>' in output.data)
user = FakeFasUserAdmin()
with user_set(pkgdb2.APP, user):
output = self.app.get(
'/package/guake/devel/orphan', follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="message">You are no longer point of contact on '
'branch: devel</li>' in output.data)
with user_set(pkgdb2.APP, user):
output = self.app.get(
'/package/random/devel/orphan', follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="errors">No package of this name found.</li>'
in output.data)
示例4: test_package_take
# 需要导入模块: from tests import FakeFasUser [as 别名]
# 或者: from tests.FakeFasUser import username [as 别名]
def test_package_take(self, login_func, utils_module):
""" Test the package_take function. """
login_func.return_value = None
utils_module.get_packagers.return_value = ['pingou', 'toshio']
create_package_acl(self.session)
data = {
'branches': ['master'],
}
user = FakeFasUser()
user.username = 'toshio'
with user_set(pkgdb2.APP, user):
output = self.app.post(
'/package/guake/take', follow_redirects=True,
data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="error">No branches orphaned found</li>'
in output.data)
csrf_token = output.data.split(
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
data = {
'branches': ['master'],
'csrf_token': csrf_token,
}
user = FakeFasUser()
with user_set(pkgdb2.APP, user):
output = self.app.post(
'/package/guake/orphan', follow_redirects=True, data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="message">You are no longer point of contact on '
'branch: master</li>' in output.data)
data = {
'branches': ['foo'],
}
user = FakeFasUser()
user.username = 'toshio'
with user_set(pkgdb2.APP, user):
output = self.app.post(
'/package/guake/take', follow_redirects=True,
data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<td class="errors">'foo' is not a valid choice '
'for this field</td>' in output.data)
csrf_token = output.data.split(
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
data = {
'branches': ['master'],
'csrf_token': csrf_token,
}
user = FakeFasUser()
with user_set(pkgdb2.APP, user):
output = self.app.get('/package/guake/take')
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<title> Select branches | PkgDB </title>' in output.data)
output = self.app.get('/package/guake/take/0')
self.assertEqual(output.status_code, 200)
self.assertFalse(
'<title> Select branches | PkgDB </title>' in output.data)
output = self.app.post(
'/package/guake/take', follow_redirects=True, data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="message">You have taken the package guake on '
'branch master</li>' in output.data)
with user_set(pkgdb2.APP, user):
output = self.app.post(
'/package/random/take', follow_redirects=True, data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="errors">No package of this name found.</li>'
in output.data)
示例5: test_package_retire
# 需要导入模块: from tests import FakeFasUser [as 别名]
# 或者: from tests.FakeFasUser import username [as 别名]
def test_package_retire(self, login_func, mock_func):
""" Test the package_retire function. """
login_func.return_value = None
create_package_acl(self.session)
data = {
'branches': ['foobar'],
}
user = FakeFasUser()
user.username = 'toshio'
with user_set(pkgdb2.APP, user):
output = self.app.post(
'/package/guake/retire', follow_redirects=True,
data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'class="errors">Only Admins are allowed to retire package '
'here, you should use `fedpkg retire`.</li>' in output.data)
csrf_token = output.data.split(
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
data = {
'branches': ['master'],
'csrf_token': csrf_token,
}
user = FakeFasUser()
with user_set(pkgdb2.APP, user):
output = self.app.post(
'/package/guake/orphan', follow_redirects=True,
data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="message">You are no longer point of contact on '
'branch: master</li>' in output.data)
data['branches'] = ['f18']
output = self.app.post(
'/package/guake/orphan', follow_redirects=True,
data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="message">You are no longer point of contact on '
'branch: f18</li>' in output.data)
data = {
'branches': ['master'],
'csrf_token': csrf_token,
}
user = FakeFasUser()
user.username = 'toshio'
with user_set(pkgdb2.APP, user):
output = self.app.post(
'/package/guake/retire', follow_redirects=True,
data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'class="errors">Only Admins are allowed to retire package '
'here, you should use `fedpkg retire`.</li>' in output.data)
user = FakeFasUserAdmin()
with user_set(pkgdb2.APP, user):
output = self.app.get('/package/guake/retire')
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<title> Select branches | PkgDB </title>' in output.data)
output = self.app.get('/package/guake/retire/0')
self.assertEqual(output.status_code, 200)
self.assertFalse(
'<title> Select branches | PkgDB </title>' in output.data)
data['branches'] = ['foobar']
output = self.app.post(
'/package/guake/retire', follow_redirects=True,
data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<td class="errors">'foobar' is not a valid choice '
'for this field</td>' in output.data)
data['branches'] = ['f18']
output = self.app.post(
'/package/guake/retire', follow_redirects=True,
data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="message">This package has been retired on '
'branch: f18</li>' in output.data)
with user_set(pkgdb2.APP, user):
output = self.app.post(
'/package/random/retire', follow_redirects=True,
data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="errors">No package of this name found.</li>'
in output.data)
示例6: test_request_acl
# 需要导入模块: from tests import FakeFasUser [as 别名]
# 或者: from tests.FakeFasUser import username [as 别名]
def test_request_acl(self, login_func, mock_func):
""" Test the request_acl function. """
login_func.return_value = None
create_package_acl(self.session)
user = FakeFasUser()
mock_func.return_value = ['pingou', 'ralph', 'kevin']
with user_set(pkgdb2.APP, user):
output = self.app.get('/acl/guake/request/')
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<h1>Request ACLs on package: guake</h1>' in output.data)
self.assertTrue(
'<input id="csrf_token" name="csrf_token"' in output.data)
self.assertTrue(
'<option value="approveacls">approveacls' in output.data)
csrf_token = output.data.split(
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
data = {
'branches': 'master',
'acl': 'watchbugzilla',
'csrf_token': csrf_token,
}
output = self.app.post('/acl/guake/request/', data=data,
follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue('<li class="message">ACLs updated</li>' in
output.data)
user.username = 'Toshio'
with user_set(pkgdb2.APP, user):
output = self.app.get('/acl/guake/request/')
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<h1>Request ACLs on package: guake</h1>' in output.data)
self.assertTrue(
'<input id="csrf_token" name="csrf_token"' in output.data)
self.assertTrue(
'<option value="approveacls">approveacls' in output.data)
csrf_token = output.data.split(
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
data = {
'branches': 'master',
'acl': 'watchbugzilla',
'csrf_token': csrf_token,
}
output = self.app.post('/acl/guake/request/', data=data,
follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue('<li class="message">ACLs updated</li>' in
output.data)
data = {
'branches': 'master',
'acl': 'commit',
'csrf_token': csrf_token,
}
output = self.app.post('/acl/guake/request/', data=data,
follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'class="error">User "Toshio" is not in the packager'
' group</' in output.data)
user = FakeFasUser()
user.groups = ['gitr2spec']
with user_set(pkgdb2.APP, user):
output = self.app.get('/acl/guake/request/')
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<h1>Request ACLs on package: guake</h1>' in output.data)
self.assertTrue(
'<input id="csrf_token" name="csrf_token"' in output.data)
self.assertTrue(
'<option value="approveacls">approveacls' in output.data)
csrf_token = output.data.split(
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
data = {
'branches': 'master',
'acl': 'commit',
'csrf_token': csrf_token,
}
output = self.app.post('/acl/guake/request/', data=data,
follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="message">ACLs updated</li>' in output.data)
self.assertTrue(
#.........这里部分代码省略.........
示例7: test_comaintain_package
# 需要导入模块: from tests import FakeFasUser [as 别名]
# 或者: from tests.FakeFasUser import username [as 别名]
def test_comaintain_package(self, login_func, mock_func):
""" Test the comaintain_package function. """
login_func.return_value = None
create_package_acl(self.session)
user = FakeFasUser()
with user_set(pkgdb2.APP, user):
output = self.app.get(
'/acl/guake/comaintain/', follow_redirects=True)
self.assertEqual(output.status_code, 405)
with user_set(pkgdb2.APP, user):
output = self.app.get('/package/guake/')
csrf_token = output.data.split(
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
data = {'csrf_token': csrf_token}
output = self.app.post(
'/acl/guake/comaintain/',
data=data, follow_redirects=True)
self.assertTrue(
'<li class="error">You are already a co-maintainer on '
'f18</li>' in output.data)
self.assertFalse(
'<li class="message">ACLs updated</li>' in output.data)
output = self.app.post(
'/acl/random/comaintain/',
data=data, follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="error">No package found by this name</li>'
in output.data)
user = FakeFasUser()
mock_func.return_value = ['pingou', 'ralph', 'kevin']
user.username = 'kevin'
with user_set(pkgdb2.APP, user):
output = self.app.post(
'/acl/guake/comaintain/',
data=data, follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="message">ACLs updated</li>' in output.data)
# Nothing to update the second time
output = self.app.post(
'/acl/guake/comaintain/',
data=data, follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="message">Nothing to update</li>' in output.data)
output = self.app.post(
'/acl/random/comaintain/',
data=data, follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="error">No package found by this name</li>'
in output.data)
user = FakeFasUser()
user.groups = ['gitr2spec']
with user_set(pkgdb2.APP, user):
output = self.app.post(
'/acl/guake/comaintain/',
data=data, follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="errors">You must be a packager</li>'
in output.data)
示例8: test_request_acl_all_branch
# 需要导入模块: from tests import FakeFasUser [as 别名]
# 或者: from tests.FakeFasUser import username [as 别名]
def test_request_acl_all_branch(self, login_func, mock_func):
""" Test the request_acl_all_branch function. """
login_func.return_value = None
create_package_acl(self.session)
user = FakeFasUser()
mock_func.return_value = ['pingou', 'ralph', 'kevin']
with user_set(pkgdb2.APP, user):
output = self.app.get(
'/acl/guake/request/approveacls/', follow_redirects=True)
self.assertEqual(output.status_code, 405)
with user_set(pkgdb2.APP, user):
output = self.app.get('/package/guake/')
csrf_token = output.data.split(
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
data = {'csrf_token': csrf_token}
output = self.app.post(
'/acl/guake/request/approveacls/',
data=data, follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'class="message">ACL approveacls requested on branch f18</li>'
in output.data)
self.assertTrue(
'class="message">ACL approveacls requested on branch master</l'
in output.data)
self.assertEqual(
output.data.count('<a class="pending"'), 2)
output = self.app.post(
'/acl/guake/request/foobar/',
data=data, follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="errors">Invalid ACL provided foobar.</li>'
in output.data)
output = self.app.post(
'/acl/barfoo/request/commit/',
data=data, follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="error">No package found by this name</li>'
in output.data)
user.username = 'toshio'
user.groups = []
with user_set(pkgdb2.APP, user):
output = self.app.post(
'/acl/guake/request/commit/',
data=data, follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="error">You must be a packager to apply to the '
'ACL: commit on guake</li>'
in output.data)
output = self.app.post(
'/acl/guake/request/watchcommits/',
data=data, follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="message">ACL watchcommits requested on branch '
'f18</li>' in output.data)
self.assertTrue(
'<li class="message">ACL watchcommits requested on branch '
'master</li>' in output.data)
示例9: test_acl_reassign
# 需要导入模块: from tests import FakeFasUser [as 别名]
# 或者: from tests.FakeFasUser import username [as 别名]
def test_acl_reassign(self, login_func, mock_func):
""" Test the api_acl_reassign function. """
login_func.return_value = None
output = self.app.post('/api/package/acl/reassign')
self.assertEqual(output.status_code, 301)
user = FakeFasUser()
with user_set(APP, user):
output = self.app.post('/api/package/acl/reassign/')
self.assertEqual(output.status_code, 500)
data = json.loads(output.data)
self.assertEqual(data, {
"output": "notok",
"error": "Invalid input submitted",
})
create_package_acl(self.session)
data = {
'pkgnames': ['guake', 'geany'],
'branches': 'master',
'poc': 'toshio',
}
# Fails is user is not a packager.
user = FakeFasUser()
with user_set(APP, user):
exp = {
"error": "User \"toshio\" is not in the packager group",
"output": "notok"
}
output = self.app.post('/api/package/acl/reassign/', data=data)
json_out = json.loads(output.data)
self.assertEqual(output.status_code, 500)
self.assertEqual(json_out, exp)
mock_func.get_packagers.return_value = ['pingou', 'ralph', 'toshio']
mock_func.log.return_value = ''
# Fails for geany is user is a packager but not in the group that
# is the current poc - works for guake
with user_set(APP, user):
exp = {
"error": "You are not part of the group \"gtk-sig\", you "
"are not allowed to change the point of contact.",
"messages": [""],
"output": "ok"
}
output = self.app.post('/api/package/acl/reassign/', data=data)
json_out = json.loads(output.data)
self.assertEqual(output.status_code, 200)
self.assertEqual(json_out, exp)
# Works
data = {
'pkgnames': ['geany'],
'branches': 'master',
'poc': 'toshio',
}
user.groups.append('gtk-sig')
with user_set(APP, user):
exp = {"messages": [''], "output": "ok"}
output = self.app.post('/api/package/acl/reassign/', data=data)
json_out = json.loads(output.data)
self.assertEqual(output.status_code, 200)
self.assertEqual(json_out, exp)
# Check if it fails normally
user.username = 'Ralph'
with user_set(APP, user):
exp = {
"error": "You are not allowed to change the point of contact.",
"output": "notok"
}
output = self.app.post('/api/package/acl/reassign/', data=data)
json_out = json.loads(output.data)
self.assertEqual(output.status_code, 500)
self.assertEqual(json_out, exp)
示例10: test_package_request_edit
# 需要导入模块: from tests import FakeFasUser [as 别名]
# 或者: from tests.FakeFasUser import username [as 别名]
def test_package_request_edit(self, login_func, mock_func):
""" Test the package_request_edit function. """
login_func.return_value = None
mock_func.get_packagers.return_value = ['pingou', 'toshio']
mock_func.log.return_value = 'foo bar'
create_package_acl(self.session)
data = {
'branches': ['epel7'],
}
user = FakeFasUser()
user.username = 'toshio'
with user_set(pkgdb2.APP, user):
output = self.app.post(
'/package/requests/1', follow_redirects=True,
data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="errors">No action found with this identifier.</li>'
in output.data)
create_admin_actions(self.session)
# User not allowed to view request
output = self.app.post(
'/package/requests/1', follow_redirects=True,
data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="errors">Only package adminitrators (`approveacls`)'
' and the requester can review pending branch requests</li>'
in output.data)
# Before the edit
user = FakeFasUser()
user.username = 'ralph'
with user_set(pkgdb2.APP, user):
output = self.app.get('/package/requests/1')
self.assertEqual(output.status_code, 200)
self.assertTrue('<h1>Update request: 1</h1>' in output.data)
self.assertTrue(
'<option selected value="Pending">' in output.data)
csrf_token = output.data.split(
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
data = {
'status': 'Awaiting Review',
'csrf_token': csrf_token,
}
# User cannot approve their own request
output = self.app.post(
'/package/requests/1',
follow_redirects=True, data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<td class="errors">Not a valid choice</td>' in output.data)
data = {
'status': 'Obsolete',
'csrf_token': csrf_token,
}
user = FakeFasUser()
with user_set(pkgdb2.APP, user):
# Admin cannot obsolete a request that is not their
output = self.app.post(
'/package/requests/1',
follow_redirects=True, data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<td class="errors">Not a valid choice</td>' in output.data)
data['status'] = 'Awaiting Review'
# All good
output = self.app.post(
'/package/requests/1',
follow_redirects=True, data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue('<li class="message">foo bar</li>'in output.data)
示例11: test_package_give
# 需要导入模块: from tests import FakeFasUser [as 别名]
# 或者: from tests.FakeFasUser import username [as 别名]
def test_package_give(self, login_func, mock_func):
""" Test the package_give function. """
login_func.return_value = None
create_package_acl(self.session)
user = FakeFasUser()
with user_set(pkgdb2.APP, user):
output = self.app.get('/package/guake/give')
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<h1>Give Point of Contact of package: guake</h1>'
in output.data)
self.assertTrue(
'<input id="csrf_token" name="csrf_token"' in output.data)
csrf_token = output.data.split(
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
data = {
'pkg_branch': '',
'pkg_poc': '',
'csrf_token': csrf_token,
}
output = self.app.post('/package/guake/give', data=data)
self.assertEqual(output.status_code, 200)
self.assertEqual(
output.data.count(
'<td class="errors">This field is required.</td>'
), 1)
with user_set(pkgdb2.APP, user):
output = self.app.get('/package/guake/give')
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<h1>Give Point of Contact of package: guake</h1>'
in output.data)
self.assertTrue(
'<input id="csrf_token" name="csrf_token"' in output.data)
csrf_token = output.data.split(
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
data = {
'pkg_branch': 'devel',
'pkg_poc': 'limb',
'csrf_token': csrf_token,
}
output = self.app.post('/package/guake/give', data=data,
follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="error">The point of contact of this package '
'is not in the packager group</li>'
in output.data)
mock_func.get_packagers.return_value = ['spot']
mock_func.log.return_value = ''
with user_set(pkgdb2.APP, user):
output = self.app.get('/package/guake/give')
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<h1>Give Point of Contact of package: guake</h1>'
in output.data)
self.assertTrue(
'<input id="csrf_token" name="csrf_token"' in output.data)
csrf_token = output.data.split(
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
data = {
'pkg_branch': 'devel',
'pkg_poc': 'spot',
'csrf_token': csrf_token,
}
output = self.app.post('/package/guake/give', data=data,
follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue('<h1 property="doap:name">guake</h1>'
in output.data)
self.assertTrue('<a href="/packager/spot/">' in output.data)
with user_set(pkgdb2.APP, user):
output = self.app.get('/package/random/give')
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="errors">No package of this name found.</li>'
in output.data)
user.username = 'ralph'
with user_set(pkgdb2.APP, user):
output = self.app.get('/package/guake/give')
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<h1>Give Point of Contact of package: guake</h1>'
in output.data)
self.assertTrue(
#.........这里部分代码省略.........
示例12: test_upload_results_loggedin
# 需要导入模块: from tests import FakeFasUser [as 别名]
# 或者: from tests.FakeFasUser import username [as 别名]
def test_upload_results_loggedin(self):
''' Test the app.upload_results function. '''
folder = os.path.dirname(os.path.abspath(__file__))
filename = '1.log'
full_path = os.path.join(folder, filename)
user = FakeFasUser()
with user_set(app.APP, user):
output = self.app.get('/upload/')
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<td><input id="test_result" name="test_result" '
'type="file"></td>' in output.data)
csrf_token = output.data.split(
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
# Valid upload via the UI
stream = open(full_path)
data = {
'test_result': stream,
'username': 'pingou',
'csrf_token': csrf_token,
}
output = self.app.post('/upload/', data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="message">Upload successful!</li>' in output.data)
# Valid upload authenticated and via the anonymous API
stream = open(full_path)
data = {
'test_result': stream,
'username': 'pingou',
}
output = self.app.post('/upload/anonymous', data=data)
self.assertEqual(output.status_code, 200)
data = json.loads(output.data)
self.assertEqual(data, {'message': 'Upload successful!'})
# Invalid file upload
full_path = os.path.join(folder, 'invalid.log')
stream = open(full_path)
data = {
'test_result': stream,
'username': 'pingou',
'csrf_token': csrf_token,
}
output = self.app.post('/upload/', data=data)
self.assertEqual(output.status_code, 302)
# Invalid file upload
full_path = os.path.join(folder, 'invalid.log')
stream = open(full_path)
data = {
'test_result': stream,
'username': 'pingou',
'csrf_token': csrf_token,
}
output = self.app.post('/upload/', data=data, follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="message">Could not parse these results</li>'
in output.data)
# Invalid username
user = FakeFasUser()
user.username = 'kerneltest'
with user_set(app.APP, user):
full_path = os.path.join(folder, 'invalid.log')
stream = open(full_path)
data = {
'test_result': stream,
'username': 'pingou',
'csrf_token': csrf_token,
}
output = self.app.post('/upload/', data=data, follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="error">The `kerneltest` username is reserved, '
'you are not allowed to use it</li>' in output.data)
示例13: test_update_pkg_poc
# 需要导入模块: from tests import FakeFasUser [as 别名]
# 或者: from tests.FakeFasUser import username [as 别名]
def test_update_pkg_poc(self):
""" Test the update_pkg_poc function. """
self.test_add_package()
# Package must exists
self.assertRaises(pkgdblib.PkgdbException,
pkgdblib.update_pkg_poc,
self.session,
pkg_name='test',
clt_name='F-17',
user=FakeFasUser(),
pkg_poc='toshio',
)
self.session.rollback()
# Collection must exists
self.assertRaises(pkgdblib.PkgdbException,
pkgdblib.update_pkg_poc,
self.session,
pkg_name='guake',
clt_name='F-16',
user=FakeFasUser(),
pkg_poc='toshio',
)
self.session.rollback()
# User must be the actual Point of Contact (or an admin of course,
# or part of the group)
self.assertRaises(pkgdblib.PkgdbException,
pkgdblib.update_pkg_poc,
self.session,
pkg_name='guake',
clt_name='F-18',
user=FakeFasUser(),
pkg_poc='toshio',
)
self.session.rollback()
# Groups must end with -sig
user = FakeFasUser()
user.username = 'ralph'
self.assertRaises(pkgdblib.PkgdbException,
pkgdblib.update_pkg_poc,
self.session,
pkg_name='guake',
clt_name='F-18',
user=user,
pkg_poc='group::perl',
)
self.session.rollback()
# Change PoC to a group
pkgdblib.update_pkg_poc(
self.session,
pkg_name='guake',
clt_name='F-18',
user=user,
pkg_poc='group::perl-sig',
)
pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
self.assertEqual(pkg_acl[0].package.name, 'guake')
self.assertEqual(pkg_acl[0].point_of_contact, 'group::perl-sig')
# User must be in the group it gives the PoC to
self.assertRaises(pkgdblib.PkgdbException,
pkgdblib.update_pkg_poc,
self.session,
pkg_name='guake',
clt_name='F-18',
user=user,
pkg_poc='ralph',
)
self.session.rollback()
user.groups.append('perl-sig')
pkgdblib.update_pkg_poc(
self.session,
pkg_name='guake',
clt_name='F-18',
user=user,
pkg_poc='ralph',
)
pkg_acl = pkgdblib.get_acl_package(self.session, 'guake')
self.assertEqual(pkg_acl[0].collection.branchname, 'F-18')
self.assertEqual(pkg_acl[0].package.name, 'guake')
self.assertEqual(pkg_acl[0].point_of_contact, 'ralph')
# PoC can change PoC
user = FakeFasUser()
user.username = 'ralph'
pkgdblib.update_pkg_poc(self.session,
pkg_name='guake',
clt_name='F-18',
user=user,
pkg_poc='toshio',
)
#.........这里部分代码省略.........
示例14: test_api_monitor_package
# 需要导入模块: from tests import FakeFasUser [as 别名]
# 或者: from tests.FakeFasUser import username [as 别名]
def test_api_monitor_package(self, login_func, mock_func):
""" Test the api_package_critpath function. """
login_func.return_value = None
user = FakeFasUser()
# No package
with user_set(pkgdb2.APP, user):
output = self.app.post('/api/package/guake/monitor/1')
self.assertEqual(output.status_code, 500)
data = json.loads(output.data)
self.assertEqual(
sorted(data),
['error', 'output']
)
self.assertEqual(
data['error'], "No package found by this name")
self.assertEqual(
data['output'], "notok")
create_package_acl(self.session)
create_package_critpath(self.session)
# User is not a packager
user.username = 'Toshio'
with user_set(pkgdb2.APP, user):
output = self.app.post('/api/package/guake/monitor/1')
self.assertEqual(output.status_code, 500)
data = json.loads(output.data)
self.assertEqual(
sorted(data),
['error', 'output']
)
self.assertEqual(
data['error'],
"You are not allowed to update the monitor flag on this "
"package")
self.assertEqual(
data['output'], "notok")
# Works
user.username = 'pingou'
with user_set(pkgdb2.APP, user):
output = self.app.post('/api/package/guake/monitor/1')
self.assertEqual(output.status_code, 200)
data = json.loads(output.data)
self.assertEqual(
sorted(data),
['messages', 'output']
)
self.assertEqual(
data['messages'], "Monitoring status of guake set to True")
self.assertEqual(
data['output'], "ok")
output = self.app.post('/api/package/guake/monitor/1')
self.assertEqual(output.status_code, 200)
data = json.loads(output.data)
self.assertEqual(
sorted(data),
['messages', 'output']
)
self.assertEqual(
data['messages'], "Monitoring status un-changed")
self.assertEqual(
data['output'], "ok")
# User is not a packager but is admin
user = FakeFasUserAdmin()
user.username = 'Toshio'
with user_set(pkgdb2.APP, user):
output = self.app.post('/api/package/guake/monitor/False')
self.assertEqual(output.status_code, 200)
data = json.loads(output.data)
self.assertEqual(
sorted(data),
['messages', 'output']
)
self.assertEqual(
data['messages'], "Monitoring status of guake set to False")
self.assertEqual(
data['output'], "ok")
示例15: test_unwatch_package
# 需要导入模块: from tests import FakeFasUser [as 别名]
# 或者: from tests.FakeFasUser import username [as 别名]
def test_unwatch_package(self, bz_mail_func, login_func, mock_func):
""" Test the unwatch_package function. """
login_func.return_value = None
bz_mail_func.return_value = 1
create_package_acl(self.session)
user = FakeFasUser()
mock_func.return_value = ['pingou', 'ralph', 'kevin']
with user_set(pkgdb2.APP, user):
output = self.app.get(
'/acl/rpms/guake/unwatch/', follow_redirects=True)
self.assertEqual(output.status_code, 405)
with user_set(pkgdb2.APP, user):
output = self.app.get('/package/rpms/guake/')
csrf_token = output.data.split(
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
data = {'csrf_token': csrf_token}
output = self.app.post(
'/acl/rpms/guake/unwatch/', data=data, follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="error">You cannot remove `Watch*` ACLs from '
'the Point of Contact.</li>' in output.data)
output = self.app.post(
'/acl/rpms/random/unwatch/', data=data, follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="error">No package found by this name</li>'
in output.data)
# Give watchbugzilla to ralph on guake/master
guake_pkg = model.Package.by_name(self.session, 'rpms', 'guake')
devel_collec = model.Collection.by_name(self.session, 'master')
pklist_guake_devel = model.PackageListing.by_pkgid_collectionid(
self.session, guake_pkg.id, devel_collec.id)
packager = model.PackageListingAcl(
fas_name='ralph',
packagelisting_id=pklist_guake_devel.id,
acl='watchbugzilla',
status='Approved',
)
self.session.add(packager)
self.session.commit()
# Drop watch* for ralph
user.username = 'ralph'
with user_set(pkgdb2.APP, user):
output = self.app.get('/package/rpms/guake/')
csrf_token = output.data.split(
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
data = {'csrf_token': csrf_token}
output = self.app.post(
'/acl/rpms/guake/unwatch/', data=data, follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="message">ACLs updated</li>' in output.data)
output = self.app.post(
'/acl/rpms/random/unwatch/', data=data, follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="error">No package found by this name</li>'
in output.data)