Esempio n. 1
0
 def test_setup_logging_dict(self, smtp_config_yaml):
     logging_config_dict = {'version': 1,
                            'handlers': {
                                'error_file_handler': {
                                    'class': 'logging.FileHandler',
                                    'level': 'ERROR',
                                    'filename': 'errors.log',
                                    'encoding': 'utf8',
                                    'mode': 'w'
                                },
                                'error_mail_handler': {
                                    'class': 'logging.handlers.SMTPHandler',
                                    'level': 'CRITICAL',
                                    'mailhost': 'localhost',
                                    'fromaddr': 'noreply@localhost',
                                    'toaddrs': '*****@*****.**',
                                    'subject': 'SCRAPER FAILED'
                                }
                            },
                            'root': {
                                'level': 'INFO',
                                'handlers': ['error_file_handler', 'error_mail_handler']
                            }}
     setup_logging(logging_config_dict=logging_config_dict)
     actual_logging_tree = format.build_description()
     for handler in ['File', 'SMTP']:
         assert handler in actual_logging_tree
     assert '*****@*****.**' in actual_logging_tree
Esempio n. 2
0
 def test_setup_logging_smtp_dict(self):
     smtp_config_dict = {'handlers': {'error_mail_handler': {'toaddrs': '*****@*****.**', 'subject': 'lala'}}}
     setup_logging(smtp_config_dict=smtp_config_dict)
     actual_logging_tree = format.build_description()
     for handler in ['Stream', 'File', 'SMTP']:
         assert handler in actual_logging_tree
     assert '*****@*****.**' in actual_logging_tree
# -*- coding: utf-8 -*-
"""Facade that handles ScraperWiki and calls project main function"""
import logging
import sys
from typing import Callable

import scraperwiki

from hdx.configuration import Configuration
from hdx.facades import logging_kwargs
from hdx.hdx_logging import setup_logging

logger = logging.getLogger(__name__)
setup_logging(**logging_kwargs)


def facade(projectmainfn, **kwargs):
    # type: (Callable[[], None], Any) -> bool
    """Facade that handles ScraperWiki and calls project main function

    Args:
        projectmainfn (() -> None): main function of project
        **kwargs: configuration parameters to pass to HDX Configuration class

    Returns:
        bool: True = success, False = failure
    """

    try:
        #
        # Setting up configuration
Esempio n. 4
0
 def test_setup_logging_json(self, logging_config_json):
     setup_logging(logging_config_json=logging_config_json)
     actual_logging_tree = format.build_description()
     for handler in ['Stream', 'File']:
         assert handler in actual_logging_tree
Esempio n. 5
0
    def test_setup_logging(self, logging_config_json, logging_config_yaml, smtp_config_json, smtp_config_yaml):
        with pytest.raises(FILENOTFOUND_EXCTYPE):
            setup_logging(smtp_config_json='NOT_EXIST')

        with pytest.raises(FILENOTFOUND_EXCTYPE):
            setup_logging(logging_config_json='NOT_EXIST', smtp_config_yaml=smtp_config_yaml)

        with pytest.raises(FILENOTFOUND_EXCTYPE):
            setup_logging(logging_config_yaml='NOT_EXIST', smtp_config_yaml=smtp_config_yaml)

        with pytest.raises(LoggingError):
            setup_logging(logging_config_yaml=logging_config_yaml, smtp_config_yaml=smtp_config_yaml)

        with pytest.raises(LoggingError):
            setup_logging(logging_config_dict={'la': 'la'}, logging_config_json=logging_config_json,
                          smtp_config_yaml=smtp_config_yaml)

        with pytest.raises(LoggingError):
            setup_logging(logging_config_dict={'la': 'la'}, logging_config_yaml=logging_config_yaml,
                          smtp_config_yaml=smtp_config_yaml)

        with pytest.raises(LoggingError):
            setup_logging(logging_config_json=logging_config_json, logging_config_yaml=logging_config_yaml,
                          smtp_config_yaml=smtp_config_yaml)

        with pytest.raises(LoggingError):
            setup_logging(smtp_config_dict={'la': 'la'}, smtp_config_json=smtp_config_json)

        with pytest.raises(LoggingError):
            setup_logging(smtp_config_dict={'la': 'la'}, smtp_config_yaml=smtp_config_yaml)

        with pytest.raises(LoggingError):
            setup_logging(smtp_config_json=smtp_config_json, smtp_config_yaml=smtp_config_yaml)
Esempio n. 6
0
 def test_setup_logging_smtp_yaml(self, smtp_config_yaml):
     setup_logging(smtp_config_yaml=smtp_config_yaml)
     actual_logging_tree = format.build_description()
     for handler in ['Stream', 'File', 'SMTP']:
         assert handler in actual_logging_tree
     assert '*****@*****.**' in actual_logging_tree
Esempio n. 7
0
 def test_setup_logging_smtp_json(self, smtp_config_json):
     setup_logging(smtp_config_json=smtp_config_json)
     actual_logging_tree = format.build_description()
     for handler in ['Stream', 'File', 'SMTP']:
         assert handler in actual_logging_tree
     assert '*****@*****.**' in actual_logging_tree