Esempio n. 1
0
    def process_error(self, doc):
        fault_node = doc.find('soap-env:Body/soap-env:Fault',
                              namespaces=self.nsmap)

        if fault_node is None:
            raise Fault(message='Unknown fault occured',
                        code=None,
                        actor=None,
                        detail=etree_to_string(doc))

        def get_text(name):
            child = fault_node.find(name)
            if child is not None:
                return child.text

        message = fault_node.findtext('soap-env:Reason/soap-env:Text',
                                      namespaces=self.nsmap)
        code = fault_node.findtext('soap-env:Code/soap-env:Value',
                                   namespaces=self.nsmap)
        subcodes = []
        subcode_element = fault_node.find('soap-env:Code/soap-env:Subcode',
                                          namespaces=self.nsmap)
        while subcode_element is not None:
            subcodes.append(
                subcode_element.findtext('soap-env:Value',
                                         namespaces=self.nsmap))
            subcode_element = subcode_element.find('soap-env:Subcode',
                                                   namespaces=self.nsmap)

        raise Fault(message=message,
                    code=code,
                    actor=None,
                    detail=fault_node.find('Detail'),
                    subcodes=subcodes)
Esempio n. 2
0
    def process_error(self, doc, operation):
        fault_node = doc.find("soap-env:Body/soap-env:Fault", namespaces=self.nsmap)

        if fault_node is None:
            raise Fault(
                message="Unknown fault occured",
                code=None,
                actor=None,
                detail=etree_to_string(doc),
            )

        def get_text(name):
            child = fault_node.find(name)
            if child is not None:
                return child.text

        message = fault_node.findtext(
            "soap-env:Reason/soap-env:Text", namespaces=self.nsmap
        )
        code = fault_node.findtext(
            "soap-env:Code/soap-env:Value", namespaces=self.nsmap
        )

        # Extract the fault subcodes. These can be nested, as in subcodes can
        # also contain other subcodes.
        subcodes = []
        subcode_element = fault_node.find(
            "soap-env:Code/soap-env:Subcode", namespaces=self.nsmap
        )
        while subcode_element is not None:
            subcode_value_element = subcode_element.find(
                "soap-env:Value", namespaces=self.nsmap
            )
            subcode_qname = as_qname(
                subcode_value_element.text, subcode_value_element.nsmap, None
            )
            subcodes.append(subcode_qname)
            subcode_element = subcode_element.find(
                "soap-env:Subcode", namespaces=self.nsmap
            )

        # TODO: We should use the fault message as defined in the wsdl.
        detail_node = fault_node.find("soap-env:Detail", namespaces=self.nsmap)
        raise Fault(
            message=message,
            code=code,
            actor=None,
            detail=detail_node,
            subcodes=subcodes,
        )
 def test_update_context_dne(self):
     self.client.service.change.side_effect = [
         Fault("Context does not exist")
     ]
     self.assertRaises(exc.ContextNotFound, self.client.update_context, 1,
                       {"loginMappings": ["domain.com"]})
     self.assertEqual(self.client.service.change.call_count, 1)
 def test_update_context_dne_error(self):
     self.client.service.change.side_effect = [
         Fault('The context 1 does not exist!')
     ]
     self.assertRaises(exc.ContextNotFound, self.client.update_user, 1,
                       self.user['name'], self.user)
     self.assertEqual(self.client.service.change.call_count, 1)
 def test_update_user_dne_error(self):
     self.client.service.change.side_effect = [
         Fault("No such user {} in context 1".format(self.user["name"]))
     ]
     self.assertRaises(exc.UserNotFound, self.client.update_user, 1,
                       self.user['name'], self.user)
     self.assertEqual(self.client.service.change.call_count, 1)
