def test_produce_upload_classlist(): classlist = [(10050380, "Fink, Iris")] msgr = ManagerMessenger() msgr.upload_classlist = MagicMock(return_value=None) msgr.closeUser = MagicMock(return_value=None) msgr.stop = MagicMock(return_value=None) upload_classlist(classlist=classlist, msgr=msgr) msgr.upload_classlist.assert_called_with(classlist) msgr.closeUser.assert_called() msgr.stop.assert_called()
def get_messenger(server=None, password=None): if server and ":" in server: s, p = server.split(":") msgr = ManagerMessenger(s, port=p) else: msgr = ManagerMessenger(server) msgr.start() if not password: password = getpass('Please enter the "manager" password: '******'In order to force-logout the existing authorisation run "plom-build clear"' ) sys.exit(10) return msgr
def download_classlist_and_spec(server=None, password=None): """Download list of student IDs/names and test specification from server.""" if server and ":" in server: s, p = server.split(":") msgr = ManagerMessenger(s, port=p) else: msgr = ManagerMessenger(server) msgr.start() if not password: password = getpass('Please enter the "manager" password: '******'In order to force-logout the existing authorisation run "plom-build clear"' ) exit(10) try: classlist = msgr.IDrequestClasslist() except PlomBenignException as e: print("Failed to download classlist: {}".format(e)) exit(4) try: spec = msgr.get_spec() except PlomBenignException as e: print("Failed to get specification: {}".format(e)) exit(4) msgr.closeUser() msgr.stop() return classlist, spec
def build_database(server=None, password=None, vermap={}): """Build the database from a pre-set version map. args: vermap (dict): question version map. If empty dict, server will make its own mapping. For the map format see :func:`plom.finish.make_random_version_map`. server (str): password (str): return: str: long multiline string of all the version DB entries. """ if server and ":" in server: s, p = server.split(":") msgr = ManagerMessenger(s, port=p) else: msgr = ManagerMessenger(server) msgr.start() if not password: password = getpass('Please enter the "manager" password: ') check_version_map(vermap) msgr.requestAndSaveToken("manager", password) try: status = msgr.TriggerPopulateDB(vermap) except PlomBenignException: # TODO this should be a more specific exception raise RuntimeError("Server already has a populated database") from None # grab map and sanity check qvmap = msgr.getGlobalQuestionVersionMap() if vermap: assert qvmap == vermap msgr.closeUser() msgr.stop() return status
def build_papers(server=None, password=None, fakepdf=False, no_qr=False): if server and ":" in server: s, p = server.split(":") msgr = ManagerMessenger(s, port=p) else: msgr = ManagerMessenger(server) msgr.start() if not password: password = getpass('Please enter the "manager" password: '******'Building {} pre-named papers and {} blank papers in "{}"...'. format( spec["numberToName"], spec["numberToProduce"] - spec["numberToName"], paperdir, )) else: classlist = None print('Building {} blank papers in "{}"...'.format( spec["numberToProduce"], paperdir)) build_all_papers(spec, pvmap, classlist, fakepdf, no_qr=no_qr) print("Checking papers produced and updating databases") confirm_processed(spec, msgr, classlist) print("Identifying any pre-named papers into the database") identify_prenamed(spec, msgr, classlist) finally: msgr.closeUser() msgr.stop()
def buildDatabaseAndPapers(server=None, password=None): if server and ":" in server: s, p = server.split(":") msgr = ManagerMessenger(s, port=p) else: msgr = ManagerMessenger(server) msgr.start() if not password: password = getpass('Please enter the "manager" password: '******'In order to force-logout the existing authorisation run "plom-build clear"' ) exit(10) try: spec = msgr.get_spec() try: status = msgr.TriggerPopulateDB() except PlomBenignException: print("Error: Server already has a populated database") exit(3) print(status) pvmap = msgr.getGlobalPageVersionMap() os.makedirs(paperdir, exist_ok=True) if spec["numberToName"] > 0: try: classlist = msgr.IDrequestClasslist() except PlomBenignException as e: print("Failed to download classlist: {}".format(e)) exit(4) print( 'Building {} pre-named papers and {} blank papers in "{}"...'. format( spec["numberToName"], spec["numberToProduce"] - spec["numberToName"], paperdir, )) else: classlist = None print('Building {} blank papers in "{}"...'.format( spec["numberToProduce"], paperdir)) build_all_papers(spec, pvmap, classlist) print("Checking papers produced and updating databases") confirm_processed(spec, msgr, classlist) print("Identifying any pre-named papers into the database") identify_prenamed(spec, msgr, classlist) finally: msgr.closeUser() msgr.stop()