예제 #1
0
파일: test_http.py 프로젝트: credativ/pulp
    def test_handle_event(self, mock_create):
        # Setup
        notifier_config = {"url": "https://localhost/api/", "username": "******", "password": "******"}

        event = Event("type-1", {"k1": "v1"})

        mock_connection = mock.Mock()
        mock_response = mock.Mock()

        mock_response.status = httplib.OK

        mock_connection.getresponse.return_value = mock_response
        mock_create.return_value = mock_connection

        # Test
        http.handle_event(notifier_config, event)
        time.sleep(0.5)  # handle works in a thread so give it a bit to finish

        # Verify
        self.assertEqual(1, mock_create.call_count)
        self.assertEqual(1, mock_connection.request.call_count)

        request_args = mock_connection.request.call_args[0]
        self.assertEqual("POST", request_args[0])
        self.assertEqual("/api/", request_args[1])

        expected_body = {"event_type": event.event_type, "payload": event.payload, "call_report": None}

        request_kwargs = mock_connection.request.call_args[1]
        parsed_body = json.loads(request_kwargs["body"])
        self.assertEqual(parsed_body, expected_body)

        headers = request_kwargs["headers"]
        self.assertTrue("Authorization" in headers)
예제 #2
0
    def test_handle_event_unparsable_url(self, mock_create):
        # Test
        http.handle_event({'url': '!@#$%'}, Event('type-1',
                                                  {}))  # should not error

        # Verify
        self.assertEqual(0, mock_create.call_count)
예제 #3
0
    def test_handle_event_missing_url(self, mock_create, mock_task_ser):
        # Test
        mock_task_ser.return_value = 'serialized data!'
        http.handle_event({}, Event('type-1', {}))  # should not error

        # Verify
        self.assertEqual(0, mock_create.call_count)
예제 #4
0
    def test_handle_event_unparsable_url(self, mock_create, mock_task_ser):
        # Test
        mock_task_ser.return_value = 'serialized data!'
        http.handle_event({'url': '!@#$%'}, Event('type-1', {}))  # should not error

        # Verify
        self.assertEqual(0, mock_create.call_count)
예제 #5
0
파일: test_http.py 프로젝트: grizax/pulp
    def test_handle_event(self, mock_thread):
        # Setup
        notifier_config = {'key': 'value'}
        mock_event = mock.Mock(spec=Event)
        event_data = mock_event.data.return_value

        # Test
        http.handle_event(notifier_config, mock_event)
        mock_thread.assert_called_once_with(
            target=http._send_post,
            args=[notifier_config, event_data]
        )
예제 #6
0
파일: test_http.py 프로젝트: shubham90/pulp
    def test_handle_event(self, mock_thread):
        # Setup
        notifier_config = {'key': 'value'}
        mock_event = mock.Mock(spec=Event)
        event_data = mock_event.data.return_value

        # Test
        http.handle_event(notifier_config, mock_event)
        mock_thread.assert_called_once_with(
            target=http._send_post,
            args=[notifier_config, event_data]
        )
예제 #7
0
    def test_handle_event(self, mock_send_post, mock_jutil, mock_json):
        # Setup
        notifier_config = {'key': 'value'}
        mock_event = mock.Mock(spec=Event)
        event_data = mock_event.data.return_value

        # Test
        http.handle_event(notifier_config, mock_event)
        mock_json.dumps.assert_called_once_with(event_data, default=mock_jutil.default)
        mock_send_post.assert_called_once_with(
            notifier_config,
            mock_json.dumps.return_value
        )
예제 #8
0
    def test_handle_event_with_serialize_error(self, mock_create):
        # Setup
        notifier_config = {'url': 'https://localhost/api/'}

        event = Event('type-1', {'k1': 'v1', '_id': _test_objid()})

        mock_connection = mock.Mock()
        mock_response = mock.Mock()

        mock_response.status = httplib.NOT_FOUND

        mock_connection.getresponse.return_value = mock_response
        mock_create.return_value = mock_connection

        # Test
        http.handle_event(notifier_config, event)  # should not throw TypeError
예제 #9
0
파일: test_http.py 프로젝트: credativ/pulp
    def test_handle_event_with_serialize_error(self, mock_create):
        # Setup
        notifier_config = {"url": "https://localhost/api/"}

        event = Event("type-1", {"k1": "v1", "_id": _test_objid()})

        mock_connection = mock.Mock()
        mock_response = mock.Mock()

        mock_response.status = httplib.NOT_FOUND

        mock_connection.getresponse.return_value = mock_response
        mock_create.return_value = mock_connection

        # Test
        http.handle_event(notifier_config, event)  # should not throw TypeError
예제 #10
0
    def test_handle_event_with_serialize_error(self, mock_create):
        # Setup
        notifier_config = {'url' : 'https://localhost/api/'}

        event = Event('type-1', {'k1' : 'v1', '_id': _test_objid()})

        mock_connection = mock.Mock()
        mock_response = mock.Mock()

        mock_response.status = httplib.NOT_FOUND

        mock_connection.getresponse.return_value = mock_response
        mock_create.return_value = mock_connection

        # Test
        http.handle_event(notifier_config, event) # should not throw TypeError