Esempio n. 6
0
 def create_list(self,
                 list_name: str,
                 subject: str,
                 template: str,
                 description: str,
                 topic: str,
                 use_custom_template: bool = False,
                 raise_error: bool = True) -> bool:
     """
     Create a new mailing-list.
     """
     if topic not in TOPICS and topic not in SUBTOPICS:
         raise ValueError(f"Topic '{topic}' does not exist.")
     if template not in TEMPLATES and not use_custom_template:
         raise ValueError(f"Template '{template}' does not exist.")
     try:
         result = self.zeep.service.createList(list_name, subject, template,
                                               description, topic)
         return result._raw_elements[0].text == "true"
     except Fault as e:
         if raise_error:
             raise Fault(
                 f"An unknown error occured while creating the list {list_name}. "
                 f"Maybe the list already exists?", e)
         else:
             return False
 def test_get_context_dne_error(self):
     self.client.service.getData.side_effect = [
         Fault('Database for context 1 and server BLAH can not be resolved')
     ]
     self.assertRaises(exc.ContextNotFound, self.client.get_user, 1,
                       self.user["name"])
     self.assertEqual(self.client.service.getData.call_count, 1)
 def _process_reply(self, service, vals=None, send_as_kw=False):
     """Schenker API returns error petitions as server exceptions wich makes zeep to
     raise a Fault exception as well. To catch the error info we need to make a
     raw_response request and the extract the error codes from the response."""
     try:
         if not send_as_kw:
             response = service(vals)
         else:
             response = service(**vals)
     except Fault as e:
         with self.client.settings(raw_response=True):
             if not send_as_kw:
                 response = service(vals)
             else:
                 response = service(**vals)
             try:
                 root = ET.fromstring(response.text)
                 error_text = next(root.iter("faultstring")).text
                 error_message = next(root.iter("message")).text
                 error_code = next(root.iter("code")).text
                 raise ValidationError(
                     _("Error in the request to the Schenker API. This is the "
                       "thrown message:\n\n"
                       "[%s]\n"
                       "%s - %s" % (error_text, error_code, error_message)))
             except ValidationError:
                 raise
             # If we can't get the proper exception, fallback to the first
             # exception error traceback
             except Exception:
                 raise Fault(e)
     return response
Esempio n. 9
0
async def test_flow_import_onvif_auth_error(hass):
    """Test that config flow fails when ONVIF API fails."""
    with patch(
        "homeassistant.components.onvif.config_flow.get_device"
    ) as mock_onvif_camera:
        setup_mock_onvif_camera(mock_onvif_camera)
        mock_onvif_camera.create_devicemgmt_service = MagicMock(
            side_effect=Fault("Auth Error")
        )

        result = await hass.config_entries.flow.async_init(
            config_flow.DOMAIN,
            context={"source": config_entries.SOURCE_IMPORT},
            data={
                config_flow.CONF_NAME: NAME,
                config_flow.CONF_HOST: HOST,
                config_flow.CONF_PORT: PORT,
                config_flow.CONF_USERNAME: USERNAME,
                config_flow.CONF_PASSWORD: PASSWORD,
            },
        )

        assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
        assert result["step_id"] == "auth"
        assert result["errors"]["base"] == "cannot_connect"
 def test_create_unknown_error(self):
     self.client.service.create.side_effect = [Fault("some failure")]
     self.assertRaises(Fault, self.client.create_context, {
         "id": 105,
         "loginMappings": ["tyrawr.com"]
     }, {"user_name": "some_admin"})
     self.assertEqual(self.client.service.create.call_count, 1)
 def test_delete_context_dne_error(self):
     self.client.service.delete.side_effect = [
         Fault('Authentication failed')
     ]
     self.assertRaises(exc.ContextNotFound, self.client.delete_user, 1,
                       self.user["name"])
     self.assertEqual(self.client.service.delete.call_count, 1)
 def test_update_product_user_dne_error(self):
     self.client.service.changeByModuleAccessName.side_effect = [
         Fault("No such user {} in context 1".format(self.user["name"]))
     ]
     self.assertRaises(exc.UserNotFound, self.client.update_user_product, 1,
                       self.user["name"], "gd_pim")
     self.assertEqual(
         self.client.service.changeByModuleAccessName.call_count, 1)
 def test_update_product_context_dne_error(self):
     self.client.service.changeByModuleAccessName.side_effect = [
         Fault('The context 1 does not exist!')
     ]
     self.assertRaises(exc.ContextNotFound, self.client.update_user_product,
                       1, self.user["name"], "gd_pim")
     self.assertEqual(
         self.client.service.changeByModuleAccessName.call_count, 1)
