def test_invalid_api_base_path_initialization(self, mock_requests_get):
        mock_requests_get.side_effect = _mocked_requests_get
        expected_base_path_url = "http://{}:{}test/api/{}".format(self.status_host, self.status_port, DEFAULT_API_VERSION)

        agent = NginxStatusAgent(self.status_host, self.status_port, api_base_path='test/api')
        agent._initialize_newer_api_urls()
        self.assertEquals(agent.base_status_url, expected_base_path_url)
Esempio n. 2
0
    def setUp(self):
        self.status_host = _random_string()
        self.status_port = _random_int()
        self.base_status_url = 'http://{}:{}/status'.format(
            self.status_host, str(self.status_port))

        self.agent = NginxStatusAgent(self.status_host, self.status_port)
    def test_invalid_api_base_path_initialization(self, mock_requests_get):
        mock_requests_get.side_effect = _mocked_requests_get
        expected_base_path_url = "http://{}:{}invalid/status".format(self.status_host, self.status_port)

        agent = NginxStatusAgent(self.status_host, self.status_port, api_base_path='invalid/status')
        agent._initialize_legacy_api_urls()
        self.assertEquals(agent.base_status_url, expected_base_path_url)
    def setUp(self, mock_requests_get):
        self.status_host = _random_string()
        self.status_port = _random_int()
        self.base_status_url = 'http://{}:{}/api/4'.format(self.status_host, str(self.status_port))

        mock_requests_get.side_effect = _mocked_requests_get

        self.agent = NginxStatusAgent(self.status_host, self.status_port, api_version=4)
Esempio n. 5
0
    def test_get_status_with_auth(self, mock_requests_get):
        username = _random_string()
        password = _random_string()
        auth_tuple = (username, password)

        auth_agent = NginxStatusAgent(self.status_host, self.status_port,
                                      username, password)

        auth_agent.get_status()
        mock_requests_get.assert_called_with(self.base_status_url,
                                             auth=auth_tuple)
    def test_invalid_api_base_path(self, mock_requests_get):
        mock_requests_get.side_effect = _mocked_requests_get

        with self.assertRaises(RuntimeError) as runtime_error:
            NginxStatusAgent(self.status_host, self.status_port, api_base_path='/invalid')
        self.assertEquals(runtime_error.exception.message, "Failed to detect the Nginx-plus API type (versioned or legacy), please check your input configuration.")
    def test_api_version(self, mock_requests_get):
        mock_requests_get.side_effect = _mocked_requests_get

        agent = NginxStatusAgent(self.status_host, self.status_port, api_version=6)
        self.assertEquals(agent.api_version, 6)
        self.assertEquals(agent.api_base_path, '/api')
    def test_non_default_api_base_path(self, mock_requests_get):
        mock_requests_get.side_effect = _mocked_requests_get

        agent = NginxStatusAgent(self.status_host, self.status_port, api_base_path='/test/api')
        self.assertEquals(agent.api_base_path, '/test/api')
    def test_api_version_and_api_base_path_input_None(self, mock_requests_get):
        mock_requests_get.side_effect = _mocked_requests_get

        agent = NginxStatusAgent(self.status_host, self.status_port)
        self.assertEquals(agent.api_version, DEFAULT_API_VERSION)
        self.assertEquals(agent.api_base_path, '/api')
    def test_default_api_base_path(self, mock_requests_get):
        mock_requests_get.side_effect = _mocked_requests_get

        agent = NginxStatusAgent(self.status_host, self.status_port)
        self.assertEquals(agent.api_version, None)
        self.assertEquals(agent.api_base_path, '/status')