<commit_before># This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest

import models.base as mbase
import models.boot as mboot


class TestBootModel(unittest.TestCase):

    def test_boot_document_valid_instance(self):
        boot_doc = mboot.BootDocument(
            "board", "job", "kernel", "defconfig", "lab"
        )
        self.assertIsInstance(boot_doc, mbase.BaseDocument)

    def test_boot_document_to_dict(self):
        self.maxDiff = None
        boot_doc = mboot.BootDocument(
            "board", "job", "kernel", "defconfig", "lab", arch="arm"
        )
        boot_doc.id = "id"
        boot_doc.job_id = "job-id"
        boot_doc.created_on = "now"
        boot_doc.defconfig_id = "defconfig_id"
        boot_doc.retries = 10
        boot_doc.version = "1.0"
        boot_doc.dtb_append = False
        boot_doc.boot_log = "boot-log"
        boot_doc.boot_log_html = "boot-log-html"
        boot_doc.warnings = 2
        boot_doc.git_branch = "git-branch"
        boot_doc.git_commit = "git-commit"
        boot_doc.git_describe = "git-describe"
        boot_doc.git_url = "git-url"
        boot_doc.fastboot_cmd = "fastboot"
        boot_doc.defconfig_full = "defconfig"
        boot_doc.file_server_url = "file-server"
        boot_doc.file_server_resource = "file-resource"
        boot_doc.initrd = "initrd"
        boot_doc.board_instance = "instance"
        boot_doc.uimage = "path/to/uImage"
        boot_doc.uimage_addr = "uimage_addr"
        boot_doc.qemu = "qemu_binary"
        boot_doc.qemu_command = "qemu_command"
        boot_doc.metadata = {"foo": "bar"}
        boot_doc.mach = "soc"

        expected = {
            "_id": "id",
            "arch": "arm",
            "board": "board",
            "board_instance": "instance",
            "boot_log": "boot-log",
            "boot_log_html": "boot-log-html",
            "boot_result_description": None,
            "created_on": "now",
            "defconfig": "defconfig",
            "defconfig_full": "defconfig",
            "defconfig_id": "defconfig_id",
            "dtb": None,
            "dtb_addr": None,
            "dtb_append": False,
            "endian": None,
            "fastboot": False,
            "fastboot_cmd": "fastboot",
            "file_server_resource": "file-resource",
            "file_server_url": "file-server",
            "git_branch": "git-branch",
            "git_commit": "git-commit",
            "git_describe": "git-describe",
            "git_url": "git-url",
            "initrd": "initrd",
            "initrd_addr": None,
            "job": "job",
            "job_id": "job-id",
            "kernel": "kernel",
            "kernel_image": None,
            "lab_name": "lab",
            "load_addr": None,
            "mach": "soc",
            "metadata": {"foo": "bar"},
            "name": "board-job-kernel-defconfig-arm",
            "qemu": "qemu_binary",
            "qemu_command": "qemu_command",
            "retries": 10,
            "status": None,
            "time": 0,
            "uimage": "path/to/uImage",
            "uimage_addr": "uimage_addr",
            "version": "1.0",
            "warnings": 2
        }

        self.assertDictEqual(expected, boot_doc.to_dict())

    def test_boot_doc_from_json_missing_key(self):
        boot_json = {
            "_id": "id",
            "name": "boot-name",
            "status": "PASS",
            "warnings": 0
        }

        self.assertIsNone(mboot.BootDocument.from_json(boot_json))

    def test_boot_doc_from_json_wrong_type(self):
        self.assertIsNone(mboot.BootDocument.from_json([]))
        self.assertIsNone(mboot.BootDocument.from_json(()))
        self.assertIsNone(mboot.BootDocument.from_json(""))

    def test_boot_doc_from_json(self):
        self.maxDiff = None
        boot_json = {
            "_id": "id",
            "arch": "arm",
            "board": "board",
            "board_instance": "instance",
            "boot_log": "boot-log",
            "boot_log_html": "boot-log-html",
            "boot_result_description": "desc",
            "created_on": "now",
            "defconfig": "defconfig",
            "defconfig_full": "defconfig_full",
            "defconfig_id": "defconfig_id",
            "dtb": "dtb_val",
            "dtb_addr": "1234",
            "dtb_append": False,<commit_msg>Remove not needed tests function.<commit_after># This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest

import models.base as mbase
import models.boot as mboot


class TestBootModel(unittest.TestCase):

    def test_boot_document_valid_instance(self):
        boot_doc = mboot.BootDocument(
            "board", "job", "kernel", "defconfig", "lab"
        )
        self.assertIsInstance(boot_doc, mbase.BaseDocument)

    def test_boot_document_to_dict(self):
        boot_doc = mboot.BootDocument(
            "board", "job", "kernel", "defconfig", "lab", arch="arm"
        )
        boot_doc.id = "id"
        boot_doc.job_id = "job-id"
        boot_doc.created_on = "now"
        boot_doc.defconfig_id = "defconfig_id"
        boot_doc.retries = 10
        boot_doc.version = "1.0"
        boot_doc.dtb_append = False
        boot_doc.boot_log = "boot-log"
        boot_doc.boot_log_html = "boot-log-html"
        boot_doc.warnings = 2
        boot_doc.git_branch = "git-branch"
        boot_doc.git_commit = "git-commit"
        boot_doc.git_describe = "git-describe"
        boot_doc.git_url = "git-url"
        boot_doc.fastboot_cmd = "fastboot"
        boot_doc.defconfig_full = "defconfig"
        boot_doc.file_server_url = "file-server"
        boot_doc.file_server_resource = "file-resource"
        boot_doc.initrd = "initrd"
        boot_doc.board_instance = "instance"
        boot_doc.uimage = "path/to/uImage"
        boot_doc.uimage_addr = "uimage_addr"
        boot_doc.qemu = "qemu_binary"
        boot_doc.qemu_command = "qemu_command"
        boot_doc.metadata = {"foo": "bar"}
        boot_doc.mach = "soc"

        expected = {
            "_id": "id",
            "arch": "arm",
            "board": "board",
            "board_instance": "instance",
            "boot_log": "boot-log",
            "boot_log_html": "boot-log-html",
            "boot_result_description": None,
            "created_on": "now",
            "defconfig": "defconfig",
            "defconfig_full": "defconfig",
            "defconfig_id": "defconfig_id",
            "dtb": None,
            "dtb_addr": None,
            "dtb_append": False,
            "endian": None,
            "fastboot": False,
            "fastboot_cmd": "fastboot",
            "file_server_resource": "file-resource",
            "file_server_url": "file-server",
            "git_branch": "git-branch",
            "git_commit": "git-commit",
            "git_describe": "git-describe",
            "git_url": "git-url",
            "initrd": "initrd",
            "initrd_addr": None,
            "job": "job",
            "job_id": "job-id",
            "kernel": "kernel",
            "kernel_image": None,
            "lab_name": "lab",
            "load_addr": None,
            "mach": "soc",
            "metadata": {"foo": "bar"},
            "name": "board-job-kernel-defconfig-arm",
            "qemu": "qemu_binary",
            "qemu_command": "qemu_command",
            "retries": 10,
            "status": None,
            "time": 0,
            "uimage": "path/to/uImage",
            "uimage_addr": "uimage_addr",
            "version": "1.0",
            "warnings": 2
        }

        self.assertDictEqual(expected, boot_doc.to_dict())

    def test_boot_doc_from_json_missing_key(self):
        boot_json = {
            "_id": "id",
            "name": "boot-name",
            "status": "PASS",
            "warnings": 0
        }

        self.assertIsNone(mboot.BootDocument.from_json(boot_json))

    def test_boot_doc_from_json_wrong_type(self):
        self.assertIsNone(mboot.BootDocument.from_json([]))
        self.assertIsNone(mboot.BootDocument.from_json(()))
        self.assertIsNone(mboot.BootDocument.from_json(""))

    def test_boot_doc_from_json(self):
        boot_json = {
            "_id": "id",
            "arch": "arm",
            "board": "board",
            "board_instance": "instance",
            "boot_log": "boot-log",
            "boot_log_html": "boot-log-html",
            "boot_result_description": "desc",
            "created_on": "now",
            "defconfig": "defconfig",
            "defconfig_full": "defconfig_full",
            "defconfig_id": "defconfig_id",
            "dtb": "dtb_val",
            "dtb_addr": "1234",
            "dtb_append": False,
{'fraction_non_alphanumeric': 0.12767893247068338, 'fraction_numerical': 0.0034371209057824505, 'mean_word_length': 2.089631480324797, 'pattern_counts': {'":': 126, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1193526', 'n_tokens_mistral': 3097, 'n_tokens_neox': 3042, 'n_words': 661}