Esempio n. 1
0
    def test_zaqar_publisher_config(self):
        """Test publisher config parameters."""
        parsed_url = urlparse.urlparse('zaqar://')
        self.assertRaises(ValueError, zaqar.ZaqarPublisher,
                          self.CONF, parsed_url)

        parsed_url = urlparse.urlparse('zaqar://?queue=foo&ttl=bar')
        self.assertRaises(ValueError, zaqar.ZaqarPublisher,
                          self.CONF, parsed_url)

        parsed_url = urlparse.urlparse('zaqar://?queue=foo&ttl=60')
        publisher = zaqar.ZaqarPublisher(self.CONF, parsed_url)
        self.assertEqual(60, publisher.ttl)

        parsed_url = urlparse.urlparse('zaqar://?queue=foo')
        publisher = zaqar.ZaqarPublisher(self.CONF, parsed_url)
        self.assertEqual(3600, publisher.ttl)
        self.assertEqual('foo', publisher.queue_name)
Esempio n. 2
0
    def test_zaqar_post_samples(self, mock_queue):
        """Test publisher post."""
        parsed_url = urlparse.urlparse('zaqar://?queue=foo')
        publisher = zaqar.ZaqarPublisher(self.CONF, parsed_url)
        mock_post = mock.Mock()
        mock_queue.return_value = mock_post

        publisher.publish_samples(self.sample_data)

        mock_queue.assert_called_once_with(mock.ANY, 'foo')
        self.assertEqual(3, len(mock_post.post.call_args_list[0][0][0]))
        self.assertEqual(mock_post.post.call_args_list[0][0][0][0]['body'],
                         self.sample_data[0].as_dict())