def test_get_request_no_headers(self):
        mock_logger = mock.MagicMock()
        config_data = {
            "url": "http://fooUrl",
            "request_method": "GET",
            "request_data": None,
            "request_headers": [],
            "module": self.module,
        }
        config = MonitorConfig(content=config_data)
        url_monitor = UrlMonitor(monitor_config=config, logger=mock_logger)

        actual_request = url_monitor.build_request()
        self.assertEqual(actual_request.get_method(), "GET")
        self.assertFalse(actual_request.data is not None)
        self.assertEqual(actual_request.header_items(), [])
Example #2
0
    def test_get_request_no_headers(self):
        mock_logger = mock.MagicMock()
        config_data = {
            'url': 'fooUrl',
            'request_method': 'GET',
            'request_data': None,
            'request_headers': [],
            'module': self.module
        }
        config = MonitorConfig(content=config_data)
        url_monitor = UrlMonitor(monitor_config=config, logger=mock_logger)

        actual_request = url_monitor.build_request()
        self.assertEqual(actual_request.get_method(), 'GET')
        self.assertFalse(actual_request.has_data())
        self.assertEqual(actual_request.header_items(), [])
    def test_get_request_no_headers(self):
        mock_logger = mock.MagicMock()
        config_data = {
            'url': 'fooUrl',
            'request_method': 'GET',
            'request_data': None,
            'request_headers': [],
            'module': self.module
        }
        config = MonitorConfig(content=config_data)
        url_monitor = UrlMonitor(monitor_config=config, logger=mock_logger)

        actual_request = url_monitor.build_request()
        self.assertEqual(actual_request.get_method(), 'GET')
        self.assertFalse(actual_request.has_data())
        self.assertEqual(actual_request.header_items(), [])
    def test_post_request_with_data(self):
        mock_logger = mock.MagicMock()
        config_data = {
            'url': 'fooUrl',
            'request_method': 'POST',
            'request_data': '{fakejsonthatisnotlegit}',
            'request_headers': self.legit_headers,
            'module': self.module
        }

        config = MonitorConfig(content=config_data)
        url_monitor = UrlMonitor(monitor_config=config, logger=mock_logger)
        actual_request = url_monitor.build_request()
        self.assertEqual(actual_request.get_method(), 'POST')
        self.assertEqual(actual_request.data, '{fakejsonthatisnotlegit}')
        self.assertEqual(actual_request.header_items(),
                         [('Header_foo', 'foo'), ('Header_bar', 'bar')])
 def test_get_request_with_headers(self):
     mock_logger = mock.MagicMock()
     config_data = {
         "url": "http://fooUrl",
         "request_method": "GET",
         "request_data": None,
         "request_headers": self.legit_headers,
         "module": self.module,
     }
     config = MonitorConfig(content=config_data)
     url_monitor = UrlMonitor(monitor_config=config, logger=mock_logger)
     actual_request = url_monitor.build_request()
     self.assertEqual(actual_request.get_method(), "GET")
     self.assertFalse(actual_request.data is not None)
     self.assertEqual(
         sorted(actual_request.header_items()),
         sorted([("Header_foo", "foo"), ("Header_bar", "bar")]),
     )
Example #6
0
    def test_post_request_with_data(self):
        mock_logger = mock.MagicMock()
        config_data = {
            'url': 'fooUrl',
            'request_method': 'POST',
            'request_data': '{fakejsonthatisnotlegit}',
            'request_headers': self.legit_headers,
            'module': self.module
        }

        config = MonitorConfig(content=config_data)
        url_monitor = UrlMonitor(monitor_config=config, logger=mock_logger)
        actual_request = url_monitor.build_request()
        self.assertEqual(actual_request.get_method(), 'POST')
        self.assertEqual(actual_request.data, '{fakejsonthatisnotlegit}')
        self.assertEqual(
            actual_request.header_items(),
            [('Header_foo', 'foo'), ('Header_bar', 'bar')]
        )
Example #7
0
    def test_post_request_with_data(self):
        mock_logger = mock.MagicMock()
        config_data = {
            "url": "fooUrl",
            "request_method": "POST",
            "request_data": "{fakejsonthatisnotlegit}",
            "request_headers": self.legit_headers,
            "module": self.module,
        }

        config = MonitorConfig(content=config_data)
        url_monitor = UrlMonitor(monitor_config=config, logger=mock_logger)
        actual_request = url_monitor.build_request()
        self.assertEqual(actual_request.get_method(), "POST")
        self.assertEqual(actual_request.data, "{fakejsonthatisnotlegit}")
        self.assertEqual(
            actual_request.header_items(),
            [("Header_foo", "foo"), ("Header_bar", "bar")],
        )