Exemplo n.º 1
0
 def _find_form(self, conf):
     """
     Find elements defined in conf['form'].
     Render all Jinja2 templates from field['value'].
     Save all field['click'] triggers.
     If all found, return them as a list of dictionaries.
     If at least one was not found, return empty list.
     """
     form = conf.get('form', [])
     fields = []
     creds = settings().creds
     for field in form:
         click = field.get('click')
         text = self._parse_field_text(field, conf, creds)
         selector_type, selector = self._parse_field_selector(field)
         if selector:
             element = self._find_element(selector, selector_type)
             if element:
                 fields.append({
                     'element': element,
                     'text': text,
                     'click': click,
                 })
             else:
                 logging.warning("Element {%s: %s} not found",
                                 selector_type, selector)
     if len(fields) == len(form):
         return fields
     else:
         logging.info(
             "Skipped form filling because not all fields were found")
         return []
Exemplo n.º 2
0
def on_before_start(*_args, **_kwargs):
    """Function to be called from Kibitzr using entrypoints"""
    sentry_dsn = settings().creds.get('sentry', {}).get('dsn')
    if sentry_dsn:
        level_name = settings().creds['sentry'].get('level', '').upper()
        level = None
        if level_name:
            level = LOG_LEVEL_CODES.get(level_name)
            if level is None:
                logger.warning(
                    "Unknown sentry.level: %s. "
                    "Choose one of the existing levels: %s",
                    level_name,
                    ', '.join(sorted(LOG_LEVEL_CODES)),
                )
        setup_sentry_handler(sentry_dsn, level=level)
Exemplo n.º 3
0
 def _exec_scenario(self, code, conf, elements):
     logger.info("Executing custom scenario")
     logger.debug(code)
     exec(
         code,
         {
             'conf': conf,
             'creds': settings().creds,
             'driver': self.driver,
             'elements': elements,
         },
     )
Exemplo n.º 4
0
def python_transform(code, content, conf):
    logger.info("Python transform")
    logger.debug(code)
    assert 'content' in code, PYTHON_ERROR
    try:
        namespace = {'ok': True, 'content': content}
        context = {
            'conf': conf,
            'stash': LazyStash(),
            'creds': settings().creds,
        }
        exec(code, context, namespace)
        return namespace['ok'], six.text_type(namespace['content'])
    except:
        logger.exception("Python transform raised an Exception")
        return False, traceback.format_exc()
Exemplo n.º 5
0
 def load_conf(self):
     credentials = settings().creds.get(CONF_KEY, {})
     user = self.conf.get(CONF_KEY)
     self.name = self.conf['name']
     if isinstance(user, six.string_types):
         # In full form email has email address as value:
         self.user = user
         self.match_rules = self.conf.get('match', {})
         self.get_password = self._get_password_for_explicit_user
     elif len(credentials) == 1:
         # But if credentials define only single email,
         # it can be omitted in conf and
         # have match right in the email
         self.user = credentials.items()[0][0]
         self.match_rules = user
         self.get_password = self._get_default_password
     else:
         raise RuntimeError(
             'EMail credentials not defined for check {0}'
             .format(self.name)
         )
Exemplo n.º 6
0
def test_missing_config_raises_configuration_error(exists):
    with pytest.raises(ConfigurationError):
        settings()
Exemplo n.º 7
0
 def _get_default_password():
     credentials = settings().creds.get(CONF_KEY, {})
     return credentials.items()[0][1]
Exemplo n.º 8
0
 def _get_password_for_explicit_user(self):
     user = self.conf.get(CONF_KEY)
     credentials = settings().creds.get(CONF_KEY, {})
     return credentials[user]