<commit_before># -*- coding: utf-8 -*-
"""
Testing HTTP collector
"""

import unittest

import intelmq.lib.test as test
import intelmq.lib.utils as utils
from intelmq.bots.collectors.http.collector_http import HTTPCollectorBot


OUTPUT = [{"__type": "Report",
           "feed.name": "Example feed",
           "feed.accuracy": 100.,
           "feed.url": "http://localhost/two_files.tar.gz",
           "raw": utils.base64_encode('bar text\n'),
           },
          {"__type": "Report",
           "feed.name": "Example feed",
           "feed.accuracy": 100.,
           "feed.url": "http://localhost/two_files.tar.gz",
           "raw": utils.base64_encode('foo text\n'),
           },
          ]


@test.skip_local_web()
class TestHTTPCollectorBot(test.BotTestCase, unittest.TestCase):
    """
    A TestCase for HTTPCollectorBot.
    """

    @classmethod
    def set_bot(cls):
        cls.bot_reference = HTTPCollectorBot
        cls.sysconfig = {'http_url': 'http://localhost/two_files.tar.gz',
                         'extract_files': True,
                         'feed': 'Example feed',
                         }

    def test_events(self):
        """ Test if correct Events have been produced. """
        self.input_message = None
        self.run_bot(iterations=1)

        self.assertMessageEqual(0, OUTPUT[0])
        self.assertMessageEqual(1, OUTPUT[1])

    def test_formatting(self):
        """ Test if correct Events have been produced. """
        self.input_message = None
        self.sysconfig = {'http_url': 'http://localhost/{time[%Y]}.txt',
                          'extract_files': None,
                          'feed': 'Example feed',
                          'http_url_formatting': True,
                          }
        self.run_bot(iterations=1)


if __name__ == '__main__':  # pragma: no cover
    unittest.main()
<commit_msg>TST: Fix tests for http collector formatting<commit_after># -*- coding: utf-8 -*-
"""
Testing HTTP collector
"""

import unittest

import intelmq.lib.test as test
import intelmq.lib.utils as utils
from intelmq.bots.collectors.http.collector_http import HTTPCollectorBot


OUTPUT = [{"__type": "Report",
           "feed.name": "Example feed",
           "feed.accuracy": 100.,
           "feed.url": "http://localhost/two_files.tar.gz",
           "raw": utils.base64_encode('bar text\n'),
           },
          {"__type": "Report",
           "feed.name": "Example feed",
           "feed.accuracy": 100.,
           "feed.url": "http://localhost/two_files.tar.gz",
           "raw": utils.base64_encode('foo text\n'),
           },
          ]


@test.skip_local_web()
class TestHTTPCollectorBot(test.BotTestCase, unittest.TestCase):
    """
    A TestCase for HTTPCollectorBot.
    """

    @classmethod
    def set_bot(cls):
        cls.bot_reference = HTTPCollectorBot
        cls.sysconfig = {'http_url': 'http://localhost/two_files.tar.gz',
                         'extract_files': True,
                         'feed': 'Example feed',
                         }

    def test_events(self):
        """ Test if correct Events have been produced. """
        self.input_message = None
        self.run_bot(iterations=1)

        self.assertMessageEqual(0, OUTPUT[0])
        self.assertMessageEqual(1, OUTPUT[1])

    def test_formatting(self):
        """ Test if correct Events have been produced. """
        self.input_message = None
        self.allowed_warning_count = 1  # message has empty raw
        self.sysconfig = {'http_url': 'http://localhost/{time[%Y]}.txt',
                          'extract_files': None,
                          'feed': 'Example feed',
                          'http_url_formatting': True,
                          }
        self.run_bot(iterations=1)


if __name__ == '__main__':  # pragma: no cover
    unittest.main()

{'fraction_non_alphanumeric': 0.1341304912919158, 'fraction_numerical': 0.009097998440343124, 'mean_word_length': 1.9668465690053971, 'pattern_counts': {'":': 20, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5558325', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1115, 'n_words': 234}