Пример #1
0
 def test_raises_whne_id_exists(self, does_id_exists):
     does_id_exists.return_value = True
     assert_raise_library_error(
         lambda: lib.validate_id_does_not_exist("tree", "some-id"),
         (
             severities.ERROR,
             report_codes.ID_ALREADY_EXISTS,
             {"id": "some-id"},
         ),
     )
     does_id_exists.assert_called_once_with("tree", "some-id")
Пример #2
0
 def test_raises_whne_id_exists(self, does_id_exists):
     does_id_exists.return_value = True
     assert_raise_library_error(
         lambda: lib.validate_id_does_not_exist("tree", "some-id"),
         (
             severities.ERROR,
             report_codes.ID_ALREADY_EXISTS,
             {"id": "some-id"},
         ),
     )
     does_id_exists.assert_called_once_with("tree", "some-id")
Пример #3
0
def add_recipient(
    reporter: ReportProcessor,
    tree,
    alert_id,
    recipient_value,
    recipient_id=None,
    description="",
    allow_same_value=False,
):
    """
    Add recipient to alert with specified id. Returns added recipient element.
    Raises LibraryError if alert with specified recipient_id doesn't exist.
    Raises LibraryError if recipient already exists.

    reporter -- report processor
    tree -- cib etree node
    alert_id -- id of alert which should be parent of new recipient
    recipient_value -- value of recipient
    recipient_id -- id of new recipient, if None it will be generated
    description -- description of recipient
    allow_same_value -- if True unique recipient value is not required
    """
    if recipient_id is None:
        recipient_id = find_unique_id(tree, "{0}-recipient".format(alert_id))
    else:
        validate_id_does_not_exist(tree, recipient_id)

    alert = find_alert(get_alerts(tree), alert_id)
    ensure_recipient_value_is_unique(reporter,
                                     alert,
                                     recipient_value,
                                     allow_duplicity=allow_same_value)
    recipient = etree.SubElement(alert,
                                 "recipient",
                                 id=recipient_id,
                                 value=recipient_value)

    if description:
        recipient.attrib["description"] = description

    return recipient
Пример #4
0
def add_recipient(
    reporter,
    tree,
    alert_id,
    recipient_value,
    recipient_id=None,
    description="",
    allow_same_value=False
):
    """
    Add recipient to alert with specified id. Returns added recipient element.
    Raises LibraryError if alert with specified recipient_id doesn't exist.
    Raises LibraryError if recipient already exists.

    reporter -- report processor
    tree -- cib etree node
    alert_id -- id of alert which should be parent of new recipient
    recipient_value -- value of recipient
    recipient_id -- id of new recipient, if None it will be generated
    description -- description of recipient
    allow_same_value -- if True unique recipient value is not required
    """
    if recipient_id is None:
        recipient_id = find_unique_id(tree, "{0}-recipient".format(alert_id))
    else:
        validate_id_does_not_exist(tree, recipient_id)

    alert = find_alert(get_alerts(tree), alert_id)
    ensure_recipient_value_is_unique(
        reporter, alert, recipient_value, allow_duplicity=allow_same_value
    )
    recipient = etree.SubElement(
        alert, "recipient", id=recipient_id, value=recipient_value
    )

    if description:
        recipient.set("description", description)

    return recipient
Пример #5
0
 def test_success_when_id_does_not_exists(self, does_id_exists):
     does_id_exists.return_value = False
     lib.validate_id_does_not_exist("tree", "some-id")
     does_id_exists.assert_called_once_with("tree", "some-id")
Пример #6
0
 def test_success_when_id_does_not_exists(self, does_id_exists):
     does_id_exists.return_value = False
     lib.validate_id_does_not_exist("tree", "some-id")
     does_id_exists.assert_called_once_with("tree", "some-id")