Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_model(self) -> None:
with app.app_context(): # type: ignore
rv = self.app.get(url_for('model_index'))
assert b'Browse' in rv.data
rv = self.app.get(url_for('class_index'))
assert b'E1' in rv.data
rv = self.app.get(url_for('class_view', code='E4'))
assert b'Domain for' in rv.data
rv = self.app.get(url_for('property_index'))
assert b'P1' in rv.data
rv = self.app.get(url_for('property_view', code='P68'))
assert b'P68' in rv.data
data: Dict[str, Any] = {'domain': 'E1', 'range': 'E1', 'property': 'P13'}
rv = self.app.post(url_for('model_index'), data=data)
assert b'Wrong domain' in rv.data
data = {'domain': 'E1', 'range': 'E1', 'property': 'P67'}
self.app.post(url_for('model_index'), data=data)
with app.test_request_context(): # Insert data to display in network view
app.preprocess_request() # type: ignore
actor = Entity.insert('E21', 'King Arthur')
event = Entity.insert('E7',
'Battle of Camlann - a long name that has to be truncated ..')
resp = pillarsdk.Node.create_asset_from_file(
str(self.project_id),
str(parent_id),
'image',
blender_desktop_logo_path,
mimetype='image/jpeg',
always_create_new_node=False,
fileobj=fileobj,
api=self.sdk_api)
node_id = resp._id
self.assertTrue(node_id)
# Check the node in MongoDB
with self.app.test_request_context():
resp = self.get(url_for('nodes|item_lookup', _id=node_id), auth_token='token')
node_doc = resp.get_json()
self.assertEqual('BlenderDesktopLogo.png', node_doc['name'])
def ensure(self):
"""If the corresponding GitHub hook does not exist, creates it.
If it exists, but has wrong configuration, re-configures it.
Returns True if there weren't GitHub API errors; False otherwise.
"""
assert self.id
events = ['push', 'pull_request']
config = {
'url': flask.url_for('builds.hook', id=self.id, _external=True),
'content_type': 'json',
}
try:
gh_hook = (self.project.gh.hook(self.gh_id)
if self.gh_id not in (None, MISSING_ID) else None)
if gh_hook:
if gh_hook.events != events or gh_hook.config != config:
gh_hook.edit(config=config, events=events)
else:
gh_hook = self.project.gh.create_hook(
name='web', config=config, events=events, active=True)
except github3.GitHubError as e:
logger.warning(
'GitHub API call to create {project!r}\'s hook has failed. '
'The exception is "{e!r} and with errors {e.errors!r}.".'.format(
def special_users():
wiki = get_wiki()
users = []
for user in wiki.auth.getUsers():
user_url = 'user:/%s' % urllib.parse.quote(user.username.title())
users.append({
'username': user.username,
'url': url_for('read', url=user_url),
'groups': list(user.groups)
})
data = {
'title': "Users",
'users': users}
add_auth_data(data)
add_navigation_data(None, data)
return render_template('special-users.html', **data)
else:
flash(_('Invalid login method.'), 'error')
else:
req = request.get_legacy_request()
# Fake parameters for p_un & p_pw because SSO takes them from the environment
(iden, nickname, password, msgcode) = webuser.loginUser(req, '', '', CFG_EXTERNAL_AUTH_USING_SSO)
if iden:
user = update_login(nickname)
if user:
flash(_("You are logged in as %s.") % user.nickname, "info")
if referer is not None:
from urlparse import urlparse
# we should not redirect to these URLs after login
blacklist = [url_for('webaccount.register'),
url_for('webaccount.logout'),
url_for('webaccount.login')]
if not urlparse(referer).path in blacklist:
# Change HTTP method to https if needed.
referer = referer.replace(CFG_SITE_URL, CFG_SITE_SECURE_URL)
return redirect(referer)
return redirect('/')
except:
flash(_("Problem with login."), "error")
current_app.config.update(dict((k, v) for k, v in
vars(websession_config).iteritems()
if "CFG_" == k[:4]))
collection = Collection.query.get_or_404(1)
def to_json(self):
json_comment = {
'url': url_for('api.get_comment', id=self.id, _external=True),
'post': url_for('api.get_post', id=self.post_id, _external=True),
'body': self.body,
'body_html': self.body_html,
'timestamp': self.timestamp,
'author': url_for('api.get_user', id=self.author_id,
_external=True),
}
return json_comment
'gamecode': GameConstants.JUBEAT,
},
)
if g.config.get('support', {}).get(GameConstants.MUSECA, False):
# Museca pages
museca_entries = []
if len([p for p in profiles if p[0] == GameConstants.MUSECA]) > 0:
museca_entries.extend([
{
'label': 'Game Options',
'uri': url_for('museca_pages.viewsettings'),
},
{
'label': 'Personal Profile',
'uri': url_for('museca_pages.viewplayer', userid=g.userID),
},
{
'label': 'Personal Scores',
'uri': url_for('museca_pages.viewscores', userid=g.userID),
},
{
'label': 'Personal Records',
'uri': url_for('museca_pages.viewrecords', userid=g.userID),
},
])
museca_entries.extend([
{
'label': 'Global Scores',
'uri': url_for('museca_pages.viewnetworkscores'),
},
{
def ssh_key_remove(ssh_key_id, admin=None):
"""Handle GET (confirmation page) and POST (deletions) requests at /ssh//remove."""
if request.method == 'POST':
ssh_keys.remove_ssh_key(ssh_key_id)
# Redirect admin users back to the admin panel
if admin:
return redirect(url_for('admin_dashboard'))
return redirect(url_for('ssh_key_list'))
return render_template('confirm.html')
del rivals[VersionConstants.POPN_MUSIC_TUNE_STREET]
return render_react(
'Pop\'n Music Rivals',
'popn/rivals.react.js',
{
'userid': str(g.userID),
'rivals': rivals,
'max_active_rivals': frontend.max_active_rivals,
'players': playerinfo,
'versions': {version: name for (game, version, name) in frontend.all_games()},
},
{
'refresh': url_for('popn_pages.listrivals'),
'search': url_for('popn_pages.searchrivals'),
'player': url_for('popn_pages.viewplayer', userid=-1),
'addrival': url_for('popn_pages.addrival'),
'removerival': url_for('popn_pages.removerival'),
},
def site_token(site_id):
synchronize(site_id)
response = {
'sign_in': firebase.url_for(
'widget',
mode='select',
next=url_for('auth.signed_in', _scheme='https', _external=True),
),
'sign_out': firebase.url_for(
'sign_out',
next=url_for('auth.signed_out', _scheme='https', _external=True),
),
}
user = current_user._get_current_object()
if not user.is_authenticated:
response['status_code'] = 401
return jsonify(response)
response['account'] = {
'email': user.email,
'email_verified': True, # XXX user.email_verified,
'name': user.name,
}
for roles in user.roles:
if roles.site_id == site_id:
response['account']['roles'] = roles.roles
break
if 'roles' not in response['account']: # XXX or not user.email_verified