def test_missing_leader(self, subprocess):
        subprocess.Popen.return_value.communicate.return_value.__getitem__ \
            .return_value = \
            (
                'Topic:test   PartitionCount:1        ReplicationFactor:2     '
                'Configs:retention.ms=8640000 \n'
                '    Topic: test  Partition: 0    Leader:       Replicas: 3,'
                '2   Isr: \n')

        assert kafka_topic_enforcer.get_and_parse_existing_topic_config() == {
            'test': {
                'PartitionCount': '1',
                'ReplicationFactor': '2',
                'Topic': 'test',
                'Configs': {
                    'retention.ms': '8640000'
                },
                'partitions': [
                    {
                        'topic': 'test',
                        'partition': '0',
                        'replicas': ['3', '2']
                    }
                ]
            }
        }
        subprocess.Popen.assert_called_with(
            ['kafka/home/bin/kafka-topics.sh', '--zookeeper',
             'localhost:2181', '--describe'],
            stdout=subprocess.PIPE)
    def test_incorrect_topic_name_for_partition(self, subprocess):
        subprocess.Popen.return_value.communicate.return_value.__getitem__ \
            .return_value = \
            (
                'Topic:test   PartitionCount:1        ReplicationFactor:2     '
                'Configs:retention.ms=8640000 \n'
                '    Topic: wrong_name  Partition: 0    Leader:       '
                'Replicas: '
                '3,2   Isr: \n')

        with pytest.raises(KeyError):
            kafka_topic_enforcer.get_and_parse_existing_topic_config()
        subprocess.Popen.assert_called_with(
            ['kafka/home/bin/kafka-topics.sh', '--zookeeper',
             'localhost:2181', '--describe'],
            stdout=subprocess.PIPE)
    def test_normal_empty_config(self, subprocess):
        subprocess.Popen.return_value.communicate.return_value[0] = ''

        assert kafka_topic_enforcer.get_and_parse_existing_topic_config() == {}
        subprocess.Popen.assert_called_with(
            ['kafka/home/bin/kafka-topics.sh', '--zookeeper',
             'localhost:2181', '--describe'],
            stdout=subprocess.PIPE)