예제 #11
0
    def test_handle_event(self, mock_create, mock_task_ser):
        # Setup
        notifier_config = {
            'url': 'https://localhost/api/',
            'username': '******',
            'password': '******',
        }

        event = Event('type-1', {'k1': 'v1'})

        mock_connection = mock.Mock()
        mock_response = mock.Mock()
        mock_task_ser.return_value = None

        mock_response.status = httplib.OK

        mock_connection.getresponse.return_value = mock_response
        mock_create.return_value = mock_connection

        # Test
        http.handle_event(notifier_config, event)
        time.sleep(.5)  # handle works in a thread so give it a bit to finish

        # Verify
        self.assertEqual(1, mock_create.call_count)
        self.assertEqual(1, mock_connection.request.call_count)

        request_args = mock_connection.request.call_args[0]
        self.assertEqual('POST', request_args[0])
        self.assertEqual('/api/', request_args[1])

        expected_body = {
            'event_type': event.event_type,
            'payload': event.payload,
            'call_report': None
        }

        request_kwargs = mock_connection.request.call_args[1]
        parsed_body = json.loads(request_kwargs['body'])
        self.assertEqual(parsed_body, expected_body)

        headers = request_kwargs['headers']
        self.assertTrue('Authorization' in headers)
예제 #12
0
    def test_handle_event(self, mock_create, mock_task_ser):
        # Setup
        notifier_config = {
            'url': 'https://localhost/api/',
            'username': '******',
            'password': '******',
        }

        event = Event('type-1', {'k1': 'v1'})

        mock_connection = mock.Mock()
        mock_response = mock.Mock()
        mock_task_ser.return_value = None

        mock_response.status = httplib.OK

        mock_connection.getresponse.return_value = mock_response
        mock_create.return_value = mock_connection

        # Test
        http.handle_event(notifier_config, event)
        time.sleep(.5)  # handle works in a thread so give it a bit to finish

        # Verify
        self.assertEqual(1, mock_create.call_count)
        self.assertEqual(1, mock_connection.request.call_count)

        request_args = mock_connection.request.call_args[0]
        self.assertEqual('POST', request_args[0])
        self.assertEqual('/api/', request_args[1])

        expected_body = {'event_type': event.event_type,
                         'payload': event.payload,
                         'call_report': None}

        request_kwargs = mock_connection.request.call_args[1]
        parsed_body = json.loads(request_kwargs['body'])
        self.assertEqual(parsed_body, expected_body)

        headers = request_kwargs['headers']
        self.assertTrue('Authorization' in headers)
예제 #13
0
    def test_handle_event_with_error(self, mock_create):
        # Setup
        notifier_config = {'url': 'https://localhost/api/'}

        event = Event('type-1', {'k1': 'v1'})

        mock_connection = mock.Mock()
        mock_response = mock.Mock()

        mock_response.status = httplib.NOT_FOUND

        mock_connection.getresponse.return_value = mock_response
        mock_create.return_value = mock_connection

        # Test
        http.handle_event(notifier_config, event)  # should not error
        time.sleep(.5)

        # Verify
        self.assertEqual(1, mock_create.call_count)
        self.assertEqual(1, mock_connection.request.call_count)
예제 #14
0
    def test_handle_event_with_error(self, mock_create):
        # Setup
        notifier_config = {'url' : 'https://localhost/api/'}

        event = Event('type-1', {'k1' : 'v1'})

        mock_connection = mock.Mock()
        mock_response = mock.Mock()

        mock_response.status = httplib.NOT_FOUND

        mock_connection.getresponse.return_value = mock_response
        mock_create.return_value = mock_connection

        # Test
        http.handle_event(notifier_config, event) # should not error
        time.sleep(.5)

        # Verify
        self.assertEqual(1, mock_create.call_count)
        self.assertEqual(1, mock_connection.request.call_count)
예제 #15
0
    def test_handle_event_missing_url(self, mock_create):
        # Test
        http.handle_event({}, Event('type-1', {}))  # should not error

        # Verify
        self.assertEqual(0, mock_create.call_count)
예제 #16
0
파일: test_http.py 프로젝트: credativ/pulp
    def test_handle_event_unparsable_url(self, mock_create):
        # Test
        http.handle_event({"url": "!@#$%"}, Event("type-1", {}))  # should not error

        # Verify
        self.assertEqual(0, mock_create.call_count)
예제 #17
0
    def test_handle_event_missing_url(self, mock_create):
        # Test
        http.handle_event({}, Event('type-1', {})) # should not error

        # Verify
        self.assertEqual(0, mock_create.call_count)
예제 #18
0
    def test_handle_event_unparsable_url(self, mock_create):
        # Test
        http.handle_event({'url' : '!@#$%'}, Event('type-1', {})) # should not error

        # Verify
        self.assertEqual(0, mock_create.call_count)