def getRootToken(electionId): from ext.ExtendedElection import get_extended_election election = Election.Model.query.filter( Election.Model.electionId == electionId).one_or_none() extended_election = get_extended_election(election=election) return extended_election.get_root_token()
def test_client(): connex_app = create_app() flask_app = connex_app.app tc = flask_app.test_client() @patch("orm.entities.Audit.Stamp.create") def create_test_election(mock_stamp_create): mock_stamp = Stamp() mock_stamp.ip = "0.0.0.0" mock_stamp.createdBy = "TestAdmin" mock_stamp.createdAt = datetime.now() db.session.add(mock_stamp) db.session.flush() mock_stamp_create.return_value = mock_stamp from orm.entities.Election.election_helper import build_presidential_election election = Election.create(electionName="Test Election") basedir = os.path.join(os.path.abspath(os.path.dirname(__file__)), "..", "sample-data", "test") party_candidate_dataset_file = os.path.join(basedir, "party-candidate.csv") polling_station_dataset_file = os.path.join(basedir, "data.csv") postal_counting_centers_dataset_file = os.path.join( basedir, "postal-data.csv") invalid_vote_categories_dataset_file = os.path.join( basedir, "invalid-vote-categories.csv") build_presidential_election( root_election=election, party_candidate_dataset_file=party_candidate_dataset_file, polling_station_dataset_file=polling_station_dataset_file, postal_counting_centers_dataset_file= postal_counting_centers_dataset_file, invalid_vote_categories_dataset_file= invalid_vote_categories_dataset_file) return election with connex_app.app.app_context(): db.create_all() db.session.commit() election = create_test_election() from orm.entities.Election.election_helper import get_root_token from ext.ExtendedElection import get_extended_election extended_election = get_extended_election(election=election) jwt_token = extended_election.get_root_token() tc.environ_base['HTTP_AUTHORIZATION'] = 'Bearer ' + jwt_token yield tc
def has_role_based_access(election, tally_sheet_code, access_type): from ext.ExtendedElection import get_extended_election extended_election = get_extended_election(election=election) role_based_access_config = extended_election.role_based_access_config vote_type = election.voteType for role in connexion.context[USER_ROLES]: if role in role_based_access_config: if tally_sheet_code in role_based_access_config[role]: if vote_type in role_based_access_config[role][tally_sheet_code]: if access_type in role_based_access_config[role][tally_sheet_code][vote_type]: return True return False
def get_extended_election(self): extended_election = get_extended_election(election=self) return extended_election