示例#1
0
 def test_api_key_is_required_on_default_transport(self):
     with self.assertRaises(NameError):
         get_configuration(application='test_appname',
                           environment='test_environment',
                           api_key='',
                           api_url='test_apiurl',
                           transport='default')
def configure_transport(config=None, **kwargs):
    # return which transport to use depending on users input
    api_config = config or get_configuration(**kwargs)
    env_details = EnvironmentDetail(api_config)
    return TransportTypes.get_transport(
        api_config,
        env_details,
    )
示例#3
0
    def test_required_kwargs(self):
        '''API configuration requires appname, env and key'''
        env_map = {}

        with patch.dict('os.environ', env_map):
            with self.assertRaises(NameError):
                get_configuration()
            with self.assertRaises(NameError):
                get_configuration(application='1')
            with self.assertRaises(NameError):
                get_configuration(application='1', environment='2')
            with self.assertRaises(NameError):
                get_configuration(application='1',
                                  environment='2',
                                  api_url='3')

            get_configuration(application='1', environment='2', api_key='3')
示例#4
0
    def test_http_endpoint_environment_variable_default(self):
        config = get_configuration(
            application='test_appname',
            environment='test_environment',
            api_key='test_apikey',
            api_url='test_apiurl',
        )

        assert config.http_endpoint == DEFAULT_HTTP_ENDPOINT
示例#5
0
    def test_api_url_default(self):
        '''API URL is set automatically'''
        config = get_configuration(
            application='test4_appname',
            environment='test4_environment',
            api_key='test4_apikey',
        )

        self.assertEqual(config.application, 'test4_appname')
        self.assertEqual(config.environment, 'test4_environment')
        self.assertEqual(config.api_key, 'test4_apikey')
        self.assertEqual(config.api_url, API_URL)
示例#6
0
    def test_api_key_is_not_required_on_agent_socket_transport(self):
        config = get_configuration(application='test_appname',
                                   environment='test_environment',
                                   api_key='',
                                   api_url='test_apiurl',
                                   transport='agent_socket')

        self.assertEqual(config.application, 'test_appname')
        self.assertEqual(config.environment, 'test_environment')
        self.assertEqual(config.api_key, '')
        self.assertEqual(config.api_url, 'test_apiurl')
        self.assertEqual(config.transport, 'agent_socket')
示例#7
0
    def test_transport_given(self):
        config = get_configuration(application='test5_appname',
                                   environment='test5_environment',
                                   api_key='test5_apikey',
                                   api_url='test5_apiurl',
                                   transport='test5_transport')

        self.assertEqual(config.application, 'test5_appname')
        self.assertEqual(config.environment, 'test5_environment')
        self.assertEqual(config.api_key, 'test5_apikey')
        self.assertEqual(config.api_url, 'test5_apiurl')
        self.assertEqual(config.transport, 'test5_transport')
示例#8
0
    def test_create_group_message(self):
        api_config = get_configuration(**CONFIG)
        env_details = EnvironmentDetail(api_config)
        agent_base_transport = AgentBaseTransport(api_config, env_details)

        message = agent_base_transport.create_message(
            logging.makeLogRecord({
                'mgs': 'message',
                'funcName': 'foo'
            }))
        group_message = agent_base_transport.create_group_message([message])

        assert isinstance(group_message, stackify_agent_pb2.LogGroup)
示例#9
0
    def test_transport_default(self):
        config = get_configuration(
            application='test4_appname',
            environment='test4_environment',
            api_key='test4_apikey',
            api_url='test3_apiurl',
        )

        self.assertEqual(config.application, 'test4_appname')
        self.assertEqual(config.environment, 'test4_environment')
        self.assertEqual(config.api_key, 'test4_apikey')
        self.assertEqual(config.api_url, 'test3_apiurl')
        self.assertEqual(config.transport, 'default')
示例#10
0
    def test_kwargs(self):
        '''API configuration can load from kwargs'''
        config = get_configuration(
            application='test3_appname',
            environment='test3_environment',
            api_key='test3_apikey',
            api_url='test3_apiurl',
        )

        self.assertEqual(config.application, 'test3_appname')
        self.assertEqual(config.environment, 'test3_environment')
        self.assertEqual(config.api_key, 'test3_apikey')
        self.assertEqual(config.api_url, 'test3_apiurl')
示例#11
0
    def test_http_endpoint_environment_variable(self):
        os.environ["STACKIFY_TRANSPORT_HTTP_ENDPOINT"] = "test"

        config = get_configuration(
            application='test_appname',
            environment='test_environment',
            api_key='test_apikey',
            api_url='test_apiurl',
        )

        assert config.http_endpoint == "test"

        del os.environ["STACKIFY_TRANSPORT_HTTP_ENDPOINT"]
示例#12
0
    def test_transport_environment_variable_agent_http(self):
        os.environ["STACKIFY_TRANSPORT"] = "agent_http"

        config = get_configuration(
            application='test_appname',
            environment='test_environment',
            api_key='test_apikey',
            api_url='test_apiurl',
        )

        assert config.transport == TRANSPORT_TYPE_AGENT_HTTP

        del os.environ["STACKIFY_TRANSPORT"]
示例#13
0
    def test_transport_environment_variable_default(self):
        os.environ["STACKIFY_TRANSPORT"] = "default"

        config = get_configuration(
            application='test_appname',
            environment='test_environment',
            api_key='test_apikey',
            api_url='test_apiurl',
        )

        assert config.transport == TRANSPORT_TYPE_DEFAULT

        del os.environ["STACKIFY_TRANSPORT"]
示例#14
0
    def test_kwarg_mix(self):
        '''API configuration can load from a mix of env vars and kwargs'''
        env_map = {
            'STACKIFY_APPLICATION': 'test2_appname',
            'STACKIFY_ENVIRONMENT': 'test2_environment',
        }

        with patch.dict('os.environ', env_map):
            config = get_configuration(api_key='test2_apikey',
                                       api_url='test2_apiurl')

        self.assertEqual(config.application, 'test2_appname')
        self.assertEqual(config.environment, 'test2_environment')
        self.assertEqual(config.api_key, 'test2_apikey')
        self.assertEqual(config.api_url, 'test2_apiurl')
示例#15
0
    def test_environment_config(self):
        '''API configuration can load from env vars'''
        env_map = {
            'STACKIFY_APPLICATION': 'test1_appname',
            'STACKIFY_ENVIRONMENT': 'test1_environment',
            'STACKIFY_API_KEY': 'test1_apikey',
            'STACKIFY_API_URL': 'test1_apiurl',
        }

        with patch.dict('os.environ', env_map):
            config = get_configuration()

        self.assertEqual(config.application, 'test1_appname')
        self.assertEqual(config.environment, 'test1_environment')
        self.assertEqual(config.api_key, 'test1_apikey')
        self.assertEqual(config.api_url, 'test1_apiurl')