def test_get_set_last_chrome_session(self): self.api.file_tmp_last_chrome_session = Files.temp_file() data = { 'chrome_devtools': 'ws://127.0.0.1:64979/devtools/browser/75fbaab9-33eb-41ee-afd9-4aed65166791' } self.api.set_last_chrome_session(data) assert self.api.get_last_chrome_session() == data Files.delete(self.api.file_tmp_last_chrome_session)
def get_oauth_token(self, desired_scope): secret_data = json.loads(Secrets(self.gsuite_secret_id).value() ) # load secret from AWS Secrets store token_file = '/tmp/gmail_credential_{0}.json'.format( desired_scope ) # this is the tmp file with the token value for the desired scope if not Files.exists(token_file): # if the file does not exist if os.getenv('AWS_REGION') is not None or os.getenv( 'SYNC_SERVER' ): # check if we are running in AWS or in the sync server Files.write( token_file, secret_data['token.json'] ) # if we are, use the token.json value from the AWS secret_data else: secret_data = json.loads(Secrets( 'gsuite_token').value()) # BUG, need to refactor this credentials_file = '/tmp/gsuite_credentials.json' # file to hold the credentials.json value Files.write(credentials_file, secret_data['credentials.json'] ) # save value received from AWS into file store = file.Storage( token_file) # create a gsuite Storage object scopes = 'https://www.googleapis.com/auth/{0}'.format( desired_scope ) # full qualified name for the desired scopes flow = client.flow_from_clientsecrets( credentials_file, scopes) # create a gsuite flow object flags = argparser.parse_args( '--auth_host_name localhost --logging_level INFO'.split() ) # configure the use of a localhost server to received the oauth response run_flow( flow, store, flags ) # open browser and prompt user to follow the OAuth flow Files.delete( credentials_file ) # delete main gsuite credentials file (since we don't want it hanging around) return token_file # return file with token credentials
def cleanup_chrome_processes_and_tmp_files(): # remote temp files for file in Files.find('/tmp/core.headless_shell.*'): pid = file.split('.')[-1] Process.run('pkill',['-TERM','-P',str(pid)]) # this doesn't seem to be working since the "headless_shell <defunct>" is still there Files.delete(file)
def __exit__(self, type, value, traceback): if Files.exists(self.zip_file) and self.delete_zip_file: Files.delete(self.zip_file)
def __exit__(self, type, value, traceback): Files.delete(self.file_path) pass