本文整理汇总了Python中tests.FakeFasUser类的典型用法代码示例。如果您正苦于以下问题:Python FakeFasUser类的具体用法?Python FakeFasUser怎么用?Python FakeFasUser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FakeFasUser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_comaintain_package
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(pkgdb.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(pkgdb.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)
示例2: test_is_pkgdb_admin
def test_is_pkgdb_admin(self):
""" Test the is_pkgdb_admin function of pkgdb2. """
user = FakeFasUser()
out = pkgdb2.is_pkgdb_admin(user)
self.assertEqual(out, False)
user.groups = []
out = pkgdb2.is_pkgdb_admin(user)
self.assertEqual(out, False)
user = FakeFasUser()
out = pkgdb2.is_pkgdb_admin(None)
self.assertEqual(out, False)
user = FakeFasUserAdmin()
out = pkgdb2.is_pkgdb_admin(user)
self.assertEqual(out, True)
pkgdb2.APP.config['ADMIN_GROUP'] = 'sysadmin-main'
out = pkgdb2.is_pkgdb_admin(user)
self.assertEqual(out, False)
# Reset the ADMIN_GROUP for the other tests
pkgdb2.APP.config['ADMIN_GROUP'] = ('sysadmin-main', 'sysadmin-cvs')
示例3: test_api_package_retire3
def test_api_package_retire3(self, login_func, mock_func):
""" Test a third time the api_package_retire function. """
login_func.return_value = None
create_package_acl(self.session)
mock_func.log.return_value = ''
# Redirect as you are not a packager
user = FakeFasUser()
user.groups = []
# Add the EPEL 7 collection
collection = model.Collection(
name='Fedora EPEL',
version='7',
status='Active',
owner='kevin',
branchname='epel7',
dist_tag='.el7',
)
self.session.add(collection)
self.session.commit()
# Add guake to epel7
guake_pkg = model.Package.by_name(self.session, 'guake')
el7_collec = model.Collection.by_name(self.session, 'epel7')
pkgltg = model.PackageListing(
point_of_contact='orphan',
status='Orphaned',
package_id=guake_pkg.id,
collection_id=el7_collec.id,
)
self.session.add(pkgltg)
self.session.commit()
# Retire an orphaned package on an EPEL branch
user = FakeFasUser()
data = {
'pkgnames': 'guake',
'branches': ['epel7'],
}
with user_set(pkgdb2.APP, user):
output = self.app.post('/api/package/retire/', data=data)
self.assertEqual(output.status_code, 200)
data = json.loads(output.data)
self.assertEqual(
data,
{
"messages": [""],
"output": "ok"
}
)
示例4: test_package_request_new
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)
示例5: test_is_admin
def test_is_admin(self):
""" Test the is_admin method. """
self.assertFalse(app.is_admin(None))
user = FakeFasUser()
user.cla_done = False
self.assertFalse(app.is_admin(user))
user = FakeFasUser()
user.groups = []
self.assertFalse(app.is_admin(user))
user = FakeFasUser()
user.groups.append('sysadmin-main')
self.assertTrue(app.is_admin(user))
示例6: test_package_orphan
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)
示例7: test_admin_new_release
def test_admin_new_release(self):
""" Test the admin_new_release function. """
user = None
with user_set(app.APP, user):
output = self.app.get('/admin/new', follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<title>OpenID transaction in progress</title>'
in output.data)
user = FakeFasUser()
user.groups = []
user.cla_done = False
with user_set(app.APP, user):
output = self.app.get('/admin/new', follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="error">You are not an admin</li>' in output.data)
user = FakeFasUser()
user.groups = []
with user_set(app.APP, user):
output = self.app.get('/admin/new', follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="error">You are not an admin</li>' in output.data)
user = FakeFasUser()
user.groups.append('sysadmin-main')
with user_set(app.APP, user):
output = self.app.get('/admin/new')
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<title> New release' in output.data)
self.assertTrue(
"<label for=\"releasenum\">Release number <span "
"class='error'>*</span></label>" in output.data)
csrf_token = output.data.split(
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
data = {
'csrf_token': csrf_token,
'releasenum': 20,
'support': 'RELEASE',
}
output = self.app.post(
'/admin/new', data=data, follow_redirects=True)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="message">Release "20" added</li>'
in output.data)
self.assertTrue("<a href='/release/20'>" in output.data)
self.assertTrue("<a href='/admin/20/edit'" in output.data)
示例8: test_package_take
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)
示例9: test_package_unretire
def test_package_unretire(self, login_func, utils_module):
""" Test the package_unretire 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/orphan')
csrf_token = output.data.split(
'name="csrf_token" type="hidden" value="')[1].split('">')[0]
# Oprhan and retire guake on F18
data = {
'branches': ['f18'],
'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: f18</li>' in output.data)
user = FakeFasUserAdmin()
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(
'<li class="message">This package has been retired on '
'branch: f18</li>' in output.data)
# Start testing unretire
with user_set(pkgdb2.APP, user):
output = self.app.get(
'/package/random/unretire', 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)
output = self.app.post(
'/package/random/unretire', 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)
output = self.app.post(
'/package/guake/unretire', follow_redirects=True,
data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="error">User "admin" is not in the '
'packager group</li>' in output.data)
utils_module.get_packagers.return_value = ['pingou', 'toshio']
user.username = 'toshio'
with user_set(pkgdb2.APP, user):
output = self.app.get(
'/package/guake/unretire', follow_redirects=True,
data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<td><select id="branches" multiple name="branches">'
'<option value="f18">f18</option></select></td>'
in output.data)
output = self.app.post(
'/package/guake/unretire', follow_redirects=True,
data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="message">Admins have been asked to un-retire '
'branch: f18</li>' in output.data)
output = self.app.post(
'/package/guake/unretire/0', follow_redirects=True,
data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="error">Could not save the request for branch: '
'f18, has it already been requested?</li>' in output.data)
示例10: test_request_acl
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(
#.........这里部分代码省略.........
示例11: test_comaintain_package
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)
示例12: test_request_acl_all_branch
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)
示例13: test_acl_reassign
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)
示例14: test_package_request_edit
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)
示例15: test_delete_package
def test_delete_package(self, login_func, utils_module):
""" Test the delete_package function. """
login_func.return_value = None
utils_module.get_packagers.return_value = ['pingou', 'toshio']
create_package_acl(self.session)
data = {}
# User is not an admin
user = FakeFasUser()
user.username = 'toshio'
with user_set(pkgdb2.APP, user):
output = self.app.post(
'/package/guake/delete', follow_redirects=True,
data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="errors">You are not an administrator of pkgdb'
'</li>' in output.data)
# User is an admin but no csrf
user = FakeFasUserAdmin()
with user_set(pkgdb2.APP, user):
output = self.app.post(
'/package/guake/delete', follow_redirects=True,
data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="error">Invalid input</li>' in output.data)
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,
}
# User is not an admin but csrf
user = FakeFasUser()
user.username = 'toshio'
with user_set(pkgdb2.APP, user):
output = self.app.post(
'/package/guake/delete', follow_redirects=True,
data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="errors">You are not an administrator of pkgdb'
'</li>' in output.data)
# Check before deleting
output = self.app.get('/packages/')
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<p>4 packages found</p>' in output.data)
# User is an admin with csrf
user = FakeFasUserAdmin()
with user_set(pkgdb2.APP, user):
output = self.app.post(
'/package/guake/delete', follow_redirects=True,
data=data)
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li class="message">Package guake deleted</li>'
in output.data)
self.assertTrue(
'<p>3 packages found</p>' in output.data)
output = self.app.post(
'/package/random/delete', 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)