Пример #1
0
    def test_proper_message_multiple(self):
        """Assert proper json is returned"""
        test_topic = "test topic"
        test_body = {"test_key": "test_value"}
        test_queue = "test queue"
        test_id = "test id"
        test_headers = {
            "fedora_messaging_schema": "base.message",
            "fedora_messaging_severity": message.WARNING,
        }
        test_properties = pika.BasicProperties(
            content_type="application/json",
            content_encoding="utf-8",
            delivery_mode=2,
            headers=test_headers,
            message_id=test_id,
        )
        test_msg = message.Message(
            body=test_body, topic=test_topic, properties=test_properties
        )
        test_msg2 = message.Message(
            body=test_body, topic=test_topic, properties=test_properties
        )
        test_msg.queue = test_queue
        test_msg2.queue = test_queue
        expected_json = (
            '{"body": {"test_key": "test_value"}, "headers": {"fedora_messaging_schema": '
            '"base.message", "fedora_messaging_severity": 30}, "id": "test id", "queue": '
            '"test queue", "topic": "test topic"}\n'
            '{"body": {"test_key": "test_value"}, "headers": {"fedora_messaging_schema": '
            '"base.message", "fedora_messaging_severity": 30}, "id": "test id", "queue": '
            '"test queue", "topic": "test topic"}\n'
        )

        self.assertEqual(expected_json, message.dumps([test_msg, test_msg2]))
Пример #2
0
    def test_user_update_v1(self):
        """
        Test UserUpdateV1

        The expected message here is:

        {
        "body": {
            "msg": {
            "agent": "dudemcpants",
            "user": "******",
            "fields": ["firstname", "lastname", "gpgkeyid"]
            }
        },
        "headers": {
            "fedora_messaging_schema": "noggin.user.update.v1",
            "fedora_messaging_severity": 20,
            "sent-at": "2020-03-02T08:53:38+00:00"
        },
        "id": "c795df0d-3a95-47a9-85c4-7fabf3129ddf",
        "queue": null,
        "topic": "fas.user.update"
        }

        """

        msg = UserUpdateV1({
            "msg": {
                "agent": "dudemcpants",
                "user": "******",
                "fields": ["firstname", "lastname", "gpgkeyid"],
            }
        })
        msg.validate()

        msg_dump = json.loads(message.dumps(msg))
        assert msg_dump["body"]["msg"]["agent"] == "dudemcpants"
        assert msg_dump["body"]["msg"]["user"] == "testuser"
        assert msg_dump["body"]["msg"]["fields"] == [
            "firstname",
            "lastname",
            "gpgkeyid",
        ]
        assert msg_dump["headers"][
            "fedora_messaging_schema"] == "noggin.user.update.v1"
        assert msg_dump["topic"] == "fas.user.update"
Пример #3
0
    def test_member_sponsor_v1(self):
        """
        Test MemberSponsorV1

        The expected message here is:

        {
        "body": {
            "msg": {
            "agent": "dudemcpants",
            "group": "developers",
            "user": "******"
            }
        },
        "headers": {
            "fedora_messaging_schema": "noggin.group.member.sponsor.v1",
            "fedora_messaging_severity": 20,
            "sent-at": "2020-03-02T08:53:38+00:00"
        },
        "id": "c795df0d-3a95-47a9-85c4-7fabf3129ddf",
        "queue": null,
        "topic": "fas.group.member.sponsor"
        }

        """

        msg = MemberSponsorV1({
            "msg": {
                "agent": "dudemcpants",
                "user": "******",
                "group": "developers"
            }
        })
        msg.validate()

        msg_dump = json.loads(message.dumps(msg))
        assert msg_dump["body"]["msg"]["agent"] == "dudemcpants"
        assert msg_dump["body"]["msg"]["user"] == "testuser"
        assert msg_dump["body"]["msg"]["group"] == "developers"
        assert (msg_dump["headers"]["fedora_messaging_schema"] ==
                "noggin.group.member.sponsor.v1")
        assert msg_dump["topic"] == "fas.group.member.sponsor"
Пример #4
0
def callback(message):
    print(message)
    serialized = dumps(message)
    with open(DESTINATION, "a") as f:
        f.write(serialized)
        f.write("\n")