Пример #1
0
    def test_ensure_present_nothing_to_do(
        self, create_module, table_client, attachment_client
    ):
        module = create_module(
            params=dict(
                instance=dict(host="my.host.name", username="******", password="******"),
                state="new",
                number="INC0000001",
                caller=None,
                short_description="Test incident",
                impact=None,
                urgency=None,
                sys_id=None,
                description=None,
                close_code=None,
                close_notes=None,
                hold_reason=None,
                other=None,
                attachments=None,
            ),
        )
        table_client.get_record.return_value = dict(
            state="1",
            number="INC0000001",
            short_description="Test incident",
            sys_id="1234",
        )
        attachment_client.update_records.return_value = []
        attachment_client.list_records.return_value = []

        result = incident.ensure_present(module, table_client, attachment_client)

        table_client.get_record.assert_called_once()
        assert result == (
            False,
            dict(
                state="new",
                number="INC0000001",
                short_description="Test incident",
                attachments=[],
                sys_id="1234",
            ),
            dict(
                before=dict(
                    state="new",
                    number="INC0000001",
                    short_description="Test incident",
                    attachments=[],
                    sys_id="1234",
                ),
                after=dict(
                    state="new",
                    number="INC0000001",
                    short_description="Test incident",
                    attachments=[],
                    sys_id="1234",
                ),
            ),
        )
Пример #2
0
    def test_ensure_present_create_new(
        self, create_module, table_client, attachment_client
    ):
        module = create_module(
            params=dict(
                instance=dict(host="my.host.name", username="******", password="******"),
                state="new",
                caller=None,
                short_description="Test incident",
                impact="test low",
                urgency="test low",
                number=None,
                sys_id=None,
                description=None,
                close_code=None,
                close_notes=None,
                hold_reason=None,
                other=None,
                attachments=None,
                incident_mapping=self.INCIDENT_MAPPING,
            ),
        )
        table_client.create_record.return_value = dict(
            state="1",
            number="INC0000001",
            short_description="Test incident",
            impact="3",
            urgency="3",
            sys_id="1234",
        )
        attachment_client.upload_records.return_value = []

        result = incident.ensure_present(module, table_client, attachment_client)

        table_client.create_record.assert_called_once()
        assert result == (
            True,
            dict(
                state="new",
                number="INC0000001",
                short_description="Test incident",
                impact="test low",
                urgency="low",
                sys_id="1234",
                attachments=[],
            ),
            dict(
                before=None,
                after=dict(
                    state="new",
                    number="INC0000001",
                    short_description="Test incident",
                    impact="test low",
                    urgency="low",
                    sys_id="1234",
                    attachments=[],
                ),
            ),
        )
Пример #3
0
    def test_ensure_present_update(self, mocker, create_module, table_client):
        module = create_module(
            params=dict(
                instance=dict(host="my.host.name", username="******", password="******"),
                state="in_progress",
                number="INC0000001",
                caller="admin",
                short_description="Test incident",
                impact=None,
                urgency=None,
                sys_id=None,
                description=None,
                close_code=None,
                close_notes=None,
                hold_reason=None,
                other=None,
            ),
        )
        payload_mocker = mocker.patch.object(incident, "build_payload")
        payload_mocker.return_value = dict(
            state="in_progress", number="INC0000001", short_description="Test incident"
        )
        table_client.get_record.return_value = dict(
            state="1", number="INC0000001", short_description="Test incident"
        )
        table_client.update_record.return_value = dict(
            state="2", number="INC0000001", short_description="Test incident"
        )

        result = incident.ensure_present(module, table_client)

        table_client.update_record.assert_called_once()
        assert result == (
            True,
            dict(
                state="in_progress",
                number="INC0000001",
                short_description="Test incident",
            ),
            dict(
                before=dict(
                    state="new", number="INC0000001", short_description="Test incident"
                ),
                after=dict(
                    state="in_progress",
                    number="INC0000001",
                    short_description="Test incident",
                ),
            ),
        )