Exemplo n.º 1
0
 def test_get_test_outcome(self):
     r = Reporter(None, None, None)
     results = [r.pass_str, r.pass_str]
     self.assertEqual(r.get_test_outcome(results), r.all_passed_str)
     results = [r.pass_str, r.fail_str]
     self.assertEqual(r.get_test_outcome(results), r.some_failed_str)
     results = [r.fail_str, r.fail_str]
     self.assertEqual(r.get_test_outcome(results), r.all_failed_str)
Exemplo n.º 2
0
 def test_generate_html(self):
     r = Reporter(None, None, None)
     with NamedTemporaryFile() as html_file:
         html_output = r.generate_html(json_content=self.make_json(), output_file=html_file.name, past_results=[])
         content = html_file.read()
     self.assertRegexpMatches(html_output, "AWS")
     self.assertRegexpMatches(html_output, "Joyent")
     self.assertRegexpMatches(content, "AWS")
     self.assertRegexpMatches(content, "Joyent")
Exemplo n.º 3
0
 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")
Exemplo n.º 4
0
 def test_generate_json(self):
     results = self.make_results()
     reporter = Reporter(bundle="git", results=results, options=None)
     with NamedTemporaryFile() as json_file:
         json_result = reporter.generate_json(output_file=json_file.name)
         json_result = json.loads(json_result)
         content = json_file.read()
     for result in json_result["results"]:
         self.assertItemsEqual(result.keys(), ["info", "test_outcome", "tests", "provider_name", "benchmarks"])
         self.assertIn(result["provider_name"], ["aws", "joyent"])
         for test in result["tests"]:
             self.assertIn(test["name"], ["charm-proof", "00-setup", "10-actions"])
             self.assertItemsEqual(test.keys(), ["duration", "output", "suite", "name", "result"])
     self.assertIn('"name": "charm-proof"', content)
Exemplo n.º 5
0
 def test_generate_svg(self):
     tempdir = mkdtemp()
     svg_file = os.path.join(tempdir, "foo")
     r = Reporter(None, None, None, bundle_yaml="foo")
     fake_request = FakeRequest()
     with patch("cloudweatherreport.reporter.requests.post", autospec=True, return_value=fake_request) as mock_r:
         svg = r.generate_svg(svg_file)
         svg_path = "{}.svg".format(svg_file)
         with open(svg_path) as fp:
             content = fp.read()
             self.assertEqual(content, "svg content")
     mock_r.assert_called_once_with("http://svg.juju.solutions", "foo")
     self.assertEqual(svg, svg_path)
     rmtree(tempdir)
Exemplo n.º 6
0
 def test_get_past_test_results(self):
     temp = mkdtemp()
     files = [os.path.join(temp, 'git-2015-12-02T22:22:21-result.json'),
              os.path.join(temp, 'git-2015-12-02T22:22:21-result.html'),
              os.path.join(temp, 'git-2015-12-02T22:22:22-result.json'),
              os.path.join(temp, 'foo-2015-12-02T22:22:23-result.json'),
              os.path.join(temp, 'git-2015-12-02T22:22:25-result.json')]
     for f in files:
         with open(f, 'w') as fp:
             fp.write(self.make_json())
     r = Reporter('git', None, None)
     results, past_files = r.get_past_test_results(filename=files[0])
     self.assertItemsEqual(past_files, [files[2], files[4]])
     json_test_result = json.loads(self.make_json())
     self.assertItemsEqual(results, [json_test_result, json_test_result])
     rmtree(temp)
Exemplo n.º 7
0
 def test_generate_json(self):
     results = self.make_results()
     reporter = Reporter(bundle='git', results=results, options=None)
     with NamedTemporaryFile() as json_file:
         json_result = reporter.generate_json(output_file=json_file.name)
         json_result = json.loads(json_result)
         content = json_file.read()
     for result in json_result["results"]:
         self.assertItemsEqual(
             result.keys(),
             ['info', 'test_outcome', 'tests', 'provider_name',
              'benchmarks'])
         self.assertIn(result["provider_name"], ['aws', 'joyent'])
         for test in result["tests"]:
             self.assertIn(
                 test["name"], ['charm-proof', '00-setup', '10-actions'])
             self.assertItemsEqual(
                 test.keys(),
                 ['duration', 'output', 'suite', 'name', 'result'])
     self.assertIn('"name": "charm-proof"', content)
Exemplo n.º 8
0
 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)
Exemplo n.º 9
0
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