def _remove(self, *args): account_name = self.tree.focus() if not account_name: return # remove printers belonging to the deleted account uri_prefix = Utils.PROTOCOL + urllib.quote( account_name.encode('ascii', 'replace')) + '/' for cups_printer in self.window.getCUPSHelper().getPrinters().values(): if cups_printer['device-uri'].startswith(uri_prefix): self.window.getCUPSHelper().deletePrinter( cups_printer['device-uri']) Auth.DeleteAccount(account_name) self.handleSelected() self.window.resetAccounts() self.window.refreshPrinters()
def test_setupAuth(): testUserName = '******' # ensure setup with no details doesnt create file assert os.path.exists(Auth.config) is False assert Auth.SetupAuth(False) == (False, False) assert os.path.exists(Auth.config) is True assert Utils.ReadFile(Auth.config) == "{}" os.unlink(Auth.config) # create initial file assert os.path.exists(Auth.config) is False assert Auth.SetupAuth(False, testUserIds=['test']) == (False, False) assert os.path.exists(Auth.config) is True # ensure permissions are correct after creating config assert '0660' == oct(os.stat(Auth.config)[stat.ST_MODE])[-4:] # add dummy details storage = multistore_file.get_credential_storage( Auth.config, Auth.clientid, 'testuseraccount', ['https://www.googleapis.com/auth/cloudprint']) credentials = client.OAuth2Credentials( 'test', Auth.clientid, 'testsecret', 'testtoken', 1, 'https://www.googleapis.com/auth/cloudprint', testUserName) storage.put(credentials) # ensure permissions are correct after populating config assert '0660' == oct(os.stat(Auth.config)[stat.ST_MODE])[-4:] # re-run to test getting credentials requestors, storage = Auth.SetupAuth(False) assert requestors is not None assert storage is not None # check deleting account assert Auth.DeleteAccount(testUserName) is None requestors, storage = Auth.SetupAuth(False) assert requestors is False assert storage is False
if not result: print("No accounts are currently setup") break else: requestors, storage = result print("You currently have these accounts configured: ") i = 0 accounts = [] for requestor in requestors: i += 1 accounts.append(requestor.getAccount()) print(str(i) + ") " + requestor.getAccount()) print("0) Exit") answer = raw_input("Which account to delete (1-" + str(i) + ") ? ") if (answer.isdigit() and int(answer) <= i and int(answer) >= 1): if (Auth.DeleteAccount(accounts[int(answer) - 1]) == None): print(accounts[int(answer) - 1] + " deleted.") deleteprintersanswer = raw_input( "Also delete associated printers? ") if deleteprintersanswer.startswith( "Y") or deleteprintersanswer.startswith("y"): printer = Printer(requestors) printers, connection = printer.getCUPSPrintersForAccount( accounts[int(answer) - 1]) if len(printers) == 0: print "No printers to delete" else: for cupsPrinter in printers: print "Deleting " + cupsPrinter['printer-info'] deleteReturnValue = connection.deletePrinter( cupsPrinter['printer-info'])