예제 #1
0
def get_connection_info():
    ci = namedtuple("ConnectionInfo", "dbhost, dbport, dbuser, dbpass, dbname")
    config = ConfigHelper()
    ci.dbhost = config.get_config("DB_HOST")
    ci.dbport = config.get_config("DB_PORT")
    ci.dbuser = config.get_config("DB_USER")
    ci.dbpass = config.get_config("DB_PASS")
    ci.dbname = config.get_config("DB_NAME")
    return ci
예제 #2
0
    def __init__(self):
        config = ConfigHelper()
        self.bucket = config.get_config("GCP_BUCKET")
        self.account = config.get_config("GOOGLE_APPLICATION_CREDENTIALS")

        # all these values are necessary
        if not self.bucket or not self.account:
            raise Exception("""The GCP_BUCKET or GOOGLE_APPLICATION_CREDENTIALS
            are not set and there is not a .dspreview.json file in the user's
            home folder, please provide one of them.""")

        # make sure they are the same
        os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = self.account
        self._service = None
예제 #3
0
 def test_get_value(self, mock_path_exists):
     mock_path_exists.return_value = True
     read_data = """{"key":"value"}"""
     mo = mock_open(read_data=read_data)
     with patch('utils.config_helper.open', mo):
         config = ConfigHelper()
         self.assertEqual(
             config.get_config("key"), "value",
             """Is is not finding the correct
                                     key-value config""")
예제 #4
0
 def __enter__(self):
     try:
         config = ConfigHelper()
         credentials = pika.PlainCredentials(config.get_config("MQ_USER"),
                                             config.get_config("MQ_PASS"))
         host = config.get_config("MQ_HOST")
         port = config.get_config("MQ_PORT")
         vhost = config.get_config("MQ_VHOST")
         self.queue = config.get_config("MQ_QUEUE")
         parameters = pika.ConnectionParameters(host=host,
                                                port=port,
                                                virtual_host=vhost,
                                                credentials=credentials)
         self.connection = pika.BlockingConnection(parameters)
         self.channel = self.connection.channel()
         self.channel.queue_declare(queue=self.queue, durable=True)
     except Exception as err:
         logger.exception(err)
         raise Exception("""It was not possible to connect to the MQ,
                         please check the connection information""")
     return self