]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Add more tests for ReportSerializer 125/head
authorZack Cerza <zack@cerza.org>
Thu, 3 Oct 2013 21:23:15 +0000 (16:23 -0500)
committerZack Cerza <zack@cerza.org>
Fri, 4 Oct 2013 20:22:21 +0000 (15:22 -0500)
Signed-off-by: Zack Cerza <zack.cerza@inktank.com>
teuthology/test/fake_archive.py
teuthology/test/test_report.py

index ce804e8b5e6c8f38d3ff00a7b2362e449c3102d4..0a4f2af1acdbe8595c70d0e95850ff3bb0595141 100644 (file)
@@ -83,6 +83,8 @@ class FakeArchive(object):
         """
         Creates a fake run using run_name. Uses the YAML specified for each
         job's config.yaml
+
+        Returns a list of job_ids
         """
         assert os.path.exists(yaml_path)
         assert job_count > 0
@@ -96,4 +98,5 @@ class FakeArchive(object):
             job_yaml_path = os.path.join(self.archive_base, run_name,
                                          str(job_id), 'config.yaml')
             shutil.copyfile(yaml_path, job_yaml_path)
+        return jobs
 
index 6b943cef93b7a2145546b4733662580af092ce91..26501afd4e8d85bbb2a84a4c3b05db85750b1cc9 100644 (file)
@@ -1,8 +1,10 @@
+import yaml
+import json
 import fake_archive
 from .. import report
 
 
-class TestReport(object):
+class TestSerializer(object):
     def setup(self):
         self.archive = fake_archive.FakeArchive()
         self.archive.setup()
@@ -12,11 +14,53 @@ class TestReport(object):
     def teardown(self):
         self.archive.teardown()
 
-    def test_all_runs(self):
+    def test_all_runs_one_run(self):
         run_name = "test_all_runs"
         yaml_path = "examples/3node_ceph.yaml"
         job_count = 3
         self.archive.create_fake_run(run_name, job_count, yaml_path)
         assert [run_name] == self.reporter.serializer.all_runs
 
+    def test_all_runs_three_runs(self):
+        run_count = 3
+        runs = {}
+        for i in range(run_count):
+            run_name = "run #%s" % i
+            yaml_path = "examples/3node_ceph.yaml"
+            job_count = 3
+            job_ids = self.archive.create_fake_run(
+                run_name,
+                job_count,
+                yaml_path)
+            runs[run_name] = job_ids
+        assert sorted(runs.keys()) == sorted(self.reporter.serializer.all_runs)
+
+    def test_jobs_for_run(self):
+        run_name = "test_jobs_for_run"
+        yaml_path = "examples/3node_ceph.yaml"
+        job_count = 3
+        jobs = self.archive.create_fake_run(run_name, job_count, yaml_path)
+        job_ids = [str(job['job_id']) for job in jobs]
+
+        got_jobs = self.reporter.serializer.jobs_for_run(run_name)
+        assert sorted(job_ids) == sorted(got_jobs.keys())
+
+    def test_json_for_job(self):
+        run_name = "test_json_for_job"
+        yaml_path = "examples/3node_ceph.yaml"
+        job_count = 1
+        jobs = self.archive.create_fake_run(run_name, job_count, yaml_path)
+        job = jobs[0]
+
+        with file(yaml_path) as yaml_file:
+            obj_from_yaml = yaml.safe_load(yaml_file)
+        full_obj = obj_from_yaml.copy()
+        full_obj.update(job['info'])
+        full_obj.update(job['summary'])
+
+        out_json = self.reporter.serializer.json_for_job(
+            run_name, str(job['job_id']))
+        out_obj = json.loads(out_json)
+        assert full_obj == out_obj
+