aboutsummaryrefslogtreecommitdiff
path: root/app/models/tests/test_boot_model.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/tests/test_boot_model.py')
-rw-r--r--app/models/tests/test_boot_model.py137
1 files changed, 100 insertions, 37 deletions
diff --git a/app/models/tests/test_boot_model.py b/app/models/tests/test_boot_model.py
index 90c12a2..7fbc9f5 100644
--- a/app/models/tests/test_boot_model.py
+++ b/app/models/tests/test_boot_model.py
@@ -13,26 +13,26 @@
import unittest
-import models.base as modb
-import models.boot as modbt
+import models.base as mbase
+import models.boot as mboot
class TestBootModel(unittest.TestCase):
def test_boot_document_valid_instance(self):
- boot_doc = modbt.BootDocument(
- 'board', 'job', 'kernel', 'defconfig', 'lab'
+ boot_doc = mboot.BootDocument(
+ "board", "job", "kernel", "defconfig", "lab"
)
- self.assertIsInstance(boot_doc, modb.BaseDocument)
+ self.assertIsInstance(boot_doc, mbase.BaseDocument)
def test_boot_document_to_dict(self):
self.maxDiff = None
- boot_doc = modbt.BootDocument(
- 'board', 'job', 'kernel', 'defconfig', 'lab', arch='arm'
+ 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.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"
@@ -52,33 +52,33 @@ class TestBootModel(unittest.TestCase):
boot_doc.board_instance = "instance"
expected = {
- '_id': 'id',
- 'board': 'board',
- 'boot_log': "boot-log",
- 'boot_log_html': "boot-log-html",
- 'boot_result_description': None,
- 'created_on': 'now',
- 'defconfig': 'defconfig',
- 'defconfig_id': "defconfig_id",
- 'dtb': None,
- 'dtb_addr': None,
- 'dtb_append': False,
- 'endian': None,
- 'fastboot': False,
- 'initrd_addr': None,
- 'job': 'job',
- 'job_id': 'job-id',
- 'kernel': 'kernel',
- 'kernel_image': None,
- 'lab_name': 'lab',
- 'load_addr': None,
- 'metadata': {},
- 'name': 'board-job-kernel-defconfig-arm',
- 'retries': 10,
- 'status': None,
- 'time': 0,
- 'version': "1.0",
- 'warnings': 2,
+ "_id": "id",
+ "board": "board",
+ "boot_log": "boot-log",
+ "boot_log_html": "boot-log-html",
+ "boot_result_description": None,
+ "created_on": "now",
+ "defconfig": "defconfig",
+ "defconfig_id": "defconfig_id",
+ "dtb": None,
+ "dtb_addr": None,
+ "dtb_append": False,
+ "endian": None,
+ "fastboot": False,
+ "initrd_addr": None,
+ "job": "job",
+ "job_id": "job-id",
+ "kernel": "kernel",
+ "kernel_image": None,
+ "lab_name": "lab",
+ "load_addr": None,
+ "metadata": {},
+ "name": "board-job-kernel-defconfig-arm",
+ "retries": 10,
+ "status": None,
+ "time": 0,
+ "version": "1.0",
+ "warnings": 2,
"git_commit": "git-commit",
"git_branch": "git-branch",
"git_describe": "git-describe",
@@ -93,3 +93,66 @@ class TestBootModel(unittest.TestCase):
}
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,
+ "endian": "little",
+ "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": "1234",
+ "job": "job",
+ "job_id": "job-id",
+ "kernel": "kernel",
+ "kernel_image": "kernel_image",
+ "lab_name": "lab",
+ "load_addr": "12345",
+ "metadata": {"foo": "bar"},
+ "name": "board-job-kernel-defconfig_full-arm",
+ "retries": 10,
+ "status": "PASS",
+ "time": 0,
+ "version": "1.0",
+ "warnings": 2
+ }
+
+ boot_doc = mboot.BootDocument.from_json(boot_json)
+
+ self.assertIsInstance(boot_doc, mboot.BootDocument)
+ self.assertDictEqual(boot_json, boot_doc.to_dict())