def test_generate(self): results = self.make_results() reporter = Reporter(bundle="git", results=results, options=None) with NamedTemporaryFile() as json_file: with NamedTemporaryFile() as html_file: reporter.generate(html_filename=html_file.name, json_filename=json_file.name) json_content = json_file.read() html_content = html_file.read() json_content = json.loads(json_content) self.assertIn("charm-proof", html_content) self.assertEqual(json_content["bundle"]["name"], "git")
def test_generate_with_svg(self): tempdir = mkdtemp() json_file = os.path.join(tempdir, "file.json") html_file = os.path.join(tempdir, "file.html") svg_file = os.path.join(tempdir, "file.svg") results = self.make_results() fake_request = FakeRequest() reporter = Reporter(bundle="git", results=results, options=None, bundle_yaml="bundle content") with patch("cloudweatherreport.reporter.requests.post", autospec=True, return_value=fake_request) as mock_r: reporter.generate(html_filename=html_file, json_filename=json_file) mock_r.assert_called_once_with("http://svg.juju.solutions", "bundle content") with open(json_file) as fp: json_content = json.loads(fp.read()) with open(html_file) as fp: html_content = fp.read() with open(svg_file) as fp: svg_content = fp.read() self.assertIn("charm-proof", html_content) self.assertEqual(json_content["bundle"]["name"], "git") self.assertEqual(svg_content, "svg content") rmtree(tempdir)
def main(args): log_level = logging.DEBUG if args.verbose else logging.INFO configure_logging(log_level) logging.info('Cloud Weather Report started.') test_plan = None if args.test_plan: test_plan = read_file(args.test_plan, 'yaml') results = [] status = None bundle = test_plan.get('bundle') html_filename, json_filename = get_filenames(bundle) for env_name in args.controller: env = jujuclient.Environment.connect(env_name=env_name) env_info = env.info() provider_name = get_provider_name(env_info["ProviderType"]) logging.info('Running test on {}.'.format(provider_name)) test_results, status = run_bundle_test( args=args, env=env_name, test_plan=test_plan) client = jujuclient.Actions(env) action_results = [] if test_plan.get('benchmark'): action_results = run_actions(test_plan, client, env.status()) all_values = get_benchmark_data( file_prefix(bundle), os.path.dirname(json_filename), provider_name) value = action_results[0].values()[0]['value'] action_results[0].values()[0]['all_values'] = all_values + [value] results.append({ "provider_name": provider_name, "test_results": json.loads(test_results) if test_results else None, "action_results": action_results, "info": env_info}) bundle_yaml = get_bundle_yaml(status) reporter = Reporter(bundle=bundle, results=results, options=args, bundle_yaml=bundle_yaml) reporter.generate(html_filename=html_filename, json_filename=json_filename) return html_filename