def test_send(self, publish_mock, topic_path_mock):
     publish_mock.return_value = '123'
     topic_path_mock.return_value = 'projects/p_id/topics/a-publisher'
     client = pubsub.PubSub(topic_name='a-publisher', project_id='p_id')
     result = client.send(message='')
     publish_mock.assert_called_with('projects/p_id/topics/a-publisher', b'')
     assert result == '123'
 def test_retrying_send(self, publish_mock):
     publish_mock.side_effect = [
         ConnectionResetError, '123'
     ]
     client = pubsub.PubSub(topic_name='a-publisher', project_id='p_id')
     result = client.send(message='')
     assert result == '123'
    def test_receive(self, pull_mock):
        def callback(message):
            assert message.message_id == 1

        valid_response = self.valid_response_factory(message_id=1)
        pull_mock.side_effect = callback(valid_response)
        client = pubsub.PubSub(topic_name=mock.Mock(), project_id='')
        client.receive(callback=callback)
    def test_assert_in_receive_callback(self, pull_mock):
        def callback(message):
            assert message.message_id == 0

        valid_response = self.valid_response_factory(message_id=1)
        with pytest.raises(AssertionError):
            pull_mock.side_effect = callback(valid_response)
        client = pubsub.PubSub(topic_name=mock.Mock(), project_id='')
        client.receive(callback=callback)