Esempio n. 14
0
def test_query_moira_lists_no_lists(mock_moira_client):
    """
    Test that an empty list is returned if Moira throws a java NPE
    """
    mock_moira_client.return_value.user_list_membership.side_effect = Fault(
        "java.lang.NullPointerException")
    other_user = factories.UserFactory(email="*****@*****.**")
    assert query_moira_lists(other_user) == []
Esempio n. 15
0
def test_query_moira_lists_error(mock_moira_client):
    """
    Test that a Moira exception is raised if moira client call fails with anything other than a java NPE
    """
    mock_moira_client.return_value.user_list_membership.side_effect = Fault(
        "Not a java NPE")
    with pytest.raises(MoiraException):
        query_moira_lists(factories.UserFactory())
 def test_delete_user_dne_error(self):
     self.client.service.delete.side_effect = [
         Fault("No such user {user} in context 1".format(
             user=self.user['name']))
     ]
     self.assertRaises(exc.UserNotFound, self.client.delete_user, 1,
                       self.user["name"])
     self.assertEqual(self.client.service.delete.call_count, 1)
 def test_update_product_unknown_error(self):
     self.client.service.changeByModuleAccessName.side_effect = [
         Fault("some failure")
     ]
     self.assertRaises(exc.OXException, self.client.update_user_product, 1,
                       self.user["name"], "gd_pim")
     self.assertEqual(
         self.client.service.changeByModuleAccessName.call_count, 1)
Esempio n. 18
0
    def process_error(self, doc, operation):
        fault_node = doc.find("soap-env:Body/soap-env:Fault", namespaces=self.nsmap)

        if fault_node is None:
            raise Fault(
                message="Unknown fault occured",
                code=None,
                actor=None,
                detail=etree_to_string(doc),
            )

        raise Fault(
            message=self.get_text(fault_node, "faultstring"),
            code=self.get_text(fault_node, "faultcode"),
            actor=self.get_text(fault_node, "faultactor"),
            detail=self.get_child_node(fault_node, "detail"),
        )
 def test_create_product_dne_error(self):
     self.client.service.createByModuleAccessName.side_effect = [
         Fault('No such access combination name "gd_pim"')
     ]
     self.assertRaises(exc.NoSuchProduct, self.client.create_user, 1,
                       self.user, "gd_pim")
     self.assertEqual(
         self.client.service.createByModuleAccessName.call_count, 1)
 def test_create_unknown_error(self):
     self.client.service.createByModuleAccessName.side_effect = [
         Fault("some failure")
     ]
     self.assertRaises(exc.OXException, self.client.create_user, 1,
                       self.user, "gd_pim")
     self.assertEqual(
         self.client.service.createByModuleAccessName.call_count, 1)
 def test_create_localpart_conflict_error(self):
     self.client.service.createByModuleAccessName.side_effect = [
         Fault("The displayname is already used")
     ]
     self.assertRaises(exc.UserConflict, self.client.create_user, 1,
                       self.user, "gd_pim")
     self.assertEqual(
         self.client.service.createByModuleAccessName.call_count, 1)
 def test_create_context_dne_error(self):
     self.client.service.createByModuleAccessName.side_effect = [
         Fault('Authentication failed')
     ]
     self.assertRaises(exc.ContextNotFound, self.client.create_user, 1,
                       self.user, "gd_pim")
     self.assertEqual(
         self.client.service.createByModuleAccessName.call_count, 1)
 def test_update_domain_in_use(self):
     self.client.service.change.side_effect = [
         Fault(
             'A mapping with login info "domain.com" already exists in the system!'
         )
     ]
     self.assertRaises(exc.DomainInUse, self.client.update_context, 1,
                       {"loginMappings": ["domain.com"]})
     self.assertEqual(self.client.service.change.call_count, 1)
