예제 #1
0
 def setUp(self):
     super().setUp()
     self.client = MakerAdminClient(base_url="https://makeradmin.se")
     self.client.is_logged_in = MagicMock(return_value=True)
     self.client.login = MagicMock(return_value=True)
     self.client.ship_orders = MagicMock(return_value=None)
     self.ui = Tui()
예제 #2
0
def main():

    basicConfig(
        format=
        '%(asctime)s %(levelname)s [%(process)d/%(threadName)s %(pathname)s:%(lineno)d]: %(message)s',
        stream=sys.stderr,
        level=INFO)

    parser = argparse.ArgumentParser(
        "Fetches member list from makeradmin.se or local file, then prompt user with"
        f" changes to make. Built from source revision {source_revision}.",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument(
        "-d",
        "--db",
        default=
        'mssql://(local)\\SQLEXPRESS/MultiAccess?trusted_connection=yes&driver=SQL+Server',
        help="SQL Alchemy db engine spec.")
    parser.add_argument(
        "-w",
        "--what",
        default=",".join(WHAT_ALL),
        help=f"What to update, comma separated list."
        f" '{WHAT_ORDERS}' tell maker admin to perform order actions before updating members."
        f" '{WHAT_UPDATE}' will update end times and rfid_tag."
        f" '{WHAT_ADD}' will add members in MultAccess."
        f" '{WHAT_BLOCK}' will block members that should not have access.")
    parser.add_argument(
        "-u",
        "--maker-admin-base-url",
        default='https://api.makerspace.se',
        help="Base url of maker admin (for login and fetching of member info)."
    )
    parser.add_argument(
        "-m",
        "--members-filename",
        default=None,
        help=
        "Provide members in a file instead of fetching from maker admin (same format as response"
        " from maker admin).")
    parser.add_argument(
        "-t",
        "--token",
        default="",
        help="Provide token on command line instead of prompting for login.")
    parser.add_argument(
        "--customer-id",
        default=16,
        type=int,
        help="MultiAcces custoemr primary key to use to get and add users.")
    parser.add_argument(
        "--authority-id",
        default=23,
        type=int,
        help="MultiAcces authority primary key to add ny default to new users."
    )
    parser.add_argument(
        "--ignore-running",
        action='store_true',
        help="Ignore the check for if MultiAcces is running, do not use this.")

    args = parser.parse_args()

    what = args.what.split(',')
    for w in what:
        if w not in WHAT_ALL:
            raise argparse.ArgumentError(f"Unknown argument '{w}' to what.")

    with Tui() as ui:
        client = MakerAdminClient(ui=ui,
                                  base_url=args.maker_admin_base_url,
                                  members_filename=args.members_filename,
                                  token=args.token)

        ui.info__progress(f"connecting to {args.db}")
        engine = create_engine(args.db)

        while True:
            Session = sessionmaker(bind=engine)
            session = Session()

            sync(session=session,
                 ui=ui,
                 client=client,
                 customer_id=args.customer_id,
                 authority_id=args.authority_id,
                 ignore_running=args.ignore_running,
                 what=what)

            session.close()

            ui.prompt__run_again()
예제 #3
0
 def test_info_methods_does_not_block_execution(self):
     ui = Tui()
     ui.info__progress("msg")
예제 #4
0
 def test_fatal_methods_raises_system_exit(self):
     ui = Tui()
     with self.assertRaises(SystemExit):
         ui.fatal__error("err")
     with self.assertRaises(SystemExit):
         ui.fatal__problem_members([])
예제 #5
0
 def setUp(self):
     super().setUp()
     self.tui = Tui()