def test_payload_sent_to_rabbitmq(self, mocked_rabbit):
        """
        Tests that a payload is sent to rabbitmq and that it contains the
        expected payload.
        """

        instance_rabbit = mocked_rabbit.return_value
        instance_rabbit.__enter__.return_value = instance_rabbit
        instance_rabbit.__exit__.return_value = None
        instance_rabbit.publish.side_effect = None

        payload = {
            "exchange": "test",
            "route": "test",
            "repository": "important-service",
            "commit": "da89fuhds",
            "environment": "staging",
            "author": "author",
            "tag": "da89fuhds",
        }
        payload_copy = payload.copy()

        GithubListener.push_rabbitmq(payload_copy)

        self.assertTrue(mocked_rabbit.called)

        c = instance_rabbit.publish.call_args[1]

        self.assertEqual(c["route"], payload.pop("route"))
        self.assertEqual(c["exchange"], payload.pop("exchange"))

        p = json.loads(c["payload"])
        for key in payload:
            self.assertEqual(payload[key], p.get(key, None), msg='key "{}" not found in call {}'.format(key, p))
Exemple #2
0
    def test_payload_sent_to_rabbitmq(self, mocked_rabbit):
        """
        Tests that a payload is sent to rabbitmq and that it contains the
        expected payload.
        """

        instance_rabbit = mocked_rabbit.return_value
        instance_rabbit.__enter__.return_value = instance_rabbit
        instance_rabbit.__exit__.return_value = None
        instance_rabbit.publish.side_effect = None

        payload = OrderedDict([
            ('application', 'important-service'),
            ('commit', 'd8fgdfgdf'),
            ('environment', 'staging'),
            ('author', 'author'),
            ('tag', 'dsfdsf')
        ])

        GithubListener.push_rabbitmq(payload=payload, exchange='test', route='test')

        self.assertTrue(mocked_rabbit.called)

        instance_rabbit.publish.assert_has_calls(
            [mock.call(payload=json.dumps(payload), exchange='test', route='test')]
        )