diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py index 7702810057..0b6a7e1d2b 100644 --- a/Allura/allura/controllers/auth.py +++ b/Allura/allura/controllers/auth.py @@ -1545,6 +1545,7 @@ def revoke_access_token2authcode(self, _id): flash('Authorization revoked') redirect('.') + class OAuth2AuthorizationController(BaseController): def _check_security(self): require_authenticated() diff --git a/Allura/allura/controllers/rest.py b/Allura/allura/controllers/rest.py index 82a39e1f48..0c45bb16ec 100644 --- a/Allura/allura/controllers/rest.py +++ b/Allura/allura/controllers/rest.py @@ -546,6 +546,7 @@ def token(self, **kwargs): response.status_int = status return body + def rest_has_access(obj, user, perm): """ Helper function that encapsulates common functionality for has_access API diff --git a/Allura/allura/lib/custom_middleware.py b/Allura/allura/lib/custom_middleware.py index 0e8c0392a9..9e937a66d0 100644 --- a/Allura/allura/lib/custom_middleware.py +++ b/Allura/allura/lib/custom_middleware.py @@ -326,7 +326,7 @@ def timers(self): debug_each_call=False), Timer('ming', ming.odm.odmsession.ODMSession, 'insert_now', 'update_now', 'delete_now', - 'find', 'find_one_and_update', 'find_one_and_replace', 'find_one_and_delete', + 'find', 'find_one_and_update', 'find_one_and_replace', 'find_one_and_delete', 'remove', 'update', 'update_if_not_modified', 'aggregate', 'distinct', ), @@ -502,7 +502,7 @@ def __call__(self, environ, start_response): srcs += ' ' + ' '.join(environ['csp_form_actions']) oauth_endpoints = ( - '/auth/oauth2/authorize', '/auth/oauth2/do_authorize', '/rest/oauth/authorize', '/rest/oauth/do_authorize') + '/auth/oauth2/authorize', '/auth/oauth2/do_authorize', '/rest/oauth/authorize', '/rest/oauth/do_authorize') if not req.path.startswith(oauth_endpoints): # Do not enforce CSP for OAuth1 and OAuth2 authorization if asbool(self.config.get('csp.form_actions_enforce', False)): rules.add(f"form-action {srcs}") diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py index 8631f09caf..a8a903da7c 100644 --- a/Allura/allura/lib/helpers.py +++ b/Allura/allura/lib/helpers.py @@ -1051,6 +1051,7 @@ def https_open(self, req): validators.NonPrivateUrl().to_python(req.full_url, None) return super().https_open(req) + class UseKnownIPHTTPConnection(http.client.HTTPConnection): # only for http, since https requires a valid cert it should be ok def __init__(self, *a, known_ip_to_use=None, **kw): @@ -1073,6 +1074,7 @@ def http_open(self, req): else: return super().http_open(req) + urllib.request.install_opener(urllib.request.build_opener(NotInternalHTTPHandler, NoInternalHTTPSHandler)) diff --git a/Allura/allura/lib/patches.py b/Allura/allura/lib/patches.py index d8d6423943..ec810fab18 100644 --- a/Allura/allura/lib/patches.py +++ b/Allura/allura/lib/patches.py @@ -24,6 +24,8 @@ from allura.lib import helpers as h _patched = False + + def apply(): global _patched # noqa: PLW0603 if _patched: diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py index fa059bd388..6275c20bc0 100644 --- a/Allura/allura/lib/plugin.py +++ b/Allura/allura/lib/plugin.py @@ -820,7 +820,6 @@ def _passlib_crypt_by_id(self, algorithm: str) -> passlib.ifc.PasswordHash: raise ValueError(f'LDAP algorithms should always start with ldap_ (got {algorithm})') return crypt - def set_password(self, user, old_password, new_password, set_timestamp=True): dn = ldap_user_dn(user.username) if old_password is not None: diff --git a/Allura/allura/lib/security.py b/Allura/allura/lib/security.py index 1db9f19c2a..10805f0934 100644 --- a/Allura/allura/lib/security.py +++ b/Allura/allura/lib/security.py @@ -304,7 +304,7 @@ def debug_obj(obj) -> str: return str(obj) -def has_access(obj, permission: str, user: M.User | None = None, project: M.Project | None = None, roles = None) -> bool: +def has_access(obj, permission: str, user: M.User | None = None, project: M.Project | None = None, roles=None) -> bool: '''Return whether the given user has the permission name on the given object. - First, all the roles for a user in the given project context are computed. diff --git a/Allura/allura/lib/solr.py b/Allura/allura/lib/solr.py index 49511d8aad..68fddb3c6f 100644 --- a/Allura/allura/lib/solr.py +++ b/Allura/allura/lib/solr.py @@ -62,7 +62,7 @@ def escape_solr_arg(term): return term -def make_solr_from_config(push_servers: Iterable[str], query_server: str|None=None, +def make_solr_from_config(push_servers: Iterable[str], query_server: str | None = None, push_servers_auths: Iterable[tuple[str, str] | None] = (), query_server_auth: tuple[str, str] | None = None, **kwargs): @@ -91,7 +91,7 @@ class Solr: unless explicitly overridden. """ - def __init__(self, push_servers: Iterable[str], query_server: str|None = None, + def __init__(self, push_servers: Iterable[str], query_server: str | None = None, push_servers_auths: Iterable[tuple[str, str] | None] = (), query_server_auth: tuple[str, str] | None = None, commit=True, commitWithin=None, **kw): diff --git a/Allura/allura/lib/widgets/oauth_widgets.py b/Allura/allura/lib/widgets/oauth_widgets.py index 7fe33b75ee..5823907d4f 100644 --- a/Allura/allura/lib/widgets/oauth_widgets.py +++ b/Allura/allura/lib/widgets/oauth_widgets.py @@ -81,4 +81,3 @@ class fields(ew_core.NameList): attrs=dict(type='url', style='min-width:25em; margin-left: 162px;', # match grid-4 label width pattern='https://.*', title='must start with https://'), ) - diff --git a/Allura/allura/lib/widgets/project_list.py b/Allura/allura/lib/widgets/project_list.py index b91d2dd84f..d0d643e0c9 100644 --- a/Allura/allura/lib/widgets/project_list.py +++ b/Allura/allura/lib/widgets/project_list.py @@ -37,7 +37,7 @@ class ProjectSummary(ew_core.Widget): show_proj_icon=True, show_download_button=True, show_awards_banner=True, - ) + ) def prepare_context(self, context): response = super().prepare_context(context) @@ -84,7 +84,7 @@ class ProjectList(ew_core.Widget): show_proj_icon=True, show_download_button=True, show_awards_banner=True, - ) + ) def prepare_context(self, context): response = super().prepare_context(context) @@ -121,4 +121,4 @@ class ProjectScreenshots(ew_core.Widget): def resources(self): yield ew.JSLink('allura/js/Sortable.min.js') yield ew.JSLink('js/screenshots.js') - yield ew.CSSLink('css/screenshots.css') \ No newline at end of file + yield ew.CSSLink('css/screenshots.css') diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py index 51dc986178..a14cbf2ad0 100644 --- a/Allura/allura/model/auth.py +++ b/Allura/allura/model/auth.py @@ -175,7 +175,7 @@ def send_verification_link(self): '''.format(self.email, self.claimed_by_user(include_pending=True).username, h.absurl(f'/auth/verify_addr?a={h.urlquote(self.nonce)}'), - ) + ) log.info('Verification email:\n%s', text) allura.tasks.mail_tasks.sendsimplemail.post( fromaddr=g.noreply, diff --git a/Allura/allura/model/discuss.py b/Allura/allura/model/discuss.py index 6cb0b6ef38..35d07cc777 100644 --- a/Allura/allura/model/discuss.py +++ b/Allura/allura/model/discuss.py @@ -405,7 +405,7 @@ def notify_moderators(self, post): if (has_access(self, 'moderate', u) and Mailbox.subscribed(user_id=u._id, app_config_id=post.app_config_id)): - n.send_direct(str(u._id)) + n.send_direct(str(u._id)) def update_stats(self): self.num_replies = self.post_class().query.find( diff --git a/Allura/allura/model/index.py b/Allura/allura/model/index.py index 50b33999f1..64f5526b4e 100644 --- a/Allura/allura/model/index.py +++ b/Allura/allura/model/index.py @@ -170,7 +170,7 @@ def from_links(cls, *links): result = {} # Parse all the links parsed_links = {link: cls._parse_link(link) - for link in links} + for link in links} links_by_artifact = defaultdict(list) project_ids = set() for link, d in list(parsed_links.items()): diff --git a/Allura/allura/model/notification.py b/Allura/allura/model/notification.py index a8b5a76253..337411c3da 100644 --- a/Allura/allura/model/notification.py +++ b/Allura/allura/model/notification.py @@ -237,7 +237,7 @@ def _make_notification(cls, artifact, topic, **kwargs): but the notification still gets sent if there is an error ''' log.warning('Could not render notification template %s' % - artifact.type_s, exc_info=True) + artifact.type_s, exc_info=True) assert d['reply_to_address'] is not None project = c.project @@ -622,7 +622,7 @@ def find_and_modify_direct_mbox(): queue=[], queue_empty=True, )}, - ) + ) mbox.fire(now) def fire(self, now): diff --git a/Allura/allura/model/repo_refresh.py b/Allura/allura/model/repo_refresh.py index e5dbbbea2a..2e1fa2a3a5 100644 --- a/Allura/allura/model/repo_refresh.py +++ b/Allura/allura/model/repo_refresh.py @@ -92,7 +92,7 @@ def refresh_repo(repo, all_commits=False, notify=True, new_clone=False, commits_ if user is not None: g.statsUpdater.newCommit(new, repo.app_config.project, user) actor = user or TransientActor( - activity_name=new.committed.name or new.committed.email) + activity_name=new.committed.name or new.committed.email) g.director.create_activity(actor, 'committed', new, target=repo.app, related_nodes=[repo.app_config.project], tags=['commit', repo.tool.lower()]) diff --git a/Allura/allura/model/session.py b/Allura/allura/model/session.py index 2752afa46d..fb577f6bed 100644 --- a/Allura/allura/model/session.py +++ b/Allura/allura/model/session.py @@ -273,7 +273,7 @@ def substitute_extensions(session, extensions=None): main_orm_session = ThreadLocalODMSession( doc_session=main_doc_session, extensions=[IndexerSessionExtension] - ) +) main_explicitflush_orm_session = ThreadLocalODMSession( doc_session=main_doc_session, extensions=[IndexerSessionExtension, ExplicitFlushOnlySessionExtension] diff --git a/Allura/allura/model/timeline.py b/Allura/allura/model/timeline.py index 6c343bd6fe..db3bbc3424 100644 --- a/Allura/allura/model/timeline.py +++ b/Allura/allura/model/timeline.py @@ -114,6 +114,7 @@ class TransientActor(NodeBase, ActivityObjectBase): """An activity actor which is not a persistent Node in the network. """ + def __init__(self, activity_name): NodeBase.__init__(self) ActivityObjectBase.__init__(self) diff --git a/Allura/allura/scripts/refreshrepo.py b/Allura/allura/scripts/refreshrepo.py index 7756d14836..af5bee9542 100644 --- a/Allura/allura/scripts/refreshrepo.py +++ b/Allura/allura/scripts/refreshrepo.py @@ -160,7 +160,7 @@ def repo_type_list(s): parser.add_argument('--clean-after', metavar='DATETIME', dest='clean_after', type=lambda d: datetime.strptime(d, date_format), help='Like --clean but only docs for commits after date ({} format)'.format( - date_format.replace('%', '%%') + date_format.replace('%', '%%') )) parser.add_argument( '--all', action='store_true', dest='all', default=False, diff --git a/Allura/allura/tasks/admin_tasks.py b/Allura/allura/tasks/admin_tasks.py index 9e30247a53..879e83f651 100644 --- a/Allura/allura/tasks/admin_tasks.py +++ b/Allura/allura/tasks/admin_tasks.py @@ -32,6 +32,7 @@ def install_app(*args, **kwargs): """ c.project.install_app(*args, **kwargs) + install_app.__doc__ += ''' Arguments:: diff --git a/Allura/allura/templates/__init__.py b/Allura/allura/templates/__init__.py index 7b9f3fc3e4..5acea7ec68 100644 --- a/Allura/allura/templates/__init__.py +++ b/Allura/allura/templates/__init__.py @@ -16,4 +16,3 @@ # under the License. """Templates package for the application.""" - diff --git a/Allura/allura/templates_responsive/__init__.py b/Allura/allura/templates_responsive/__init__.py index d70ae0770d..144e29886a 100644 --- a/Allura/allura/templates_responsive/__init__.py +++ b/Allura/allura/templates_responsive/__init__.py @@ -13,4 +13,4 @@ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations -# under the License. \ No newline at end of file +# under the License. diff --git a/Allura/allura/tests/exclude_from_rewrite_hook.py b/Allura/allura/tests/exclude_from_rewrite_hook.py index 828f994c43..6311e4001a 100644 --- a/Allura/allura/tests/exclude_from_rewrite_hook.py +++ b/Allura/allura/tests/exclude_from_rewrite_hook.py @@ -46,4 +46,4 @@ def raise_compound_exception(): assert False, 'assert %d' % x except Exception: errs.append(sys.exc_info()) - raise CompoundError(*errs) \ No newline at end of file + raise CompoundError(*errs) diff --git a/Allura/allura/tests/functional/__init__.py b/Allura/allura/tests/functional/__init__.py index f4a7b12aa7..b8c15d7761 100644 --- a/Allura/allura/tests/functional/__init__.py +++ b/Allura/allura/tests/functional/__init__.py @@ -16,4 +16,3 @@ # under the License. """Functional test suite for the controllers of the application.""" - diff --git a/Allura/allura/tests/functional/test_admin.py b/Allura/allura/tests/functional/test_admin.py index d0d6ee2605..fa3249276f 100644 --- a/Allura/allura/tests/functional/test_admin.py +++ b/Allura/allura/tests/functional/test_admin.py @@ -405,7 +405,7 @@ def test_project_screenshot(self, uuid1): upload = ('screenshot', file_name, file_data) self.app.get('/admin/') - e_filename, e_fileext = os.path.splitext(file_name) + e_filename, e_fileext = os.path.splitext(file_name) with audits('screenshots: added screenshot {}'.format(f"{e_filename}-123{e_fileext}")): self.app.post('/admin/add_screenshot', params=dict( caption='test me'), diff --git a/Allura/allura/tests/functional/test_auth.py b/Allura/allura/tests/functional/test_auth.py index a30f938b24..4d01808110 100644 --- a/Allura/allura/tests/functional/test_auth.py +++ b/Allura/allura/tests/functional/test_auth.py @@ -2184,7 +2184,11 @@ def test_authorize(self): redirect_uris=['https://localhost/'] ) ThreadLocalODMSession.flush_all() - r = self.app.get('/auth/oauth2/authorize', params={'client_id': 'client_12345', 'response_type': 'code', 'redirect_uri': 'https://localhost/'}) + r = self.app.get('/auth/oauth2/authorize', params={ + 'client_id': 'client_12345', + 'response_type': 'code', + 'redirect_uri': 'https://localhost/', + }) assert 'testoauth2' in r.text assert 'client_12345' in r.text @@ -2201,11 +2205,14 @@ def test_do_authorize_no(self): redirect_uris=['https://localhost/'] ) ThreadLocalODMSession.flush_all() - r = self.app.get('/auth/oauth2/authorize', params={'client_id': 'client_12345', 'response_type': 'code', 'redirect_uri': 'https://localhost/'}) + r = self.app.get('/auth/oauth2/authorize', params={ + 'client_id': 'client_12345', + 'response_type': 'code', + 'redirect_uri': 'https://localhost/', + }) r = r.forms[0].submit('no') assert M.OAuth2AuthorizationCode.query.get(client_id='client_12345') is None - @mock.patch.dict(config, {'auth.oauth2.enabled': True}) def test_authorize_and_create_access_token(self): # client owned by someone other than the test-admin user that self.app.get/post use @@ -2225,7 +2232,11 @@ def test_authorize_and_create_access_token(self): r.mustcontain(no='testoauth2') # First navigate to the authorization page for the backend to validate the authorization request - r = self.app.get('/auth/oauth2/authorize', params={'client_id': 'client_12345', 'response_type': 'code', 'redirect_uri': 'https://localhost/'}) + r = self.app.get('/auth/oauth2/authorize', params={ + 'client_id': 'client_12345', + 'response_type': 'code', + 'redirect_uri': 'https://localhost/', + }) # The submit authorization for the authorization code to be created r.forms[0].submit('yes') @@ -2251,7 +2262,6 @@ def test_authorize_and_create_access_token(self): r = self.app.get('/auth/oauth/') r.mustcontain('testoauth2') - @mock.patch.dict(config, {'auth.oauth2.enabled': True}) def test_revoke_auth_code(self): # only the auth code is present, and it gets revoked @@ -2287,7 +2297,6 @@ def test_revoke_auth_code(self): r = self.app.get('/auth/oauth/') r.mustcontain(no='testoauth2') - @mock.patch.dict(config, {'auth.oauth2.enabled': True}) def test_revoke_access_token(self): # both auth code and access token are present, both get revoked @@ -2332,16 +2341,16 @@ def test_revoke_access_token(self): r = self.app.get('/auth/oauth/') r.mustcontain(no='testoauth2') - @mock.patch.dict(config, {'auth.oauth2.enabled': True}) def test_pkce(self, mock_client, mock_credentials): code_verifier = 'QkatVHgTq_cZj8tTKWPIe78fXpoeszhVq6kLIUxJj8g9tMmfi0XV4dfZHQBXwOiWsLihJotfrOGKR4nZSXA4mA' code_challenge = 'BxGpJVKt_l6Srlq3uXPfpxge3TxtxetcWhGXq2958yU' - code_challenge_method = 'S256' # Must be uppercase + code_challenge_method = 'S256' # Must be uppercase # Authorize the app by sending the code challenge and code challenge method as qs param - params = dict(client_id='client_12345', response_type='code', redirect_uri='https://localhost/', code_challenge=code_challenge, - code_challenge_method=code_challenge_method) + params = dict(client_id='client_12345', response_type='code', redirect_uri='https://localhost/', + code_challenge=code_challenge, + code_challenge_method=code_challenge_method) r = self.app.get('/auth/oauth2/authorize', params=params) # Authorize app @@ -2352,7 +2361,8 @@ def test_pkce(self, mock_client, mock_credentials): assert ac is not None # Exchange the authorization code for an access token. It should fail if you do not provide the code verifier - body = dict(client_id='client_12345', client_secret='98765', code=ac.authorization_code, grant_type='authorization_code', redirect_uri='https://localhost/') + body = dict(client_id='client_12345', client_secret='98765', code=ac.authorization_code, + grant_type='authorization_code', redirect_uri='https://localhost/') with pytest.raises(webtest.app.AppError) as ex: r = self.app.post_json('/rest/oauth2/token', body, extra_environ={'username': '*anonymous'}) @@ -2368,7 +2378,8 @@ def test_pkce(self, mock_client, mock_credentials): def test_refresh_token(self, mock_client, mock_valid_token): token = M.OAuth2AccessToken.query.get(client_id='client_12345') - body = dict(client_id='client_12345', client_secret='98765', grant_type='refresh_token', refresh_token=token.refresh_token) + body = dict(client_id='client_12345', client_secret='98765', grant_type='refresh_token', + refresh_token=token.refresh_token) r = self.app.post_json('/rest/oauth2/token', body, extra_environ={'username': '*anonymous'}) assert r.status_int == 200 assert r.json['access_token'] != token.access_token @@ -2376,7 +2387,8 @@ def test_refresh_token(self, mock_client, mock_valid_token): @mock.patch.dict(config, {'auth.oauth2.enabled': True}) def test_invalid_refresh_token(self, mock_client, mock_valid_token): - body = dict(client_id='client_12345', client_secret='98765', grant_type='refresh_token', refresh_token='invalid_token') + body = dict(client_id='client_12345', client_secret='98765', grant_type='refresh_token', + refresh_token='invalid_token') with pytest.raises(webtest.app.AppError) as ex: r = self.app.post_json('/rest/oauth2/token', body, extra_environ={'username': '*anonymous'}) @@ -2387,8 +2399,8 @@ def test_access_token_with_expired_code(self, mock_client, mock_expired_authoriz c = M.OAuth2ClientApp.query.get(client_id='client_12345') ac = M.OAuth2AuthorizationCode.query.get(client_id='client_12345') - body = dict(client_id=c.client_id, client_secret=c.client_secret, grant_type='authorization_code', code=ac.authorization_code, - redirect_uri=c.redirect_uris[0]) + body = dict(client_id=c.client_id, client_secret=c.client_secret, grant_type='authorization_code', + code=ac.authorization_code, redirect_uri=c.redirect_uris[0]) with pytest.raises(webtest.app.AppError) as ex: r = self.app.post_json('/rest/oauth2/token', body, extra_environ={'username': '*anonymous'}) @@ -2399,8 +2411,8 @@ def test_access_token_with_invalid_redirect_uri(self, mock_client, mock_valid_au c = M.OAuth2ClientApp.query.get(client_id='client_12345') ac = M.OAuth2AuthorizationCode.query.get(client_id='client_12345') - body = dict(client_id=c.client_id, client_secret=c.client_secret, grant_type='authorization_code', code=ac.authorization_code, - redirect_uri='https://invalid.com') + body = dict(client_id=c.client_id, client_secret=c.client_secret, grant_type='authorization_code', + code=ac.authorization_code, redirect_uri='https://invalid.com') with pytest.raises(webtest.app.AppError) as ex: r = self.app.post_json('/rest/oauth2/token', body, extra_environ={'username': '*anonymous'}) @@ -2412,8 +2424,8 @@ def test_access_token_with_invalid_credentials(self, mock_client, mock_valid_aut ac = M.OAuth2AuthorizationCode.query.get(client_id='client_12345') # First test passing an invalid client id - body = dict(client_id='invalid_client_id', client_secret=c.client_secret, grant_type='authorization_code', code=ac.authorization_code, - redirect_uri=c.redirect_uris[0]) + body = dict(client_id='invalid_client_id', client_secret=c.client_secret, grant_type='authorization_code', + code=ac.authorization_code, redirect_uri=c.redirect_uris[0]) with pytest.raises(webtest.app.AppError) as ex: r = self.app.post_json('/rest/oauth2/token', body, extra_environ={'username': '*anonymous'}) @@ -2421,8 +2433,8 @@ def test_access_token_with_invalid_credentials(self, mock_client, mock_valid_aut assert 'invalid_client' in str(ex.value) # Now test passing an invalid client secret - body = dict(client_id=c.client_id, client_secret='invalid_secret', grant_type='authorization_code', code=ac.authorization_code, - redirect_uri=c.redirect_uris[0]) + body = dict(client_id=c.client_id, client_secret='invalid_secret', grant_type='authorization_code', + code=ac.authorization_code, redirect_uri=c.redirect_uris[0]) with pytest.raises(webtest.app.AppError) as ex: r = self.app.post_json('/rest/oauth2/token', body, extra_environ={'username': '*anonymous'}) diff --git a/Allura/allura/tests/functional/test_feeds.py b/Allura/allura/tests/functional/test_feeds.py index d3d2eaa1f6..9949b59767 100644 --- a/Allura/allura/tests/functional/test_feeds.py +++ b/Allura/allura/tests/functional/test_feeds.py @@ -71,7 +71,7 @@ def test_wiki_page_feed(self): 'title': 'Root', 'text': '', 'labels': '', - }) + }) self.app.get('/wiki/Root/feed.rss') self.app.get('/wiki/Root/feed.atom') diff --git a/Allura/allura/tests/functional/test_personal_dashboard.py b/Allura/allura/tests/functional/test_personal_dashboard.py index b6a68eb3da..68d64392d6 100644 --- a/Allura/allura/tests/functional/test_personal_dashboard.py +++ b/Allura/allura/tests/functional/test_personal_dashboard.py @@ -87,7 +87,7 @@ def setup_method(self, method): super().setup_method(method) setup_unit_test() self.setup_with_tools() - mr= self.merge_request + mr = self.merge_request ThreadLocalODMSession.flush_all() # variation on @with_git but with different project to avoid clashes with other tests using git diff --git a/Allura/allura/tests/functional/test_rest.py b/Allura/allura/tests/functional/test_rest.py index a5ceaeaae7..9459ff40c9 100644 --- a/Allura/allura/tests/functional/test_rest.py +++ b/Allura/allura/tests/functional/test_rest.py @@ -465,7 +465,7 @@ def test_oauth2_expired_token_authentication(self): r = self.api_get('/rest/p/test/wiki/Home') params = dict(text=r.json['text']) r = self.api_post('/rest/p/test/wiki/Home', params=params) - + assert '401 Unauthorized' in str(ex.value) diff --git a/Allura/allura/tests/functional/test_root.py b/Allura/allura/tests/functional/test_root.py index d115683889..8c86769e71 100644 --- a/Allura/allura/tests/functional/test_root.py +++ b/Allura/allura/tests/functional/test_root.py @@ -191,7 +191,7 @@ def test_slash_redirect(self): @skipIf(module_not_available('newrelic'), 'requires newrelic') def test_newrelic_set_transaction_name(self): from allura.controllers.project import NeighborhoodController - with mock.patch('newrelic.agent.callable_name') as callable_name,\ + with mock.patch('newrelic.agent.callable_name') as callable_name, \ mock.patch('newrelic.agent.set_transaction_name') as set_transaction_name: callable_name.return_value = 'foo' self.app.get('/p/') diff --git a/Allura/allura/tests/model/__init__.py b/Allura/allura/tests/model/__init__.py index e2b83dcde2..799fda96e0 100644 --- a/Allura/allura/tests/model/__init__.py +++ b/Allura/allura/tests/model/__init__.py @@ -16,4 +16,3 @@ # under the License. """Model test suite for the models of the application.""" - diff --git a/Allura/allura/tests/model/test_artifact.py b/Allura/allura/tests/model/test_artifact.py index 33274bda62..9424f90f9c 100644 --- a/Allura/allura/tests/model/test_artifact.py +++ b/Allura/allura/tests/model/test_artifact.py @@ -51,6 +51,8 @@ def __init__(self, **kw): super().__init__(**kw) if self.slug is not None and self.full_slug is None: self.full_slug = datetime.utcnow().strftime('%Y%m%d%H%M%S%f') + ':' + self.slug + + Mapper.compile_all() diff --git a/Allura/allura/tests/model/test_auth.py b/Allura/allura/tests/model/test_auth.py index 3a6ece759d..7afb845d14 100644 --- a/Allura/allura/tests/model/test_auth.py +++ b/Allura/allura/tests/model/test_auth.py @@ -87,19 +87,19 @@ def selftest_email_address_lookup_helpers(): def test_email_address_canonical(self): assert M.EmailAddress.canonical('nobody@EXAMPLE.COM') == \ - 'nobody@example.com' + 'nobody@example.com' assert M.EmailAddress.canonical('nobody@example.com') == \ - 'nobody@example.com' + 'nobody@example.com' assert M.EmailAddress.canonical('I Am Nobody ') == \ - 'nobody@example.com' + 'nobody@example.com' assert M.EmailAddress.canonical(' nobody@example.com\t') == \ - 'nobody@example.com' + 'nobody@example.com' assert M.EmailAddress.canonical('I Am@Nobody ') == \ - 'nobody@example.com' + 'nobody@example.com' assert M.EmailAddress.canonical(' No@body ') == \ - 'no@body@example.com' + 'no@body@example.com' assert M.EmailAddress.canonical('no@body@example.com') == \ - 'no@body@example.com' + 'no@body@example.com' assert M.EmailAddress.canonical('invalid') is None def test_email_address_send_verification_link(self): diff --git a/Allura/allura/tests/model/test_discussion.py b/Allura/allura/tests/model/test_discussion.py index 5cb6b764c3..15b2ed6e1a 100644 --- a/Allura/allura/tests/model/test_discussion.py +++ b/Allura/allura/tests/model/test_discussion.py @@ -599,4 +599,4 @@ def test_delete_post(self): assert M.BaseAttachment.query.get(filename='discussion.txt') assert M.BaseAttachment.query.get(filename='thread.txt') - assert not M.BaseAttachment.query.get(filename='post.txt') \ No newline at end of file + assert not M.BaseAttachment.query.get(filename='post.txt') diff --git a/Allura/allura/tests/model/test_filesystem.py b/Allura/allura/tests/model/test_filesystem.py index 60cd96aedd..844a7b7b22 100644 --- a/Allura/allura/tests/model/test_filesystem.py +++ b/Allura/allura/tests/model/test_filesystem.py @@ -32,6 +32,8 @@ class File(M.File): class __mongometa__: session = M.session.main_orm_session + + Mapper.compile_all() diff --git a/Allura/allura/tests/model/test_repo.py b/Allura/allura/tests/model/test_repo.py index 7434f4b1b0..a553eb3b57 100644 --- a/Allura/allura/tests/model/test_repo.py +++ b/Allura/allura/tests/model/test_repo.py @@ -445,14 +445,13 @@ def test_get_no_query(self, tr_get): tr_get.assert_called_once_with(_id='foo') assert val == tree1 - def test_set(self): tree = mock.Mock(spec=['_id', 'test_set'], _id='foo', val='test_set') self.cache.set(M.repository.Tree, {'val': 'test_set'}, tree) assert self.cache._query_cache == \ - {M.repository.Tree: {(('val', 'test_set'),): 'foo'}} + {M.repository.Tree: {(('val', 'test_set'),): 'foo'}} assert self.cache._instance_cache == \ - {M.repository.Tree: {'foo': tree}} + {M.repository.Tree: {'foo': tree}} @mock.patch('bson.ObjectId') def test_set_none_id(self, obj_id): @@ -465,7 +464,7 @@ def test_set_none_id(self, obj_id): (('val2', 'test_set2'),): 'OBJID', } assert self.cache._instance_cache == \ - {M.repository.Tree: {'OBJID': tree}} + {M.repository.Tree: {'OBJID': tree}} tree._id = '_id' assert self.cache.get(M.repository.Tree, {'val1': 'test_set1'}) == tree assert self.cache.get(M.repository.Tree, {'val2': 'test_set2'}) == tree @@ -503,7 +502,7 @@ def test_instance_ids(self): self.cache.set(M.repository.Tree, {'val': 'tree1'}, tree1) self.cache.set(M.repository.Tree, {'val': 'tree2'}, tree2) assert set(self.cache.instance_ids(M.repository.Tree)) == \ - {'id1', 'id2'} + {'id1', 'id2'} assert self.cache.instance_ids(M.repository.LastCommit) == [] @mock.patch.object(M.repository.Tree.query, 'find') @@ -650,9 +649,9 @@ def test_pruning_query_flush(self, tr_get, session): 'tree2': tree2, } assert session.call_args_list == \ - [mock.call(tree1), mock.call(tree2)] + [mock.call(tree1), mock.call(tree2)] assert session.return_value.flush.call_args_list == \ - [mock.call(tree1), mock.call(tree2)] + [mock.call(tree1), mock.call(tree2)] assert not session.return_value.expunge.called @mock.patch('allura.model.repository.session') diff --git a/Allura/allura/tests/scripts/__init__.py b/Allura/allura/tests/scripts/__init__.py index 77505f1c35..144e29886a 100644 --- a/Allura/allura/tests/scripts/__init__.py +++ b/Allura/allura/tests/scripts/__init__.py @@ -14,4 +14,3 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. - diff --git a/Allura/allura/tests/scripts/test_create_sitemap_files.py b/Allura/allura/tests/scripts/test_create_sitemap_files.py index 8097f169ea..07c858d8c4 100644 --- a/Allura/allura/tests/scripts/test_create_sitemap_files.py +++ b/Allura/allura/tests/scripts/test_create_sitemap_files.py @@ -44,7 +44,7 @@ def test_create(self): rmtree(tmpdir.path) # needs to be non-existent for the script self.run_script(['-o', tmpdir.path]) - tmpdir.compare(['sitemap-0.xml', 'sitemap.xml'],recursive=False, files_only=True) + tmpdir.compare(['sitemap-0.xml', 'sitemap.xml'], recursive=False, files_only=True) xml_index = ET.parse(os.path.join(tmpdir.path, 'sitemap.xml')) ns = {'ns0': 'http://www.sitemaps.org/schemas/sitemap/0.9'} diff --git a/Allura/allura/tests/templates/__init__.py b/Allura/allura/tests/templates/__init__.py index 77505f1c35..144e29886a 100644 --- a/Allura/allura/tests/templates/__init__.py +++ b/Allura/allura/tests/templates/__init__.py @@ -14,4 +14,3 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. - diff --git a/Allura/allura/tests/templates/jinja_master/__init__.py b/Allura/allura/tests/templates/jinja_master/__init__.py index 77505f1c35..144e29886a 100644 --- a/Allura/allura/tests/templates/jinja_master/__init__.py +++ b/Allura/allura/tests/templates/jinja_master/__init__.py @@ -14,4 +14,3 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. - diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py index c88623c5dd..9f93a51f2a 100644 --- a/Allura/allura/tests/test_globals.py +++ b/Allura/allura/tests/test_globals.py @@ -792,7 +792,7 @@ def test_empty_cache(self): html = self.md.cached_convert(self.post, 'text') assert html == self.expected_html assert html == self.post.text_cache.html - assert hashlib.md5(self.post.text.encode('utf-8')).hexdigest() == self.post.text_cache.md5 + assert hashlib.md5(self.post.text.encode('utf-8')).hexdigest() == self.post.text_cache.md5 assert self.post.text_cache.render_time > 0 @patch.dict('allura.lib.app_globals.config', markdown_cache_threshold='-0.01') diff --git a/Allura/allura/tests/test_helpers.py b/Allura/allura/tests/test_helpers.py index 817abde698..d9f223479d 100644 --- a/Allura/allura/tests/test_helpers.py +++ b/Allura/allura/tests/test_helpers.py @@ -16,7 +16,7 @@ # under the License. import io -from unittest import skipIf +from unittest import skipIf from os import path from datetime import datetime, timedelta import time @@ -47,6 +47,7 @@ # httpbin.io does not allow /redirect-to to localhost httpbin_domain = 'httpbin.dev' + def setup_module(): setup_basic_test() @@ -628,7 +629,7 @@ class BestApp: with pytest.raises(ImportError, match=r'Ambiguous \[allura\] entry points detected. ' 'Multiple entry points with name "myapp".'): - list(h.iter_entry_points('allura')) + list(h.iter_entry_points('allura')) def test_get_user_status(): diff --git a/Allura/allura/tests/test_markdown.py b/Allura/allura/tests/test_markdown.py index 3e56fe81e8..5975d0d2d6 100644 --- a/Allura/allura/tests/test_markdown.py +++ b/Allura/allura/tests/test_markdown.py @@ -131,4 +131,4 @@ def test_convert(self, lookup, get_comment_slug): md = markdown.Markdown( extensions=[mde.CommitMessageExtension(app), 'markdown.extensions.nl2br'], output_format='html') - assert md.convert(text) == expected_html \ No newline at end of file + assert md.convert(text) == expected_html diff --git a/Allura/allura/tests/test_plugin.py b/Allura/allura/tests/test_plugin.py index 5bdaf5751b..4118abb2e7 100644 --- a/Allura/allura/tests/test_plugin.py +++ b/Allura/allura/tests/test_plugin.py @@ -638,9 +638,9 @@ def test_password_encoder_legacy(self): assert ep('test_pass', '0000') == ('sha2560000j7pRjKKZ5L8G0jScZKja9ECmYF2zBV82Mi+E3wkop30=', 'allura_sha256') @pytest.mark.parametrize('algorithm,rounds,specific_salt,salt_len,expected_config', [ - ('sha512_crypt', None,None, None, '$6$rounds=656000$'), - ('pbkdf2_sha256', None,None, None, '$pbkdf2-sha256$29000$'), - ('pbkdf2_sha512', None,None, None, '$pbkdf2-sha512$25000$'), + ('sha512_crypt', None, None, None, '$6$rounds=656000$'), + ('pbkdf2_sha256', None, None, None, '$pbkdf2-sha256$29000$'), + ('pbkdf2_sha512', None, None, None, '$pbkdf2-sha512$25000$'), # test with explicit # of rounds & salt_len ('pbkdf2_sha512', 26789, None, 50, '$pbkdf2-sha512$26789$'), ('bcrypt_sha256', None, 'O'*22, None, '$bcrypt-sha256$v=2,t=2b,r=12$'), diff --git a/Allura/allura/tests/test_validators.py b/Allura/allura/tests/test_validators.py index d4ca3031b3..39d7a68e8b 100644 --- a/Allura/allura/tests/test_validators.py +++ b/Allura/allura/tests/test_validators.py @@ -127,7 +127,7 @@ def test_invalid(self, c): c.user = M.User.anonymous() with pytest.raises(fe.Invalid) as cm: self.val.to_python(True) - assert str(cm.value) == "Log in to Mark as Private" + assert str(cm.value) == "Log in to Mark as Private" class TestMountPointValidator: @@ -210,7 +210,7 @@ def test_invalid_name(self): def test_import_failure(self): with pytest.raises(fe.Invalid) as cm: self.val.to_python('allura.does.not.exist') - assert str(cm.value) =='Could not import "allura.does.not.exist"' + assert str(cm.value) == 'Could not import "allura.does.not.exist"' def test_attr_lookup_failure(self): with pytest.raises(fe.Invalid) as cm: @@ -329,7 +329,7 @@ def f(filename): pass def test_valid(self): input = self._mock('foo.png') - assert input == self.val.to_python(input) + assert input == self.val.to_python(input) input = self._mock('foo.jpg') assert input == self.val.to_python(input) diff --git a/Allura/allura/tests/unit/controllers/test_discussion_moderation_controller.py b/Allura/allura/tests/unit/controllers/test_discussion_moderation_controller.py index 388ba955eb..2b9a01fff6 100644 --- a/Allura/allura/tests/unit/controllers/test_discussion_moderation_controller.py +++ b/Allura/allura/tests/unit/controllers/test_discussion_moderation_controller.py @@ -51,7 +51,7 @@ def test_that_it_can_approve(self): post = self.get_post() assert post.status == 'ok' assert (post.thread.last_post_date.strftime("%Y-%m-%d %H:%M:%S") == - mod_date.strftime("%Y-%m-%d %H:%M:%S")) + mod_date.strftime("%Y-%m-%d %H:%M:%S")) def test_that_it_can_mark_as_spam(self): self.moderate_post(spam=True) diff --git a/Allura/allura/tests/unit/test_app.py b/Allura/allura/tests/unit/test_app.py index 71b4e95f0f..1e41f7a39b 100644 --- a/Allura/allura/tests/unit/test_app.py +++ b/Allura/allura/tests/unit/test_app.py @@ -124,4 +124,4 @@ def install_app(): # XXX: Remove project argument to install; it's redundant app = Application(project, app_config) app.install(project) - return app \ No newline at end of file + return app diff --git a/Allura/allura/tests/unit/test_artifact.py b/Allura/allura/tests/unit/test_artifact.py index bac61bfd73..b8a1477d32 100644 --- a/Allura/allura/tests/unit/test_artifact.py +++ b/Allura/allura/tests/unit/test_artifact.py @@ -25,4 +25,4 @@ def test_translate_query(self): fields = {'name_t': '', 'shortname_s': ''} query = 'name:1 AND shortname:2 AND shortname_name_field:3' q = M.Artifact.translate_query(query, fields) - assert q == 'name_t:1 AND shortname_s:2 AND shortname_name_field:3' + assert q == 'name_t:1 AND shortname_s:2 AND shortname_name_field:3' diff --git a/Allura/allura/tests/unit/test_session.py b/Allura/allura/tests/unit/test_session.py index e69e9737d4..884f83f5e4 100644 --- a/Allura/allura/tests/unit/test_session.py +++ b/Allura/allura/tests/unit/test_session.py @@ -167,7 +167,7 @@ def test_update_index(self, find): find.return_value = [m(_id=i) for i in (7, 8, 9)] self.ext.update_index(objs_deleted, arefs) assert self.ext.to_delete == \ - {o.index_id() for o in objs_deleted} + {o.index_id() for o in objs_deleted} assert self.ext.to_add == {4, 5, 6} # test deleting something that was previously added @@ -175,7 +175,7 @@ def test_update_index(self, find): find.return_value = [m(_id=4)] self.ext.update_index(objs_deleted, []) assert self.ext.to_delete == \ - {o.index_id() for o in objs_deleted} + {o.index_id() for o in objs_deleted} assert self.ext.to_add == {5, 6} @mock.patch('allura.model.session.index_tasks') diff --git a/Allura/allura/tests/unit/test_solr.py b/Allura/allura/tests/unit/test_solr.py index 42c4643ce5..83d6b167f6 100644 --- a/Allura/allura/tests/unit/test_solr.py +++ b/Allura/allura/tests/unit/test_solr.py @@ -49,7 +49,7 @@ def test_init(self, pysolr): calls = [mock.call('server1', auth=None), mock.call('server2', auth=None), mock.call('server3', auth=None), - ] + ] pysolr.Solr.assert_has_calls(calls) assert len(solr.push_pool) == 2 diff --git a/Allura/allura/websetup/bootstrap.py b/Allura/allura/websetup/bootstrap.py index c0e47e6db1..18989a0b39 100644 --- a/Allura/allura/websetup/bootstrap.py +++ b/Allura/allura/websetup/bootstrap.py @@ -304,9 +304,11 @@ def clear_all_database_tables(): continue db.drop_collection(coll) + # this re-uses hashes for the same pwd, which gives a huge speedup during tests. Not good for real usage, since salting is the same. user_pwd_hash_speedup_cache = {} + def fast_set_pwd(user: M.User, password: str): if password in user_pwd_hash_speedup_cache: user.password, user.password_algorithm = user_pwd_hash_speedup_cache[password] @@ -315,6 +317,7 @@ def fast_set_pwd(user: M.User, password: str): user.set_password(password) user_pwd_hash_speedup_cache[password] = (user.password, user.password_algorithm) + def create_user(display_name, username=None, password='foo', make_project=False): # noqa: S107 if not username: username = display_name.lower().replace(' ', '-') @@ -328,7 +331,7 @@ def create_user(display_name, username=None, password='foo', make_project=False) em = EmailAddress.get(**kw) em.confirmed = True em.set_nonce_hash() - user.set_pref('email_address',email) + user.set_pref('email_address', email) fast_set_pwd(user, password) return user diff --git a/Allura/ldap-setup.py b/Allura/ldap-setup.py index e913430483..428f04078b 100644 --- a/Allura/ldap-setup.py +++ b/Allura/ldap-setup.py @@ -110,6 +110,7 @@ def tempfile(template, values): yield name os.remove(name) + backend_ldif = string.Template(''' # Load dynamic backend modules dn: cn=module,cn=config diff --git a/Allura/ldap-userconfig.py b/Allura/ldap-userconfig.py index dd1c270c08..18fa323846 100644 --- a/Allura/ldap-userconfig.py +++ b/Allura/ldap-userconfig.py @@ -55,5 +55,6 @@ def upload(uname, pubkey): os.chown(keyfile, u.pw_uid, g.gr_gid) os.chmod(keyfile, 0o600) + if __name__ == '__main__': main() diff --git a/Allura/setup.py b/Allura/setup.py index 63613d66a4..e32efdeb0f 100644 --- a/Allura/setup.py +++ b/Allura/setup.py @@ -26,7 +26,7 @@ ''' setup( name='Allura', - version=__version__, # noqa: F821 + version=__version__, # noqa: F821 description='Base distribution of the Allura development platform', long_description=PROJECT_DESCRIPTION, author='Allura Team', diff --git a/AlluraTest/alluratest/smtp_debug.py b/AlluraTest/alluratest/smtp_debug.py index 65be0a1622..377754bed4 100644 --- a/AlluraTest/alluratest/smtp_debug.py +++ b/AlluraTest/alluratest/smtp_debug.py @@ -22,4 +22,4 @@ class BetterDebuggingServer(DebuggingServer): def process_message(self, peer, mailfrom, rcpttos, data, **kwargs): print('TO: ' + ', '.join(rcpttos)) - super().process_message(peer, mailfrom, rcpttos, data) \ No newline at end of file + super().process_message(peer, mailfrom, rcpttos, data) diff --git a/AlluraTest/alluratest/test_syntax.py b/AlluraTest/alluratest/test_syntax.py index 8124d76846..faebde60d6 100644 --- a/AlluraTest/alluratest/test_syntax.py +++ b/AlluraTest/alluratest/test_syntax.py @@ -41,4 +41,3 @@ def test_run_precommit(): code, outputs = run(cmd, dir=os.environ.get('ALLURA_GIT_DIR')) if code != 0: raise Exception(f'pre-commit failed to run: {outputs[0].decode()} {outputs[1].decode()}') - diff --git a/ForgeActivity/forgeactivity/tests/functional/test_root.py b/ForgeActivity/forgeactivity/tests/functional/test_root.py index 41d5256f66..8b8443e890 100644 --- a/ForgeActivity/forgeactivity/tests/functional/test_root.py +++ b/ForgeActivity/forgeactivity/tests/functional/test_root.py @@ -54,7 +54,7 @@ def test_index_disabled(self): def test_anon_read(self): r = self.app.get('/u/test-user-1', extra_environ={'username': '*anonymous'}).follow() - assert r.html.select('div.profile-section.tools a[href="/u/test-user-1/activity/"]'),\ + assert r.html.select('div.profile-section.tools a[href="/u/test-user-1/activity/"]'), \ 'No Activity tool in top nav' @td.with_tool('test', 'activity') diff --git a/ForgeBlog/forgeblog/tests/test_commands.py b/ForgeBlog/forgeblog/tests/test_commands.py index 4a1d797ecb..174031c508 100644 --- a/ForgeBlog/forgeblog/tests/test_commands.py +++ b/ForgeBlog/forgeblog/tests/test_commands.py @@ -94,7 +94,7 @@ def test_pull_rss_feeds(urlopen): Test html summary 2003-12-13T18:30:02Z - '''+ html_in_feed + b''' + ''' + html_in_feed + b''' ''') diff --git a/ForgeBlog/forgeblog/widgets.py b/ForgeBlog/forgeblog/widgets.py index 3aa74a13d3..c0445369c6 100644 --- a/ForgeBlog/forgeblog/widgets.py +++ b/ForgeBlog/forgeblog/widgets.py @@ -39,7 +39,7 @@ def fields(self): return ew_core.NameList([ ew.TextField(name='title', validator=v.UnicodeString(not_empty=True, - messages={'empty': "You must provide a Title"}), + messages={'empty': "You must provide a Title"}), attrs=dict(placeholder='Enter your title here', title='Enter your title here', style='width: 425px')), diff --git a/ForgeChat/forgechat/model/chat.py b/ForgeChat/forgechat/model/chat.py index 03d1c0905e..ba72930b83 100644 --- a/ForgeChat/forgechat/model/chat.py +++ b/ForgeChat/forgechat/model/chat.py @@ -93,4 +93,5 @@ def sender_short(self): def timestamp_hour(self): return self.timestamp.strftime('%H:%M:%S') + Mapper.compile_all() diff --git a/ForgeDiscussion/forgediscussion/widgets/forum_widgets.py b/ForgeDiscussion/forgediscussion/widgets/forum_widgets.py index 1909b6d899..ed461f9133 100644 --- a/ForgeDiscussion/forgediscussion/widgets/forum_widgets.py +++ b/ForgeDiscussion/forgediscussion/widgets/forum_widgets.py @@ -95,7 +95,7 @@ class ModerateThread(CsrfForm): submit_text = 'Save Changes' class fields(ew_core.NameList): - subject = ew.InputField(label='Change subject:', attrs={'style':'width: 50%'}) + subject = ew.InputField(label='Change subject:', attrs={'style': 'width: 50%'}) discussion = _ForumSelector(label='Move to different forum:') flags = ew.CheckboxSet(label='Options', options=['Sticky', 'Announcement']) diff --git a/ForgeFeedback/forgefeedback/feedback_main.py b/ForgeFeedback/forgefeedback/feedback_main.py index 07b937e27f..21178ef5fb 100644 --- a/ForgeFeedback/forgefeedback/feedback_main.py +++ b/ForgeFeedback/forgefeedback/feedback_main.py @@ -131,7 +131,7 @@ def index(self, **kw): @expose('jinja:forgefeedback:templates/feedback/index.html') def get_review_list(self, **kw): self.review_list = Feedback.query.find({'project_id': c.project._id})\ - .sort('created_date', pymongo.DESCENDING).all() + .sort('created_date', pymongo.DESCENDING).all() return self.review_list """ The new feedback given by the logged in user which includes @@ -163,8 +163,8 @@ def new_feedback(self, **kw): @expose('jinja:forgefeedback:templates/feedback/edit_feedback.html') def edit_feedback(self, **kw): self.review = Feedback.query.find( - {'reported_by_id': c.user._id, 'project_id': c.project._id} - ).first() + {'reported_by_id': c.user._id, 'project_id': c.project._id} + ).first() return dict(description=self.review.description, rating=self.review.rating) @@ -192,7 +192,7 @@ def edit_user_review(self, description=None, rating=None, **kw): def delete_feedback(self, **kw): user_review = Feedback.query.find( {'reported_by_id': c.user._id, 'project_id': c.project._id} - ).first() + ).first() if user_review: Feedback.query.remove(dict( {'reported_by_id': c.user._id, 'project_id': c.project._id})) @@ -216,6 +216,7 @@ def feedback_check(self, description=None): """ This method count the number of stars finds their sum and calculates the average of all the star rating count """ + def getRating(self, **kw): onestarcount = TM.Feedback.query.find( {'rating': '1', 'project_id': c.project._id}).count() diff --git a/ForgeFeedback/forgefeedback/tests/functional/test_root.py b/ForgeFeedback/forgefeedback/tests/functional/test_root.py index b751eb7a38..902a5199f0 100644 --- a/ForgeFeedback/forgefeedback/tests/functional/test_root.py +++ b/ForgeFeedback/forgefeedback/tests/functional/test_root.py @@ -20,7 +20,6 @@ from alluratest.controller import TestController - class TestFeedback(TestController): def test_feedback(self): diff --git a/ForgeFeedback/setup.py b/ForgeFeedback/setup.py index 241608e899..196098a9a9 100644 --- a/ForgeFeedback/setup.py +++ b/ForgeFeedback/setup.py @@ -47,7 +47,3 @@ """, ) - - - - diff --git a/ForgeFiles/forgefiles/files_main.py b/ForgeFiles/forgefiles/files_main.py index 7c91a6896a..9279014e14 100755 --- a/ForgeFiles/forgefiles/files_main.py +++ b/ForgeFiles/forgefiles/files_main.py @@ -88,7 +88,6 @@ def has_linked_download(self): def get_parent_folders(linked_file_object=None): - '''Returns the list of the parent folders for the current file or folder''' parent_folder = linked_file_object.parent_folder if linked_file_object else None @@ -108,7 +107,6 @@ def _check_security(self): @expose('jinja:forgefiles:templates/files.html') def index(self): - '''Index method for the Root controller''' require_access(c.app, 'read') @@ -136,7 +134,6 @@ def index(self): subscribed=subscribed, parents=parents) def get_parent_folder_url(self, parent_folder_id): - ''' Returns the url,parent_folder and id of parent_folder object if object is there''' if (parent_folder_id == 'None') or (not parent_folder_id): @@ -152,7 +149,6 @@ def get_parent_folder_url(self, parent_folder_id): @require_post() @expose() def create_folder(self, parent_folder_id=None, folder_name=None): - '''Controller method for creating a folder. The folder is stored in UploadFolder collection''' require_access(c.app, 'create') @@ -179,7 +175,6 @@ def create_folder(self, parent_folder_id=None, folder_name=None): @require_post() @expose() def upload_file(self, parent_folder_id=None, file_upload=None, filename=None): - '''Controller method for creating a folder. The folder is stored in UploadFolder collection''' require_access(c.app, 'create') @@ -212,7 +207,6 @@ def upload_file(self, parent_folder_id=None, file_upload=None, filename=None): @require_post() @expose() def delete_file(self, file_id=None): - '''Controller method to delete a file''' file_object = UploadFiles.query.get(_id=ObjectId(file_id), app_config_id=c.app.config._id) @@ -233,7 +227,6 @@ def delete_file(self, file_id=None): return redirect(url) def delete_file_from_db(self, file_id=None): - '''Method to delete a file from db''' file_object = UploadFiles.query.get(_id=ObjectId(file_id), app_config_id=c.app.config._id) @@ -241,7 +234,6 @@ def delete_file_from_db(self, file_id=None): file_object.delete() def delete_folder_recursively(self, folder_id): - '''This method is called recursively to delete folder in a hierarchy''' sub_file_objects = UploadFiles.query.find(dict({ @@ -258,7 +250,6 @@ def delete_folder_recursively(self, folder_id): @require_post() @expose('jinja:forgefiles:templates/files.html') def delete_folder(self, folder_id=None): - '''Controller method to delete a folder''' folder_object = UploadFolder.query.get(_id=ObjectId(folder_id), app_config_id=c.app.config._id) @@ -280,7 +271,6 @@ def delete_folder(self, folder_id=None): @require_post() @expose() def link_file(self, file_id=None, status=None): - '''Controller method to link a file to the download button''' linkable_file_object = UploadFiles.query.get(_id=ObjectId(file_id), app_config_id=c.app.config._id) @@ -297,7 +287,6 @@ def link_file(self, file_id=None, status=None): @expose() def download_file(self, filename=None): - '''Controller method to download a file''' if filename: @@ -324,7 +313,6 @@ def download_file(self, filename=None): @require_post() @expose() def edit_folder(self, folder_id=None, folder_name=None): - '''Controller method to edit the folder name''' url = c.app.url @@ -342,7 +330,6 @@ def edit_folder(self, folder_id=None, folder_name=None): @require_post() @expose() def edit_file(self, file_id=None, file_name=None): - '''Controller method to edit the file name''' url = c.app.url @@ -362,7 +349,6 @@ def edit_file(self, file_id=None, file_name=None): @require_post() @expose() def publish_folder(self, folder_id=None, remarks=None): - '''Controller which publishes the folder. It send update about the publishing of the folder.''' folder_object = UploadFolder.query.get(_id=ObjectId(folder_id), app_config_id=c.app.config._id) @@ -409,7 +395,6 @@ def publish_folder(self, folder_id=None, remarks=None): @require_post() @expose() def disable_folder(self, folder_id=None, status=None): - '''Controller method to disable the folder.''' folder_object = UploadFolder.query.get(_id=ObjectId(folder_id), app_config_id=c.app.config._id) @@ -440,7 +425,6 @@ def disable_folder(self, folder_id=None, status=None): @require_post() @expose() def disable_file(self, file_id=None, status=None): - '''Controller method to disable the file.''' file_object = UploadFiles.query.get(_id=ObjectId(file_id), app_config_id=c.app.config._id) @@ -461,7 +445,6 @@ def disable_file(self, file_id=None, status=None): @expose('json:') @require_post() def subscribe(self, subscribe=None, unsubscribe=None): - '''Controller method that subscribes an user to the files plugin.''' if subscribe: diff --git a/ForgeFiles/forgefiles/model/files.py b/ForgeFiles/forgefiles/model/files.py index 43d0af0afb..ee421a4b9f 100755 --- a/ForgeFiles/forgefiles/model/files.py +++ b/ForgeFiles/forgefiles/model/files.py @@ -146,7 +146,6 @@ class UploadFiles(File): thumbnail_size = (255, 255) ArtifactType = Upload - class __mongometa__: name = 'upload_files' session = project_orm_session @@ -181,13 +180,11 @@ def before_save(data): @property def artifact(self): - '''Returns the Artifact object''' return self.ArtifactType.query.get(_id=self.artifact_id) def url(self): - '''Returns the URL of the uploaded file''' parent_folder = self.parent_folder diff --git a/ForgeFiles/forgefiles/tests/__init__.py b/ForgeFiles/forgefiles/tests/__init__.py index 77505f1c35..144e29886a 100644 --- a/ForgeFiles/forgefiles/tests/__init__.py +++ b/ForgeFiles/forgefiles/tests/__init__.py @@ -14,4 +14,3 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. - diff --git a/ForgeFiles/forgefiles/tests/functional/__init__.py b/ForgeFiles/forgefiles/tests/functional/__init__.py index 77505f1c35..144e29886a 100644 --- a/ForgeFiles/forgefiles/tests/functional/__init__.py +++ b/ForgeFiles/forgefiles/tests/functional/__init__.py @@ -14,4 +14,3 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. - diff --git a/ForgeFiles/forgefiles/tests/functional/test_root.py b/ForgeFiles/forgefiles/tests/functional/test_root.py index fb38b79247..4455902708 100644 --- a/ForgeFiles/forgefiles/tests/functional/test_root.py +++ b/ForgeFiles/forgefiles/tests/functional/test_root.py @@ -132,7 +132,7 @@ def upload_file(self): path = dir.write('myfile.txt', b'Testing Upload') with open(path, 'rb') as f: file_upload = [('file_upload', 'myfile.txt', f.read())] - filename_dict = {'filename':'myfile.txt'} + filename_dict = {'filename': 'myfile.txt'} self.app.post('/p/test/files/upload_file', filename_dict, upload_files=file_upload) file_object = UploadFiles.query.get(filename='myfile.txt') dir.cleanup() diff --git a/ForgeFiles/forgefiles/tests/model/__init__.py b/ForgeFiles/forgefiles/tests/model/__init__.py index 820aea3617..1b0a08cb60 100644 --- a/ForgeFiles/forgefiles/tests/model/__init__.py +++ b/ForgeFiles/forgefiles/tests/model/__init__.py @@ -48,4 +48,3 @@ def setup_method(self, method): def teardown_method(self, method): ThreadLocalODMSession.close_all() - diff --git a/ForgeGit/forgegit/tests/test_tasks.py b/ForgeGit/forgegit/tests/test_tasks.py index 48ab369bd2..96297b3bf8 100644 --- a/ForgeGit/forgegit/tests/test_tasks.py +++ b/ForgeGit/forgegit/tests/test_tasks.py @@ -99,4 +99,3 @@ def test_refresh_last_commits(self): # mostly just making sure nothing errored, but here's at least one thing we can assert: assert repo.status == 'ready' - diff --git a/ForgeImporters/forgeimporters/forge/discussion.py b/ForgeImporters/forgeimporters/forge/discussion.py index 61db6253da..50dd9d0b6b 100644 --- a/ForgeImporters/forgeimporters/forge/discussion.py +++ b/ForgeImporters/forgeimporters/forge/discussion.py @@ -68,10 +68,10 @@ def index(self, **kw): def create(self, discussions_json, mount_point, mount_label, **kw): if self.importer.enforce_limit(c.project): save_importer_upload( - c.project, - 'discussions.json', - json.dumps(discussions_json) - ) + c.project, + 'discussions.json', + json.dumps(discussions_json) + ) self.importer.post(mount_point=mount_point, mount_label=mount_label) flash('Discussion import has begun. Your new discussion will be available when the import is complete') else: @@ -113,15 +113,15 @@ def import_tool(self, project, user, mount_point=None, mount_label=None, **kw): for forum_json in discussion_json['forums']: new_forum = dict( - app_config_id=app.config._id, - shortname=forum_json['shortname'], - description=forum_json['description'], - name=forum_json['name'], - create='on', - parent='', - members_only=False, - anon_posts=False, - monitoring_email=None, + app_config_id=app.config._id, + shortname=forum_json['shortname'], + description=forum_json['description'], + name=forum_json['name'], + create='on', + parent='', + members_only=False, + anon_posts=False, + monitoring_email=None, ) forum = utils.create_forum(app, new_forum=new_forum) @@ -194,19 +194,19 @@ def add_posts(self, thread, posts, app): break p = thread.add_post( - subject=post_json['subject'], - text=self.annotate_text(post_json['text'], user, username), - timestamp=timestamp, - ignore_security=True, - parent_id=parent_id + subject=post_json['subject'], + text=self.annotate_text(post_json['text'], user, username), + timestamp=timestamp, + ignore_security=True, + parent_id=parent_id ) if ("last_edited" in post_json) and (post_json["last_edited"] is not None): p.last_edit_date = parse(post_json["last_edited"]) p.add_multiple_attachments( - [File(a["url"]) for a in post_json["attachments"]] - ) + [File(a["url"]) for a in post_json["attachments"]] + ) if slug != '': created_posts.append({slug: p}) diff --git a/ForgeImporters/forgeimporters/github/tests/test_utils.py b/ForgeImporters/forgeimporters/github/tests/test_utils.py index f8c45cd02e..c2ace04293 100644 --- a/ForgeImporters/forgeimporters/github/tests/test_utils.py +++ b/ForgeImporters/forgeimporters/github/tests/test_utils.py @@ -51,7 +51,7 @@ def test_convert_user_repo_sha(self): text = 'user/p@16c999e8c71134401a78d4d46435517b2271d6ac' result = self.conv.convert(text) assert (result == '[user/p@16c999]' - '(https://github.com/user/p/commit/16c999e8c71134401a78d4d46435517b2271d6ac)') + '(https://github.com/user/p/commit/16c999e8c71134401a78d4d46435517b2271d6ac)') def test_convert_ticket(self): text = 'Ticket #1' diff --git a/ForgeImporters/forgeimporters/github/tests/test_wiki.py b/ForgeImporters/forgeimporters/github/tests/test_wiki.py index 647b1b2d55..d3b53dbdae 100644 --- a/ForgeImporters/forgeimporters/github/tests/test_wiki.py +++ b/ForgeImporters/forgeimporters/github/tests/test_wiki.py @@ -15,7 +15,7 @@ # specific language governing permissions and limitations # under the License. -from unittest import skipIf +from unittest import skipIf from mock import Mock, patch, call from ming.odm import ThreadLocalODMSession import git diff --git a/ForgeImporters/forgeimporters/tests/forge/test_discussion.py b/ForgeImporters/forgeimporters/tests/forge/test_discussion.py index 70464f5e55..bcbed57e62 100644 --- a/ForgeImporters/forgeimporters/tests/forge/test_discussion.py +++ b/ForgeImporters/forgeimporters/tests/forge/test_discussion.py @@ -113,19 +113,19 @@ def test_import_tool_with_general_discussion(self, tlos, h, session, m, g, c): utils.create_forum.assert_called_once_with(app, new_forum=new_forum) forum.get_discussion_thread( - dict(headers=dict(Subject=_json["forums"][0]["threads"][0]["subject"]))) + dict(headers=dict(Subject=_json["forums"][0]["threads"][0]["subject"]))) importer.add_posts.assert_called_once_with( - thread1, - _json["forums"][0]["threads"][0]["posts"], - app + thread1, + _json["forums"][0]["threads"][0]["posts"], + app ) m.AuditLog.log.assert_called_once_with( - "import tool mount_point from exported Allura JSON", - project=project, - user=user, - url='foo' - ) + "import tool mount_point from exported Allura JSON", + project=project, + user=user, + url='foo' + ) g.post_event.assert_called_once_with("project_updated") @mock.patch.object(discussion, 'c') @@ -160,10 +160,10 @@ def test_import_tool_unicode(self, tlos, h, session, m, g, c): "slug": "0e0e", "subject": "post with un\u00ef\u00e7\u00f8\u2202\u00e9" }], - "page": None, - "subject": "post with un\u00ef\u00e7\u00f8\u2202\u00e9" - }] + "page": None, + "subject": "post with un\u00ef\u00e7\u00f8\u2202\u00e9" }] + }] } importer._load_json = mock.Mock(return_value=_json) @@ -202,7 +202,7 @@ def test_import_tool_unicode(self, tlos, h, session, m, g, c): utils.create_forum.assert_called_once_with(app, new_forum=new_forum) forum.get_discussion_thread.assert_called_once_with(dict( headers=dict(Subject=_json["forums"][0]["threads"][0]["subject"]) - )) + )) importer.get_user.assert_called_once_with('admin1') @@ -220,9 +220,9 @@ def test_import_tool_unicode(self, tlos, h, session, m, g, c): parent_id=None ) importer.annotate_text.assert_called_once_with( - post["text"], - admin, - post["author"] + post["text"], + admin, + post["author"] ) p.add_multiple_attachments.assert_called_once_with([]) @@ -332,29 +332,29 @@ def test_import_tool_multiple_threads(self, tlos, h, session, m, g, c): "subject": "Thread0", "posts": [] }, - { + { "page": None, "subject": "Thread1", "posts": [] - }, - { + }, + { "page": None, "subject": "Thread2", "posts": [] - }, - { + }, + { "page": None, "subject": "Thread3", "posts": [] - }, - { + }, + { "page": None, "subject": "Thread4", "posts": [] - } - ]} - ] - } + } + ]} + ] + } importer._load_json = mock.Mock(return_value=_json) importer.add_posts = mock.Mock() @@ -380,10 +380,10 @@ def test_import_tool_multiple_threads(self, tlos, h, session, m, g, c): importer.import_tool(project, user, 'mount_point', 'mount_label') project.install_app.assert_called_once_with( - 'discussion', - 'mount_point', - 'mount_label', - import_id={'source': 'Allura'} + 'discussion', + 'mount_point', + 'mount_label', + import_id={'source': 'Allura'} ) h.push_config.assert_called_once_with(c, app=app) @@ -422,7 +422,7 @@ def test_import_tool_forum_import_id(self, tlos, h, session, m, g, c): "name": "General Discussion", "import_id": import_id, "threads": [] - }] + }] } importer._load_json = mock.Mock(return_value=_json) @@ -492,8 +492,8 @@ def test_import_tool_thread_import_id(self, tlos, h, session, m, g, c): "posts": [], "subject": "Thread", "import_id": import_id - }] }] + }] } importer._load_json = mock.Mock(return_value=_json) @@ -532,8 +532,8 @@ def test_import_tool_thread_import_id(self, tlos, h, session, m, g, c): "limit": None, "posts": [], "subject": "Thread", - }] }] + }] } importer._load_json = mock.Mock(return_value=_json) @@ -635,7 +635,7 @@ def test_import_tool_missing_keys(self, tlos, h, session, m, g, c): "description": "Description of forum", "name": "General Discussion", "threads": [{ - "posts": [] + "posts": [] }] }] } @@ -680,11 +680,11 @@ def test_add_posts(self, h, c): importer.get_user.assert_called_once_with('admin1') h.push_config.assert_called_once_with(c, user=user, app=app) thread.add_post.assert_called_once_with( - subject=_json[0]['subject'], - text='foo', - timestamp=parse(_json[0]['timestamp']), - ignore_security=True, - parent_id=None + subject=_json[0]['subject'], + text='foo', + timestamp=parse(_json[0]['timestamp']), + ignore_security=True, + parent_id=None ) post.add_multiple_attachments.assert_called_once_with([]) @@ -937,54 +937,54 @@ def test_add_posts_nested_posts(self, h, c, File): _json = [ { - "attachments": [], - "author": "admin1", - "timestamp": "2020-01-29 22:39:31.483000", - "text": "hi", - "slug": "0d1d", - "subject": "topic with lots of replies" + "attachments": [], + "author": "admin1", + "timestamp": "2020-01-29 22:39:31.483000", + "text": "hi", + "slug": "0d1d", + "subject": "topic with lots of replies" }, { - "attachments": [], - "author": "admin1", - "timestamp": "2020-01-29 22:39:43.525000", - "text": "hello", - "slug": "0d1d/d421", - "subject": "topic with lots of replies" + "attachments": [], + "author": "admin1", + "timestamp": "2020-01-29 22:39:43.525000", + "text": "hello", + "slug": "0d1d/d421", + "subject": "topic with lots of replies" }, { - "attachments": [], - "author": "admin1", - "timestamp": "2020-01-29 22:39:50.086000", - "text": "goodbye", - "slug": "0d1d/d421/f37d", - "subject": "topic with lots of replies" + "attachments": [], + "author": "admin1", + "timestamp": "2020-01-29 22:39:50.086000", + "text": "goodbye", + "slug": "0d1d/d421/f37d", + "subject": "topic with lots of replies" }, { - "attachments": [], - "author": "admin1", - "timestamp": "2020-01-29 22:42:13.740000", - "text": "hi again", - "slug": "012f", - "subject": "topic with lots of replies" + "attachments": [], + "author": "admin1", + "timestamp": "2020-01-29 22:42:13.740000", + "text": "hi again", + "slug": "012f", + "subject": "topic with lots of replies" }, { - "attachments": [], - "author": "user02", - "timestamp": "2020-01-29 22:42:51.645000", - "text": "hi there", - "slug": "012f/211a", - "subject": "topic with lots of replies" + "attachments": [], + "author": "user02", + "timestamp": "2020-01-29 22:42:51.645000", + "text": "hi there", + "slug": "012f/211a", + "subject": "topic with lots of replies" }, { - "attachments": [], - "author": "user02", - "timestamp": "2020-01-29 22:42:58.478000", - "text": "hi here", - "slug": "0d1d/00a0", - "subject": "topic with lots of replies" + "attachments": [], + "author": "user02", + "timestamp": "2020-01-29 22:42:58.478000", + "text": "hi here", + "slug": "0d1d/00a0", + "subject": "topic with lots of replies" } - ] + ] importer.add_posts(thread, _json, app) diff --git a/ForgeImporters/forgeimporters/tests/forge/test_tracker.py b/ForgeImporters/forgeimporters/tests/forge/test_tracker.py index 7cb5e1741a..9f5bff000c 100644 --- a/ForgeImporters/forgeimporters/tests/forge/test_tracker.py +++ b/ForgeImporters/forgeimporters/tests/forge/test_tracker.py @@ -299,7 +299,7 @@ def test_process_comments(self, c, File): importer.process_comments(ticket, comments) assert importer.get_user.call_args_list == \ - [mock.call('a1'), mock.call('a2')] + [mock.call('a1'), mock.call('a2')] assert importer.annotate.call_args_list == [ mock.call('t1', author, 'a1'), mock.call('t2', author, 'a2'), @@ -341,7 +341,7 @@ def setup_method(self, method): super().setup_method(method) from forgetracker.tracker_main import TrackerAdminController TrackerAdminController._importer = \ - tracker.ForgeTrackerImportController(tracker.ForgeTrackerImporter()) + tracker.ForgeTrackerImportController(tracker.ForgeTrackerImporter()) @with_tracker def test_index(self): diff --git a/ForgeImporters/forgeimporters/tests/github/functional/test_github.py b/ForgeImporters/forgeimporters/tests/github/functional/test_github.py index d9ed29b8f1..be2e77130f 100644 --- a/ForgeImporters/forgeimporters/tests/github/functional/test_github.py +++ b/ForgeImporters/forgeimporters/tests/github/functional/test_github.py @@ -91,7 +91,6 @@ def test_oauth_flow(self, session, oauth): json={'access_token': 'abc'}, timeout=10) - def test_project_import_login_required(self): r = self.app.get('/p/import_project/github/', extra_environ=dict(username='*anonymous')) assert r.location is None diff --git a/ForgeImporters/forgeimporters/tests/github/test_tracker.py b/ForgeImporters/forgeimporters/tests/github/test_tracker.py index 70164494c0..28c3a4e74c 100644 --- a/ForgeImporters/forgeimporters/tests/github/test_tracker.py +++ b/ForgeImporters/forgeimporters/tests/github/test_tracker.py @@ -97,7 +97,7 @@ def test_process_fields(self): importer.process_fields(extractor, ticket, issue) assert ticket.summary == 'title' assert ticket.description == \ - '*Originally created by:* [creator](https://github.com/creator)\n*Originally owned by:* [owner](https://github.com/owner)\n\nhello' + '*Originally created by:* [creator](https://github.com/creator)\n*Originally owned by:* [owner](https://github.com/owner)\n\nhello' assert ticket.status == 'New' assert ticket.created_date == 'created_at' assert ticket.mod_date == 'updated_at' diff --git a/ForgeImporters/forgeimporters/tests/test_base.py b/ForgeImporters/forgeimporters/tests/test_base.py index 7467613c95..022c36c23b 100644 --- a/ForgeImporters/forgeimporters/tests/test_base.py +++ b/ForgeImporters/forgeimporters/tests/test_base.py @@ -150,7 +150,7 @@ def test_tool_importers(self, iep): pi = base.ProjectImporter(mock.Mock(name='neighborhood')) pi.source = 'foo' assert pi.tool_importers == \ - {'ep1': eps[0].lv, 'ep3': eps[2].lv} + {'ep1': eps[0].lv, 'ep3': eps[2].lv} iep.assert_called_once_with('allura.importers') @mock.patch.object(base.ToolImporter, 'by_name') @@ -307,7 +307,7 @@ def test_multiple(self, by_name): with pytest.raises(Invalid) as cm: self.tv.to_python(['value1', 'value2', 'value3']) assert cm.value.msg == \ - 'Invalid tools selected: value1, value3' + 'Invalid tools selected: value1, value3' assert by_name.call_args_list == [ mock.call('value1'), mock.call('value2'), diff --git a/ForgeImporters/forgeimporters/trac/tests/test_tickets.py b/ForgeImporters/forgeimporters/trac/tests/test_tickets.py index 9cdadba1cc..5da9166a18 100644 --- a/ForgeImporters/forgeimporters/trac/tests/test_tickets.py +++ b/ForgeImporters/forgeimporters/trac/tests/test_tickets.py @@ -18,7 +18,7 @@ import json import os -from unittest import skipIf +from unittest import skipIf import pytest from mock import Mock, patch @@ -142,9 +142,9 @@ def test_create(self, import_tool, head): assert \ 'mylabel' == import_tool.post.call_args[1]['mount_label'] assert '{"orig_user": "new_user"}' == \ - import_tool.post.call_args[1]['user_map'] + import_tool.post.call_args[1]['user_map'] assert 'http://example.com/trac/url/' == \ - import_tool.post.call_args[1]['trac_url'] + import_tool.post.call_args[1]['trac_url'] @with_tracker @patch('forgeimporters.trac.requests.head') @@ -192,6 +192,7 @@ def test_url_ticket_import_fail(self, import_tool, head): r = self.app.post('/p/test/admin/ext/import/trac-tickets/create', params, status=200) assert 'Invalid URL' in r.text + class TestTracImportSupport: def test_link_processing(self): @@ -288,7 +289,7 @@ def test_list(self): ticket = TM.Ticket.query.get(app_config_id=c.app.config._id, ticket_num=390) assert 'To reproduce: \n\\- open an mzML file' in \ - ticket.description + ticket.description assert 'duplicate of: \n\\- [#316](316 "defect: SpectraViewWidget is' in \ - ticket.discussion_thread.find_posts()[0].text + ticket.discussion_thread.find_posts()[0].text assert 'will crash TOPPView.' in ticket.description diff --git a/ForgeSVN/forgesvn/tests/functional/test_auth.py b/ForgeSVN/forgesvn/tests/functional/test_auth.py index 7a64dc229a..b235d7688b 100644 --- a/ForgeSVN/forgesvn/tests/functional/test_auth.py +++ b/ForgeSVN/forgesvn/tests/functional/test_auth.py @@ -39,7 +39,7 @@ def test_refresh_repo(self): r = self.app.get('/auth/refresh_repo/p/test/src/') assert (r.text == - ' refresh queued.\n') + ' refresh queued.\n') class TestSVNUserPermissions(TestController): diff --git a/ForgeSVN/forgesvn/tests/model/test_repository.py b/ForgeSVN/forgesvn/tests/model/test_repository.py index f1e95c18e1..631deea82f 100644 --- a/ForgeSVN/forgesvn/tests/model/test_repository.py +++ b/ForgeSVN/forgesvn/tests/model/test_repository.py @@ -217,7 +217,7 @@ def test_clone(self, post_event): os.path.join(g.tmpdir, 'testsvn/hooks/post-commit'), os.X_OK) with open(os.path.join(g.tmpdir, 'testsvn/hooks/post-commit')) as f: c = f.read() - assert 'curl -s http://localhost/auth/refresh_repo/p/test/src/\n' in c + assert 'curl -s http://localhost/auth/refresh_repo/p/test/src/\n' in c assert 'exec $DIR/post-commit-user "$@"\n' in c repo.refresh(notify=False) diff --git a/ForgeTracker/forgetracker/import_support.py b/ForgeTracker/forgetracker/import_support.py index abfe426bd0..8c3ae4252e 100644 --- a/ForgeTracker/forgetracker/import_support.py +++ b/ForgeTracker/forgetracker/import_support.py @@ -220,7 +220,7 @@ def make_artifact(self, ticket_dict): owner = '*Originally owned by:* {}\n'.format( h.really_unicode(ticket_dict['assigned_to'])) remapped['description'] = '{}{}{}{}'.format(creator, owner, - '\n' if creator or owner else '', description) + '\n' if creator or owner else '', description) ticket_num = ticket_dict['id'] existing_ticket = TM.Ticket.query.get(app_config_id=c.app.config._id, diff --git a/ForgeTracker/forgetracker/search.py b/ForgeTracker/forgetracker/search.py index d215cc6312..4c6ed7838e 100644 --- a/ForgeTracker/forgetracker/search.py +++ b/ForgeTracker/forgetracker/search.py @@ -41,7 +41,7 @@ def query_filter_choices(arg=None, fq=[]): 'project_id_s:%s' % c.project._id, 'mount_point_s:%s' % c.app.config.options.mount_point, 'type_s:Ticket', - ] + fq, + ] + fq, 'rows': 0, } params.update(FACET_PARAMS) diff --git a/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py b/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py index f580797fbd..2f886a01fe 100644 --- a/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py +++ b/ForgeTracker/forgetracker/tests/unit/test_ticket_model.py @@ -230,7 +230,7 @@ def test_feed(self): assert f.pubdate == datetime(2012, 10, 29, 9, 57, 21, 465000) assert f.title == 'test ticket' assert (f.description == - '

test description

') + '

test description

') @td.with_tool('test', 'Tickets', 'bugs', username='test-user') @td.with_tool('test', 'Tickets', 'bugs2', username='test-user') diff --git a/ForgeTracker/forgetracker/widgets/ticket_search.py b/ForgeTracker/forgetracker/widgets/ticket_search.py index effa98f3b0..e14ebf7da0 100644 --- a/ForgeTracker/forgetracker/widgets/ticket_search.py +++ b/ForgeTracker/forgetracker/widgets/ticket_search.py @@ -22,7 +22,6 @@ from allura.lib.widgets import forms - class TicketSearchResults(ew_core.SimpleForm): template = 'jinja:forgetracker:templates/tracker_widgets/ticket_search_results.html' defaults = dict( diff --git a/ForgeUserStats/forgeuserstats/tests/test_model.py b/ForgeUserStats/forgeuserstats/tests/test_model.py index 9842cc642c..fe2aa759ed 100644 --- a/ForgeUserStats/forgeuserstats/tests/test_model.py +++ b/ForgeUserStats/forgeuserstats/tests/test_model.py @@ -472,10 +472,10 @@ def test_count_loc(self, unified_diff): ) stats.addCommit(newcommit, commit_datetime, project) assert stats.general[0].commits[0] == \ - {'lines': 3, 'number': 1, 'language': None} + {'lines': 3, 'number': 1, 'language': None} unified_diff.reset_mock() with h.push_config(config, **{'userstats.count_lines_of_code': 'false'}): stats.addCommit(newcommit, commit_datetime, project) assert stats.general[0].commits[0] == \ - {'lines': 3, 'number': 2, 'language': None} + {'lines': 3, 'number': 2, 'language': None} assert not unified_diff.called diff --git a/ForgeWiki/forgewiki/model/wiki.py b/ForgeWiki/forgewiki/model/wiki.py index 5b6d0e6820..712857eafc 100644 --- a/ForgeWiki/forgewiki/model/wiki.py +++ b/ForgeWiki/forgewiki/model/wiki.py @@ -297,4 +297,5 @@ class __mongometa__: attachment_type = FieldProperty(str, if_missing='WikiAttachment') + Mapper.compile_all() diff --git a/ForgeWiki/forgewiki/tests/test_models.py b/ForgeWiki/forgewiki/tests/test_models.py index 9a70504f2e..58fa3cb28a 100644 --- a/ForgeWiki/forgewiki/tests/test_models.py +++ b/ForgeWiki/forgewiki/tests/test_models.py @@ -42,6 +42,7 @@ def test_version_race(self): page.commit() lock = Lock() + def run(n): setup_global_objects() for i in range(10): diff --git a/conftest.py b/conftest.py index 020af6a936..b4fc8ce7a4 100644 --- a/conftest.py +++ b/conftest.py @@ -17,6 +17,8 @@ import pytest # should get rid of this once this issue is fixed https://github.com/TurboGears/tg2/issues/136 + + @pytest.fixture(autouse=True, scope='session') def tg_context_patch(): from tg import ( @@ -37,4 +39,3 @@ def tg_context_patch(): translator.__dict__['_is_coroutine'] = False url.__dict__['_is_coroutine'] = False config.__dict__['_is_coroutine'] = False - \ No newline at end of file diff --git a/scripts/changelog.py b/scripts/changelog.py index 6d4c2a7e97..d5e01456f1 100755 --- a/scripts/changelog.py +++ b/scripts/changelog.py @@ -74,5 +74,6 @@ def print_changelog(version, summaries, changes_without_tickets): for change in changes_without_tickets: print(f" * {six.ensure_text(change)}") + if __name__ == '__main__': main() diff --git a/scripts/migrations/013-update-ordinals.py b/scripts/migrations/013-update-ordinals.py index 666696327a..8bdeff1ebf 100644 --- a/scripts/migrations/013-update-ordinals.py +++ b/scripts/migrations/013-update-ordinals.py @@ -69,5 +69,6 @@ def main(): ThreadLocalODMSession.flush_all() ThreadLocalODMSession.close_all() + if __name__ == '__main__': main() diff --git a/scripts/migrations/015-add-neighborhood_id-to-blog-posts.py b/scripts/migrations/015-add-neighborhood_id-to-blog-posts.py index 88d324e74b..83c3dea01d 100644 --- a/scripts/migrations/015-add-neighborhood_id-to-blog-posts.py +++ b/scripts/migrations/015-add-neighborhood_id-to-blog-posts.py @@ -34,5 +34,6 @@ def main(): ThreadLocalODMSession.flush_all() ThreadLocalODMSession.close_all() + if __name__ == '__main__': main() diff --git a/scripts/migrations/020-remove-wiki-title-slashes.py b/scripts/migrations/020-remove-wiki-title-slashes.py index 08b1bb6f91..99d192aed9 100644 --- a/scripts/migrations/020-remove-wiki-title-slashes.py +++ b/scripts/migrations/020-remove-wiki-title-slashes.py @@ -35,5 +35,6 @@ def main(): print('Updated: %s' % page.title) ThreadLocalODMSession.flush_all() + if __name__ == '__main__': main() diff --git a/scripts/migrations/022-change-anon-display-name.py b/scripts/migrations/022-change-anon-display-name.py index 2d43cacbfe..6c007cc5d4 100644 --- a/scripts/migrations/022-change-anon-display-name.py +++ b/scripts/migrations/022-change-anon-display-name.py @@ -26,5 +26,6 @@ def main(): ThreadLocalODMSession.flush_all() ThreadLocalODMSession.close_all() + if __name__ == '__main__': main() diff --git a/scripts/migrations/024-migrate-custom-profile-text.py b/scripts/migrations/024-migrate-custom-profile-text.py index de480c89d9..b859756ed3 100644 --- a/scripts/migrations/024-migrate-custom-profile-text.py +++ b/scripts/migrations/024-migrate-custom-profile-text.py @@ -80,5 +80,6 @@ def main(): ThreadLocalODMSession.flush_all() + if __name__ == '__main__': main() diff --git a/scripts/migrations/025-add-is-nbhd-project.py b/scripts/migrations/025-add-is-nbhd-project.py index ca3fc77bb3..0f29c284b7 100644 --- a/scripts/migrations/025-add-is-nbhd-project.py +++ b/scripts/migrations/025-add-is-nbhd-project.py @@ -28,5 +28,6 @@ def main(): M.Project.query.update({'shortname': {'$ne': '--init--'}}, {'$set': {'is_nbhd_project': False}}, multi=True) + if __name__ == '__main__': main() diff --git a/scripts/migrations/026-install-activity-tool.py b/scripts/migrations/026-install-activity-tool.py index 94eb6b31c0..38024c50dd 100644 --- a/scripts/migrations/026-install-activity-tool.py +++ b/scripts/migrations/026-install-activity-tool.py @@ -33,5 +33,6 @@ def main(): ThreadLocalODMSession.flush_all() ThreadLocalODMSession.close_all() + if __name__ == '__main__': main() diff --git a/scripts/migrations/027-change-ticket-write-permissions.py b/scripts/migrations/027-change-ticket-write-permissions.py index 6878f7addb..3d8483f218 100644 --- a/scripts/migrations/027-change-ticket-write-permissions.py +++ b/scripts/migrations/027-change-ticket-write-permissions.py @@ -49,5 +49,6 @@ def main(): ThreadLocalODMSession.flush_all() + if __name__ == '__main__': main() diff --git a/scripts/migrations/028-remove-svn-trees.py b/scripts/migrations/028-remove-svn-trees.py index 1cc12b1ac9..13d368a264 100644 --- a/scripts/migrations/028-remove-svn-trees.py +++ b/scripts/migrations/028-remove-svn-trees.py @@ -51,5 +51,6 @@ def main(): ThreadLocalODMSession.flush_all() ThreadLocalODMSession.close_all() + if __name__ == '__main__': main() diff --git a/scripts/migrations/029-set-mailbox-queue_empty.py b/scripts/migrations/029-set-mailbox-queue_empty.py index c2075b71cb..3a50b3c04b 100644 --- a/scripts/migrations/029-set-mailbox-queue_empty.py +++ b/scripts/migrations/029-set-mailbox-queue_empty.py @@ -31,5 +31,6 @@ def main(): {'$set': {'queue_empty': False}}, multi=True) + if __name__ == '__main__': main() diff --git a/scripts/migrations/031-set-user-pending-to-false.py b/scripts/migrations/031-set-user-pending-to-false.py index edb755a2cf..e1482b63c2 100644 --- a/scripts/migrations/031-set-user-pending-to-false.py +++ b/scripts/migrations/031-set-user-pending-to-false.py @@ -35,5 +35,6 @@ def main(): state(user).status = state(user).dirty ThreadLocalODMSession.flush_all() + if __name__ == '__main__': main() diff --git a/scripts/migrations/034-update_subscriptions_ticket_and_mr_titles.py b/scripts/migrations/034-update_subscriptions_ticket_and_mr_titles.py index 7e3dc1c3e8..dc2ee99712 100644 --- a/scripts/migrations/034-update_subscriptions_ticket_and_mr_titles.py +++ b/scripts/migrations/034-update_subscriptions_ticket_and_mr_titles.py @@ -47,7 +47,7 @@ def main(): continue new_title = 'Ticket #%d: %s' % (ticket.ticket_num, ticket.summary) log.info('"%s" --> "%s"', sub.artifact_title, new_title) - if(task != 'diff'): + if (task != 'diff'): sub.artifact_title = new_title session(sub).flush(sub) diff --git a/scripts/perf/load-up-forum.py b/scripts/perf/load-up-forum.py index 91338dec12..1b63a632df 100644 --- a/scripts/perf/load-up-forum.py +++ b/scripts/perf/load-up-forum.py @@ -61,7 +61,7 @@ def main(): p = thd.post(subject, 'a new topic 2') for j in range(randint(1, 5)): - new_post = {'text':'comment text'} + new_post = {'text': 'comment text'} # post = thd.add_post(**new_post) post = thd.add_post(text='comment text for real', subject="test subject") diff --git a/scripts/perf/sstress.py b/scripts/perf/sstress.py index a24f3d009a..9cd0dc934a 100644 --- a/scripts/perf/sstress.py +++ b/scripts/perf/sstress.py @@ -52,5 +52,6 @@ def stress(): for x in range(N / C): server.sendmail('sstress@localhost', TOADDR, EMAIL_TEXT) + if __name__ == '__main__': main() diff --git a/scripts/perf/test_git_lcd.py b/scripts/perf/test_git_lcd.py index 4dadee6c1e..d275763431 100644 --- a/scripts/perf/test_git_lcd.py +++ b/scripts/perf/test_git_lcd.py @@ -48,5 +48,6 @@ def main(repo_dir, sub_dir='', commit=None): pprint(result) print("Took %f seconds" % timer['result']) + if __name__ == '__main__': main(*sys.argv[1:])