Esempio n. 24
0
def setup_mock_onvif_camera(
    mock_onvif_camera,
    with_h264=True,
    two_profiles=False,
    with_interfaces=True,
    with_interfaces_not_implemented=False,
    with_serial=True,
):
    """Prepare mock onvif.ONVIFCamera."""
    devicemgmt = MagicMock()

    device_info = MagicMock()
    device_info.SerialNumber = SERIAL_NUMBER if with_serial else None
    devicemgmt.GetDeviceInformation = AsyncMock(return_value=device_info)

    interface = MagicMock()
    interface.Enabled = True
    interface.Info.HwAddress = MAC

    if with_interfaces_not_implemented:
        devicemgmt.GetNetworkInterfaces = AsyncMock(
            side_effect=Fault("not implemented"))
    else:
        devicemgmt.GetNetworkInterfaces = AsyncMock(
            return_value=[interface] if with_interfaces else [])

    media_service = MagicMock()

    profile1 = MagicMock()
    profile1.VideoEncoderConfiguration.Encoding = "H264" if with_h264 else "MJPEG"
    profile2 = MagicMock()
    profile2.VideoEncoderConfiguration.Encoding = "H264" if two_profiles else "MJPEG"

    media_service.GetProfiles = AsyncMock(return_value=[profile1, profile2])

    mock_onvif_camera.update_xaddrs = AsyncMock(return_value=True)
    mock_onvif_camera.create_devicemgmt_service = MagicMock(
        return_value=devicemgmt)
    mock_onvif_camera.create_media_service = MagicMock(
        return_value=media_service)
    mock_onvif_camera.close = AsyncMock(return_value=None)

    def mock_constructor(
        host,
        port,
        user,
        passwd,
        wsdl_dir,
        encrypt=True,
        no_cache=False,
        adjust_time=False,
        transport=None,
    ):
        """Fake the controller constructor."""
        return mock_onvif_camera

    mock_onvif_camera.side_effect = mock_constructor
 def test_create_email_conflict_error(self):
     self.client.service.createByModuleAccessName.side_effect = [
         Fault('Primary mail address "{}" already exists in context {}'.
               format(self.user["primaryEmail"], 1))
     ]
     self.assertRaises(exc.UserConflict, self.client.create_user, 1,
                       self.user, "gd_pim")
     self.assertEqual(
         self.client.service.createByModuleAccessName.call_count, 1)
 def test_create_uuid_conflict_error(self):
     self.client.service.createByModuleAccessName.side_effect = [
         Fault('User {} already exists in this context'.format(
             self.user["name"]))
     ]
     self.assertRaises(exc.UserConflict, self.client.create_user, 1,
                       self.user, "gd_pim")
     self.assertEqual(
         self.client.service.createByModuleAccessName.call_count, 1)
Esempio n. 27
0
def test_client_close_posting_list_error(mock_soap_client, client,
                                         posting_card, posting_list,
                                         shipping_label):
    mock_soap_client.side_effect = Fault(
        "A PLP não será fechada , o(s) objeto(s) [PP40233163BR] já estão "
        "vinculados em outra PLP!")
    shipping_label.posting_card = posting_card
    posting_list.add_shipping_label(shipping_label)
    with pytest.raises(ClosePostingListError):
        client.close_posting_list(posting_list, posting_card)
Esempio n. 28
0
    def process_error(self, doc, operation):
        fault_node = doc.find('soap-env:Body/soap-env:Fault',
                              namespaces=self.nsmap)

        if fault_node is None:
            raise Fault(message='Unknown fault occured',
                        code=None,
                        actor=None,
                        detail=etree_to_string(doc))

        def get_text(name):
            child = fault_node.find(name)
            if child is not None:
                return child.text

        raise Fault(message=get_text('faultstring'),
                    code=get_text('faultcode'),
                    actor=get_text('faultactor'),
                    detail=fault_node.find('detail'))
 def test_create_domain_in_use(self):
     self.client.service.create.side_effect = [
         Fault(
             "Cannot map 'tyrawr.com' to the newly created context. This mapping is already in use."
         )
     ]
     self.assertRaises(exc.DomainInUse, self.client.create_context, {
         "id": 105,
         "loginMappings": ["tyrawr.com"]
     }, {"user_name": "some_admin"})
     self.assertEqual(self.client.service.create.call_count, 1)
Esempio n. 30
0
    def process_error(self, doc, operation):
        fault_node = doc.find("soap-env:Body/soap-env:Fault", namespaces=self.nsmap)

        if fault_node is None:
            raise Fault(
                message="Unknown fault occured",
                code=None,
                actor=None,
                detail=etree_to_string(doc),
            )

        def get_text(name):
            child = fault_node.find(name)
            if child is not None:
                return child.text

        raise Fault(
            message=get_text("faultstring"),
            code=get_text("faultcode"),
            actor=get_text("faultactor"),
            detail=fault_node.find("detail"),
        )