def make_profile(profile_type: Profiles = None, preferences: dict = None): """Internal-only method used to create profiles on disk. :param profile_type: Profiles.BRAND_NEW, Profiles.LIKE_NEW, Profiles.TEN_BOOKMARKS, Profiles.DEFAULT :param preferences: A dictionary containing profile preferences """ if profile_type is None: profile_type = Profiles.DEFAULT if preferences is None: if profile_type is Profiles.BRAND_NEW: preferences = FirefoxSettings.DEFAULT_FX_PREFS else: preferences = {} test_root = PathManager.get_current_tests_directory() current_test = os.environ.get('CURRENT_TEST') test_path = current_test.split(test_root)[1].split('.py')[0][1:] profile_path = os.path.join(PathManager.get_current_run_dir(), test_path, 'profile') if not os.path.exists(profile_path): os.makedirs(profile_path) if profile_type is Profiles.BRAND_NEW: logger.debug('Creating brand new profile: %s' % profile_path) elif profile_type in (Profiles.LIKE_NEW, Profiles.TEN_BOOKMARKS): logger.debug('Creating new profile from %s staged profile.' % profile_type.value.upper()) profile_path = FirefoxProfile._get_staged_profile( profile_type, profile_path) else: raise ValueError('No profile found: %s' % profile_type.value) return MozProfile(profile=profile_path, preferences=preferences)
def send_json_report(self): report_s = validate_section('Report_URL') if len(report_s) > 0: logger.warning( '{}. \nJSON report cannot be sent - no report URL found in config file.' .format(report_s)) else: run_file = os.path.join(PathManager.get_current_run_dir(), 'run.json') url = get_config_property('Report_URL', 'url') if url is not None: try: with open(run_file, 'rb') as file: r = requests.post(url=url, files={'file': file}) if not r.ok: logger.error( 'Report was not sent to URL: %s \nResponse text: %s' % url, r.text) logger.debug('Sent JSON report status: %s' % r.text) except requests.RequestException as ex: logger.error( 'Failed to send run report to URL: %s \nException data: %s' % url, ex) else: logger.error('Bad URL for JSON report.')
def get_file_attachment(): test_report_file = os.path.join(PathManager.get_current_run_dir(), 'iris_log.log') if os.path.exists(test_report_file): file_log = open(test_report_file) attachment = MIMEText(file_log.read(), 1) file_log.close() attachment.add_header('Content-Disposition', 'attachment', filename=os.path.basename(test_report_file)) return attachment else: raise Exception('File %s is not present in path' % test_report_file)