Example #1
0
def pytest_runtest_setup(item):
    item.debug = {
        'urls': [],
        'screenshots': [],
        'html': [],
        'logs': [],
        'network_traffic': []
    }
    TestSetup.base_url = item.config.option.base_url

    # consider this environment sensitive if the base url or any redirection
    # history matches the regular expression
    sensitive = False
    if TestSetup.base_url:
        r = requests.get(TestSetup.base_url, verify=False)
        urls = [h.url for h in r.history] + [r.url]
        matches = [
            re.search(item.config.option.sensitive_url, u) for u in urls
        ]
        sensitive = any(matches)

    destructive = 'nondestructive' not in item.keywords

    if (sensitive and destructive):
        first_match = matches[next(i for i, match in enumerate(matches)
                                   if match)]

        # skip the test with an appropriate message
        py.test.skip('This test is destructive and the target URL is ' \
                     'considered a sensitive environment. If this test is ' \
                     'not destructive, add the \'nondestructive\' marker to ' \
                     'it. Sensitive URL: %s' % first_match.string)

    if item.config.option.sauce_labs_credentials_file:
        item.sauce_labs_credentials = credentials.read(
            item.config.option.sauce_labs_credentials_file)

    if item.config.option.credentials_file:
        TestSetup.credentials = credentials.read(
            item.config.option.credentials_file)

    test_id = '.'.join(split_class_and_test_names(item.nodeid))

    if 'skip_selenium' not in item.keywords:
        if hasattr(item, 'sauce_labs_credentials'):
            from sauce_labs import Client
            TestSetup.selenium_client = Client(test_id, item.config.option,
                                               item.keywords,
                                               item.sauce_labs_credentials)
        else:
            from selenium_client import Client
            TestSetup.selenium_client = Client(test_id, item.config.option)
        TestSetup.selenium_client.start()
        item.session_id = TestSetup.selenium_client.session_id
        TestSetup.selenium = TestSetup.selenium_client.selenium
        TestSetup.timeout = TestSetup.selenium_client.timeout
        TestSetup.default_implicit_wait = TestSetup.selenium_client.default_implicit_wait
    else:
        TestSetup.timeout = item.config.option.webqatimeout
        TestSetup.selenium = None
Example #2
0
def pytest_runtest_setup(item):
    item.debug = {
        'urls': [],
        'screenshots': [],
        'html': [],
        'logs': [],
        'network_traffic': []}
    TestSetup.base_url = item.config.option.base_url

    # consider this environment sensitive if the base url or any redirection
    # history matches the regular expression
    sensitive = False
    if TestSetup.base_url:
        r = requests.get(TestSetup.base_url, verify=False)
        urls = [h.url for h in r.history] + [r.url]
        matches = [re.search(item.config.option.sensitive_url, u) for u in urls]
        sensitive = any(matches)

    destructive = 'nondestructive' not in item.keywords

    if (sensitive and destructive):
        first_match = matches[next(i for i, match in enumerate(matches) if match)]

        # skip the test with an appropriate message
        py.test.skip('This test is destructive and the target URL is ' \
                     'considered a sensitive environment. If this test is ' \
                     'not destructive, add the \'nondestructive\' marker to ' \
                     'it. Sensitive URL: %s' % first_match.string)

    if item.config.option.sauce_labs_credentials_file:
        item.sauce_labs_credentials = credentials.read(item.config.option.sauce_labs_credentials_file)

    if item.config.option.credentials_file:
        TestSetup.credentials = credentials.read(item.config.option.credentials_file)

    test_id = '.'.join(split_class_and_test_names(item.nodeid))

    if 'skip_selenium' not in item.keywords:
        if hasattr(item, 'sauce_labs_credentials'):
            from sauce_labs import Client
            TestSetup.selenium_client = Client(
                test_id,
                item.config.option,
                item.keywords,
                item.sauce_labs_credentials)
        else:
            from selenium_client import Client
            TestSetup.selenium_client = Client(
                test_id,
                item.config.option)
        TestSetup.selenium_client.start()
        item.session_id = TestSetup.selenium_client.session_id
        TestSetup.selenium = TestSetup.selenium_client.selenium
        TestSetup.timeout = TestSetup.selenium_client.timeout
        TestSetup.default_implicit_wait = TestSetup.selenium_client.default_implicit_wait
    else:
        TestSetup.timeout = item.config.option.timeout
        TestSetup.selenium = None
