"name": "TIE Fighter", "defense_component": random_service_branch(), }, ) add_task_orders_to_portfolio(tie_fighter) add_members_to_portfolio(tie_fighter) add_applications_to_portfolio(tie_fighter) # create a portfolio for each user ships = SHIP_NAMES.copy() for user in get_users(): ship = random.choice(ships) ships.remove(ship) portfolio = Portfolios.create( user=user, portfolio_attrs={ "name": ship, "defense_component": random_service_branch(), }, ) add_task_orders_to_portfolio(portfolio) add_members_to_portfolio(portfolio) add_applications_to_portfolio(portfolio) if __name__ == "__main__": config = make_config({"DISABLE_CRL_CHECK": True, "DEBUG": False}) app = make_app(config) with app.app_context(): seed_db()
_protected_routes = [] for rule in app.url_map.iter_rules(): args = [1] * len(rule.arguments) mock_args = dict(zip(rule.arguments, args)) _n, route = rule.build(mock_args) if rule.endpoint in _NO_ACCESS_CHECK_REQUIRED or "/static" in route: continue _protected_routes.append((rule, route)) return _protected_routes sample_config = make_config({"CRL_STORAGE_PROVIDER": "LOCAL"}) sample_app = make_app(sample_config) _PROTECTED_ROUTES = protected_routes(sample_app) @pytest.mark.access_check @pytest.mark.parametrize("rule,route", _PROTECTED_ROUTES) def test_all_protected_routes_have_access_control(rule, route, mocker, client, user_session, monkeypatch): """ This tests that all routes, except the ones in _NO_ACCESS_CHECK_REQUIRED, are protected by the access decorator. """ # monkeypatch any object lookups that might happen in the access decorator monkeypatch.setattr("atst.domain.portfolios.Portfolios.for_user", lambda *a: [])