<commit_before>import unittest
import xml.etree.ElementTree as ET

import tutil
from webvulnscan import utils


class UtilsTest(unittest.TestCase):
    def test_find_get_parameters(self):
        link = 'http://random.host/?x=y&z=x'
        self.assertEqual(utils.find_get_parameters(link), ["x", "z"])

    def test_find_parameter_values(self):
        link = 'http://random.host/?x=y&z=x'
        self.assertEqual(utils.find_parameter_values(link), ["y", "x"])

    def test_change_parameter(self):
        link = 'http://x.yz/?val=22&other=11'
        self.assertEqual(utils.change_parameter(link, "val", "42"),
                         'http://x.yz/?val=42&other=11')

    def test_get_url_host(self):
        link = 'http://random.host/test/value'
        self.assertEqual(utils.get_url_host(link), "random.host")

    def test_get_page(self):
        # First, test for valid XML input.
        def get_plain_text(url, parameters=None, cookies=None):
            return "<html><a></a></html>"
        utils.get_plain_text = get_plain_text
        expect = ET.tostring(ET.fromstring(get_plain_text("")))
        result = ET.tostring(utils.get_page("http://x/"))
        self.assertEqual(expect, result)
        # Second, test for wrong input.
        def get_plain_none(url, parameters=None, cookies=None):
            return None
        utils.get_plain_text = get_plain_none
        self.assertEqual(None, utils.get_page("http://test/"))
<commit_msg>testing: Added serveral test cases<commit_after>import unittest
import xml.etree.ElementTree as ET

import tutil
from webvulnscan import utils


class UtilsTest(unittest.TestCase):
    def test_find_get_parameters(self):
        link = 'http://random.host/?x=y&z=x'
        self.assertEqual(utils.find_get_parameters(link), ["x", "z"])

    def test_find_parameter_values(self):
        link = 'http://random.host/?x=y&z=x'
        self.assertEqual(utils.find_parameter_values(link), ["y", "x"])

    def test_change_parameter(self):
        link = 'http://x.yz/?val=22&other=11'
        self.assertEqual(utils.change_parameter(link, "val", "42"),
                         'http://x.yz/?val=42&other=11')

    def test_get_url_host(self):
        link = 'http://random.host/test/value'
        self.assertEqual(utils.get_url_host(link), "random.host")

    def test_get_page(self):
        # First, test for valid XML input.
        def get_plain_text(url, parameters=None, cookies=None):
            return "<html><a></a></html>"
        utils.get_plain_text = get_plain_text
        expect = ET.tostring(ET.fromstring(get_plain_text("")))
        result = ET.tostring(utils.get_page("http://x/"))
        self.assertEqual(expect, result)
        # Second, test for wrong input.
        def get_plain_none(url, parameters=None, cookies=None):
            return None
        utils.get_plain_text = get_plain_none
        self.assertEqual(None, utils.get_page("http://test/"))
{'fraction_non_alphanumeric': 0.1422237380627558, 'fraction_numerical': 0.0068212824010914054, 'mean_word_length': 3.0399449035812673, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '7347703', 'n_tokens_mistral': 965, 'n_tokens_neox': 933, 'n_words': 162}