def pytest_runtest_setup(item):
    item.debug = {"urls": [], "screenshots": [], "html": [], "logs": [], "network_traffic": []}
    TestSetup.base_url = item.config.option.base_url

    # configure test proxies
    if hasattr(item.config, "browsermob_test_proxy"):
        item.config.option.proxy_host = item.config.option.bmp_host
        item.config.option.proxy_port = item.config.browsermob_test_proxy.port

    # consider this environment sensitive if the base url or any redirection
    # history matches the regular expression
    sensitive = False
    if TestSetup.base_url and not item.config.option.skip_url_check:
        r = requests.get(TestSetup.base_url, verify=False)
        urls = [h.url for h in r.history] + [r.url]
        matches = [re.search(item.config.option.sensitive_url, u) for u in urls]
        sensitive = any(matches)

    destructive = "nondestructive" not in item.keywords

    if sensitive and destructive:
        first_match = matches[next(i for i, match in enumerate(matches) if match)]

        # skip the test with an appropriate message
        py.test.skip(
            "This test is destructive and the target URL is "
            "considered a sensitive environment. If this test is "
            "not destructive, add the 'nondestructive' marker to "
            "it. Sensitive URL: %s" % first_match.string
        )

    if item.config.option.sauce_labs_credentials_file:
        item.sauce_labs_credentials = credentials.read(item.config.option.sauce_labs_credentials_file)

    if item.config.option.credentials_file:
        TestSetup.credentials = credentials.read(item.config.option.credentials_file)

    test_id = ".".join(split_class_and_test_names(item.nodeid))

    if "skip_selenium" not in item.keywords:
        if hasattr(item, "sauce_labs_credentials"):
            from sauce_labs import Client

            TestSetup.selenium_client = Client(test_id, item.config.option, item.keywords, item.sauce_labs_credentials)
        else:
            from selenium_client import Client

            TestSetup.selenium_client = Client(test_id, item.config.option)
        TestSetup.selenium_client.start()
        item.session_id = TestSetup.selenium_client.session_id
        TestSetup.selenium = TestSetup.selenium_client.selenium
        TestSetup.timeout = TestSetup.selenium_client.timeout
        TestSetup.default_implicit_wait = TestSetup.selenium_client.default_implicit_wait
    else:
        TestSetup.timeout = item.config.option.webqatimeout
        TestSetup.selenium = None
Example #4
0
def send(template_name):
    """
    Prompts the user for the template name, from email address, from name,
    to email address, to name, subject, and any variables that get
    passed to the template. Then sends the template.
    """
    check_creds()
    creds = credentials.read()

    try:
        mandrill_client = mandrill.Mandrill(creds['apikey'])
        template = mandrill_client.templates.info(name=template_name)

        parser.data = []
        parser.reset()
        parser.feed(template['code'])

        choices = {'from_email': 'From Email Address',
                   'from_name': 'From Name',
                   'to_email': 'To Email Address(es), comma seperated',
                   'subject': 'Subject'}
        for data in parser.data:
            choices[data] = 'Template Option-> ' + data

        template_content = prompt_user(creds, choices)
        while template_content is None:
            template_content = prompt_user()

        t_c = template_content[0]
        t_o = template_content[1]
        r_t = mandrill_client.templates.render(template_name=template_name,
                                               template_content=t_c)

        s = smtplib.SMTP('smtp.mandrillapp.com', 587)
        s.login(creds['username'], creds['apikey'])

        # Iterate over the list of "To Email Addresses"
        for email in t_o['to_email'].strip().split(','):
            msg = MIMEMultipart('alternative')

            msg['Subject'] = t_o['subject']
            msg['From'] = t_o['from_name']+' <'+t_o['from_email']+'>'
            msg['To'] = email.strip()

            content = r_t['html'].encode('ascii', 'xmlcharrefreplace')
            html = MIMEText(content, 'html')

            msg.attach(html)
            s.sendmail(msg['From'], msg['To'], msg.as_string())

        s.quit()

        print "" + Fore.MAGENTA + 'Email Sent!!'

    except mandrill.Error, e:
        # Mandrill errors are thrown as exceptions
        print 'A mandrill error occurred: %s - %s' % (e.__class__, e)
def inventory(credentials_path):
    boto.glacier.connect_to_region(_region)
    cred = credentials.read(credentials_path)
    _logger.debug('aws credentials: {0}'.format(cred))
    con = boto.glacier.layer2.Layer2(
        cred[credentials.access_header],
        cred[credentials.secret_header])

    vs = con.list_vaults()
    for vault in vs:
        _logger.info('starting inventory job for {0}'.format(vault))
        jobid = vault.retrieve_inventory()
        _logger.info('vault {0}, job {1}'.format(vault, jobid))
def inventory(credentials_path, vault_name, job_id, output_path):
    boto.glacier.connect_to_region(_region)
    cred = credentials.read(credentials_path)
    _logger.debug('aws credentials: {0}'.format(cred))
    con = boto.glacier.layer2.Layer2(
        cred[credentials.access_header],
        cred[credentials.secret_header])

    _logger.info('getting vault {0}'.format(vault_name))
    vault = con.get_vault(vault_name)
    _logger.info('getting job {0} from vault {1}'.format(job_id, vault))
    job = vault.get_job(job_id)

    _logger.info('writing result of job {0} to file {1}'.format(job_id, output_path))
    #job.download_to_file(output_path)
    result = job.get_output()
    pprint.pprint(result)
    json.dump(result, codecs.open(output_path, 'w', 'utf-8'))
Example #7
0
def _upload(credentials_path, vault_name, data_path):
    # check file inputs
    filesize = os.path.getsize(data_path)
    do_multipart = filesize >= _multipart_filesize

    _logger.info(
        'input file: {0} with size: {1} multipart_upload: {2}'.format(
            data_path, filesize, do_multipart))

    # load credentials
    cred = credentials.read(credentials_path)
    _logger.debug('aws credentials: {0}'.format(cred))
    # connect to glacier with loaded credentials
    _logger.info('opening vault: {0} in region {1}'.format(vault_name, _region))
    boto.glacier.connect_to_region(_region)
    con = boto.glacier.layer2.Layer2(
        cred[credentials.access_header],
        cred[credentials.secret_header])
    vault = con.get_vault(vault_name)

    # upload file
    description = socket.gethostname() + ':' + os.path.basename(data_path)
    _logger.info('beginning upload of {0} to {1} in {2} with description "{3}"'.format(
        data_path, 
        vault_name, 
        _region, 
        description))

    timestr = _expected_duration(filesize)
    _logger.info('expected upload time for {0} is {1}'.format(data_path, timestr))

    if do_multipart:
        vault.concurrent_create_archive_from_file(
            data_path, 
            description,
            num_threads=2)
    else:
        vault.create_archive_from_file(
            data_path,
            description=description)
    _logger.info('completed upload of {0} to {1} in {2}'.format(data_path, vault_name, _region))
Example #8
0
def list():
    """
    Return a table with your current mailchimp templates data.
    """
    check_creds()
    creds = credentials.read()
    # Get the remplates from mandrill api
    try:
        mandrill_client = mandrill.Mandrill(creds['apikey'])
        templates = mandrill_client.templates.list()
        table = PrettyTable([Fore.GREEN + "Template", "'mc:edit' fields"])
        for template in templates:
            parser.data = []
            parser.reset()
            parser.feed(template['code'])
            table.add_row([Fore.CYAN + template['publish_name'],
                           ', '.join(parser.data)])
        print table

    except mandrill.Error, e:
        # Mandrill errors are thrown as exceptions
        print 'A mandrill error occurred: %s - %s' % (e.__class__, e)